diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-09-10 01:44:25 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-09-10 02:07:21 -0600 |
| commit | cc01b6f4e53bcf65a3192252be80926b38a224fd (patch) | |
| tree | 5133ac8c0a221dfb603ae65d99b0712b5d58aac5 /spec | |
| parent | 477585e7a434839a751c6394347fbdd72762ab6f (diff) | |
reference remote image that corresponds to current release line branch
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/admonition_spec.rb | 20 | ||||
| -rw-r--r-- | spec/fixtures/svg-with-remote-image.svg | 4 | ||||
| -rw-r--r-- | spec/image_spec.rb | 28 | ||||
| -rw-r--r-- | spec/page_spec.rb | 28 | ||||
| -rw-r--r-- | spec/spec_helper/helpers.rb | 14 |
5 files changed, 57 insertions, 37 deletions
diff --git a/spec/admonition_spec.rb b/spec/admonition_spec.rb index 1151c527..07df2a6c 100644 --- a/spec/admonition_spec.rb +++ b/spec/admonition_spec.rb @@ -764,17 +764,19 @@ describe 'Asciidoctor::PDF::Converter - Admonition' do end it 'should embed remote image in icon if allow-uri-read attribute is set', visual: true, network: true do - to_file = to_pdf_file <<~'EOS', 'admonition-custom-svg-icon-with-remote-image.pdf', attribute_overrides: { 'docdir' => fixtures_dir, 'allow-uri-read' => '' } - :icons: font - :iconsdir: + with_svg_with_remote_image do |image_path| + to_file = to_pdf_file <<~EOS, 'admonition-custom-svg-icon-with-remote-image.pdf', attribute_overrides: { 'docdir' => tmp_dir, 'allow-uri-read' => '' } + :icons: font + :iconsdir: - [NOTE,icon=svg-with-remote-image.svg] - ==== - AsciiDoc is awesome! - ==== - EOS + [NOTE,icon=#{File.basename image_path}] + ==== + AsciiDoc is awesome! + ==== + EOS - (expect to_file).to visually_match 'admonition-custom-svg-icon-with-remote-image.pdf' + (expect to_file).to visually_match 'admonition-custom-svg-icon-with-remote-image.pdf' + end end it 'should use original width of SVG icon if height is less than height of admonition block', visual: true do diff --git a/spec/fixtures/svg-with-remote-image.svg b/spec/fixtures/svg-with-remote-image.svg deleted file mode 100644 index d94741a1..00000000 --- a/spec/fixtures/svg-with-remote-image.svg +++ /dev/null @@ -1,4 +0,0 @@ -<svg width="1cm" height="1cm" version="1.1" viewBox="0 0 5 5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> -<image x="0" y="0" width="5" height="5" xlink:href="https://cdn.jsdelivr.net/gh/asciidoctor/asciidoctor-pdf@v1.6.2/spec/fixtures/logo.png"/> -<rect x="0.25" y="0.25" width="4.5" height="4.5" fill-opacity="0" stroke="#000" stroke-width="0.5"/> -</svg> diff --git a/spec/image_spec.rb b/spec/image_spec.rb index d3a20203..7973efb0 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -1026,21 +1026,24 @@ describe 'Asciidoctor::PDF::Converter - Image' do end it 'should not embed remote image if allow allow-uri-read attribute is not set', visual: true do - (expect do - to_file = to_pdf_file <<~'EOS', 'image-svg-with-remote-image-disabled.pdf' - A sign of a good writer: image:svg-with-remote-image.svg[] - EOS - - (expect to_file).to visually_match 'image-svg-with-missing-image.pdf' - end).to log_message severity: :WARN, message: %(~problem encountered in image: #{fixture_file 'svg-with-remote-image.svg'}; Error retrieving URL https://cdn.jsdelivr.net/gh/asciidoctor/asciidoctor-pdf@v1.6.2/spec/fixtures/logo.png) + with_svg_with_remote_image do |image_path, image_url| + (expect do + to_file = to_pdf_file <<~EOS, 'image-svg-with-remote-image-disabled.pdf' + A sign of a good writer: image:#{image_path}[] + EOS + (expect to_file).to visually_match 'image-svg-with-missing-image.pdf' + end).to log_message severity: :WARN, message: %(~problem encountered in image: #{image_path}; Error retrieving URL #{image_url}) + end end it 'should embed remote image if allow allow-uri-read attribute is set', visual: true, network: true do - to_file = to_pdf_file <<~'EOS', 'image-svg-with-remote-image.pdf', attribute_overrides: { 'allow-uri-read' => '' } - A sign of a good writer: image:svg-with-remote-image.svg[pdfwidth=1.27cm] - EOS + with_svg_with_remote_image do |image_path| + to_file = to_pdf_file <<~EOS, 'image-svg-with-remote-image.pdf', attribute_overrides: { 'allow-uri-read' => '' } + A sign of a good writer: image:#{image_path}[pdfwidth=1.27cm] + EOS - (expect to_file).to visually_match 'image-svg-with-image.pdf' + (expect to_file).to visually_match 'image-svg-with-image.pdf' + end end it 'should warn if remote image is missing and allow-uri-read attribute is set', network: true do @@ -1888,7 +1891,8 @@ describe 'Asciidoctor::PDF::Converter - Image' do end it 'should read remote image over HTTPS if allow-uri-read is set', network: true do - pdf = to_pdf 'image::https://cdn.jsdelivr.net/gh/asciidoctor/asciidoctor-pdf@v1.6.2/spec/fixtures/logo.png[Remote Image]', attribute_overrides: { 'allow-uri-read' => '' } + refname = 'main' if (refname = %(v#{Asciidoctor::PDF::VERSION})).include? '-' + pdf = to_pdf %(image::https://cdn.jsdelivr.net/gh/asciidoctor/asciidoctor-pdf@#{refname}/spec/fixtures/logo.png[Remote Image]), attribute_overrides: { 'allow-uri-read' => '' } images = get_images pdf, 1 (expect images).to have_size 1 (expect (pdf.page 1).text).to be_empty diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 22fe4fdd..b11db7d4 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -1405,25 +1405,29 @@ describe 'Asciidoctor::PDF::Converter - Page' do end it 'should allow remote image in SVG to be read if allow-uri-read attribute is set', visual: true, network: true do - to_file = to_pdf_file <<~'EOS', 'page-background-image-svg-with-remote-image.pdf', attribute_overrides: { 'allow-uri-read' => '' } - :page-background-image: image:svg-with-remote-image.svg[fit=none,position=top] + with_svg_with_remote_image do |image_path| + to_file = to_pdf_file <<~EOS, 'page-background-image-svg-with-remote-image.pdf', attribute_overrides: { 'allow-uri-read' => '' } + :page-background-image: image:#{image_path}[fit=none,position=top] - Asciidoctor - EOS + Asciidoctor + EOS - (expect to_file).to visually_match 'page-background-image-svg-with-image.pdf' + (expect to_file).to visually_match 'page-background-image-svg-with-image.pdf' + end end it 'should not allow remote image in SVG to be read if allow-uri-read attribute is not set', visual: true do - (expect do - to_file = to_pdf_file <<~'EOS', 'page-background-image-svg-with-remote-image-disabled.pdf' - :page-background-image: image:svg-with-remote-image.svg[fit=none,position=top] + with_svg_with_remote_image do |image_path| + (expect do + to_file = to_pdf_file <<~EOS, 'page-background-image-svg-with-remote-image-disabled.pdf' + :page-background-image: image:#{image_path}[fit=none,position=top] - Asciidoctor - EOS + Asciidoctor + EOS - (expect to_file).to visually_match 'page-background-image-svg-with-image-disabled.pdf' - end).to log_message severity: :WARN, message: '~No handler available for this URL scheme' + (expect to_file).to visually_match 'page-background-image-svg-with-image-disabled.pdf' + end).to log_message severity: :WARN, message: '~No handler available for this URL scheme' + end end it 'should not warn if background SVG has warnings', visual: true do diff --git a/spec/spec_helper/helpers.rb b/spec/spec_helper/helpers.rb index ea098ea7..ff2ce5a4 100644 --- a/spec/spec_helper/helpers.rb +++ b/spec/spec_helper/helpers.rb @@ -346,4 +346,18 @@ module RSpec::ExampleHelpers yield tmp_file end end + + def with_svg_with_remote_image + refname = 'main' if (refname = %(v#{Asciidoctor::PDF::VERSION})).include? '-' + image_url = "https://cdn.jsdelivr.net/gh/asciidoctor/asciidoctor-pdf@#{refname}/spec/fixtures/logo.png" + svg_data = <<~EOS + <svg width="1cm" height="1cm" version="1.1" viewBox="0 0 5 5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + <image x="0" y="0" width="5" height="5" xlink:href="#{image_url}"/> + <rect x="0.25" y="0.25" width="4.5" height="4.5" fill-opacity="0" stroke="#000" stroke-width="0.5"/> + </svg> + EOS + with_tmp_file '.svg', contents: svg_data do |tmp_file| + yield tmp_file.path, image_url + end + end end |
