Sha256: 702c69d9eef3f57e7e78570cc092b1845fb15938acaeaac80f84a0bbff6a8957

Contents?: true

Size: 1.8 KB

Versions: 31

Compression:

Stored size: 1.8 KB

Contents

require "test_helper"

class HTML::Pipeline::AbsoluteSourceFilterTest < Test::Unit::TestCase
  AbsoluteSourceFilter = HTML::Pipeline::AbsoluteSourceFilter

  def setup
    @image_base_url = 'http://assets.example.com'
    @image_subpage_url = 'http://blog.example.com/a/post'
    @options = {
      :image_base_url    => @image_base_url,
      :image_subpage_url => @image_subpage_url
    }
  end

  def test_rewrites_root_relative_urls
    orig = %(<p><img src="/img.png"></p>)
    puts AbsoluteSourceFilter.call(orig, @options).to_s
    assert_equal "<p><img src=\"#{@image_base_url}/img.png\"></p>",
      AbsoluteSourceFilter.call(orig, @options).to_s
  end

  def test_rewrites_root_relative_urls
    orig = %(<p><img src="post/img.png"></p>)
    assert_equal "<p><img src=\"#{@image_subpage_url}/img.png\"></p>",
      AbsoluteSourceFilter.call(orig, @options).to_s
  end

  def test_does_not_rewrite_absolute_urls
    orig = %(<p><img src="http://other.example.com/img.png"></p>)
    result = AbsoluteSourceFilter.call(orig, @options).to_s
    assert_no_match /@image_base_url/, result
    assert_no_match /@image_subpage_url/, result
  end

  def test_fails_when_context_is_missing
    assert_raise RuntimeError do
      AbsoluteSourceFilter.call("<img src=\"img.png\">", {})
    end
    assert_raise RuntimeError do
      AbsoluteSourceFilter.call("<img src=\"/img.png\">", {})
    end
  end
  
  def test_tells_you_where_context_is_required
    exception = assert_raise(RuntimeError) { 
      AbsoluteSourceFilter.call("<img src=\"img.png\">", {}) 
    }
    assert_match 'HTML::Pipeline::AbsoluteSourceFilter', exception.message

    exception = assert_raise(RuntimeError) { 
      AbsoluteSourceFilter.call("<img src=\"/img.png\">", {}) 
    }
    assert_match 'HTML::Pipeline::AbsoluteSourceFilter', exception.message
  end

end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
html-pipeline-linuxfr-0.14.23 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.22 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.21 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.20 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.19 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.18 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.17 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.16 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.15 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.14 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.13 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.12 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.11 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.10 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.9 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.8 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.7 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.6 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.5 test/html/pipeline/absolute_source_filter_test.rb
html-pipeline-linuxfr-0.14.4 test/html/pipeline/absolute_source_filter_test.rb