test/test_parser_publication.rb in epub-parser-0.0.2 vs test/test_parser_publication.rb in epub-parser-0.0.3

- old
+ new

@@ -11,23 +11,92 @@ def setup super @manifest = @parser.parse_manifest end - def test_manifest_has_4_items - assert_equal 4, @manifest.items.length + def test_manifest_has_6_items + assert_equal 6, @manifest.items.length end - def test_item_has_full_path_as_href_attribute + def test_item_has_full_path_as_iri_attribute actual = File.expand_path 'fixtures/book/OPS/nav.xhtml', File.dirname(__FILE__) - assert_equal actual, @manifest['nav'].href.to_s + assert_equal actual, @manifest['nav'].iri.to_s end def test_fallback_attribute_of_item_should_be_item_object fallback = @manifest['manifest-item-2'].fallback assert_instance_of Publication::Package::Manifest::Item, fallback assert_equal 'manifest-item-fallback', fallback.id + end + + def test_item_is_readable + item = @manifest.items.first + doc = Nokogiri.XML item.read + + assert_equal 'html', doc.root.name + end + + def test_item_can_traverse_fallback_chain + assert_equal [@manifest['manifest-item-2'], @manifest['manifest-item-fallback'], @manifest['manifest-item-fallback2']], + @manifest['manifest-item-2'].fallback_chain + end + + def test_item_always_has_fallback_chain_including_itself + item = @manifest['manifest-item-1'] + + assert_equal [item], item.fallback_chain + end + + def test_item_can_use_fallback_chain_when_not_core_media_type_by_default + item = @manifest['manifest-item-2'] + fallback = item.fallback + result = item.use_fallback_chain do |current| + current + end + + assert_equal fallback, result + end + + def test_item_can_custome_supported_media_type_in_use_fallback_chain + item = @manifest['manifest-item-2'] + result = item.use_fallback_chain supported: 'application/pdf' do |current| + current + end + + assert_equal item, result + end + + def test_item_can_custome_not_supported_media_type_in_use_fallback_chain + item = @manifest['manifest-item-2'] + fallback = item.fallback.fallback + result = item.use_fallback_chain not_supported: 'image/svg+xml' do |current| + current + end + + assert_equal fallback, result + end + end + + class TestParseGuide < TestParserPublication + def setup + super + @guide = @parser.parse_guide + end + + def test_guide_has_one_reference + assert_equal 1, @guide.references.length + end + + def test_guide_has_cover_reference + assert @guide.cover + assert_equal 'cover', @guide.cover.type + end + + def test_reference_refers_item + @parser.parse_manifest + + assert_instance_of EPUB::Publication::Package::Manifest::Item, @guide.cover.item end end end