test/test_publication.rb in epub-parser-0.1.4 vs test/test_publication.rb in epub-parser-0.1.5

- old
+ new

@@ -1,20 +1,22 @@ require_relative 'helper' require 'epub/publication' class TestPublication < Test::Unit::TestCase include EPUB::Publication + def setup + @package = EPUB::Publication::Package.new + end def test_package_clear_package_attribute_of_submodules_when_attribute_writer_called metadata = EPUB::Publication::Package::Metadata.new another_metadata = EPUB::Publication::Package::Metadata.new - package = EPUB::Publication::Package.new - package.metadata = metadata - assert_equal metadata.package, package + @package.metadata = metadata + assert_equal metadata.package, @package - package.metadata = another_metadata + @package.metadata = another_metadata assert_nil metadata.package end class TestMetadata < TestPublication def test_meta_refines_setter_connect_refinee_to_the_meta @@ -60,10 +62,80 @@ package.titles << main_title package.titles << extended_title assert_equal 'Extended Title', package.title end + + def test_title_returns_compositted_title_when_it_is_not_empty + main_title = Package::Metadata::Title.new + main_title.id = 'main-title' + main_title.content = 'main title' + main_refiner = Package::Metadata::Meta.new + main_refiner.property = 'title-type' + main_refiner.content = 'main' + main_refiner.refines = main_title + main_order = Package::Metadata::Meta.new + main_order.property = 'display-seq' + main_order.content = 1 + main_order.refines = main_title + + subtitle = Package::Metadata::Title.new + subtitle.id = 'subtitle' + subtitle.content = 'subtitle' + sub_refiner = Package::Metadata::Meta.new + sub_refiner.property = 'title-type' + sub_refiner.content = 'subtitle' + sub_refiner.refines = subtitle + sub_order = Package::Metadata::Meta.new + sub_order.property = 'display-seq' + sub_order.content = 2 + sub_order.refines = subtitle + + package = Package::Metadata.new + package.titles << main_title << subtitle + + assert_equal "main title\nsubtitle", package.title + end + + def test_title_returns_main_title_when_no_title_has_order + main_title = Package::Metadata::Title.new + main_title.id = 'main-title' + main_title.content = 'main title' + main_refiner = Package::Metadata::Meta.new + main_refiner.property = 'title-type' + main_refiner.content = 'main' + main_refiner.refines = main_title + + subtitle = Package::Metadata::Title.new + subtitle.id = 'subtitle' + subtitle.content = 'subtitle' + sub_refiner = Package::Metadata::Meta.new + sub_refiner.property = 'title-type' + sub_refiner.content = 'subtitle' + sub_refiner.refines = subtitle + + package = Package::Metadata.new + package.titles << subtitle << main_title + + assert_equal "main title", package.title + end + + def test_meta_refining_publication_is_primary_expression + meta = Package::Metadata::Meta.new + meta.property = 'dcterms:modified' + + assert_true meta.primary_expression? + end + + def test_meta_refining_other_element_is_subexpression + title = Package::Metadata::Title.new + title.id = 'title' + meta = Package::Metadata::Meta.new + meta.refines = title + + assert_true meta.subexpression? + end end class TestManifest < TestPublication include EPUB::Publication @@ -91,10 +163,24 @@ item.id = 'item' stub(item).manifest.stub!.package.stub!.spine.stub!.itemrefs {[itemref]} assert_same itemref, item.itemref end + + def test_xhtml_returns_true_when_xhtml + item = Package::Manifest::Item.new + item.media_type = 'application/xhtml+xml' + + assert_true item.xhtml? + end + + def test_xhtml_returns_false_when_not_xhtml + item = Package::Manifest::Item.new + item.media_type = 'text/css' + + assert_false item.xhtml? + end end end class TestSpine < TestPublication class TestItemref < TestSpine @@ -135,9 +221,44 @@ @itemref.item = item assert_equal 'item', @itemref.idref assert_include spine.items, item assert_same item, @itemref.item + end + + def test_itemref_equals_itemref_with_same_attributes + base = Package::Spine::Itemref.new + another = Package::Spine::Itemref.new + [base, another].each do |itemref| + [:spine, :idref, :id].each do |attr| + itemref.__send__ "#{attr}=", attr.to_s + end + itemref.linear = false + end + base.properties = ['property1', 'property2'] + another.properties = ['property2', 'property1'] + + assert_true base == another + + base.linear = true + another.linear = 'yes' + + assert_true base == another + end + + def test_itemref_doesnt_equal_itemref_with_different_attributes + base = Package::Spine::Itemref.new + another = Package::Spine::Itemref.new + [base, another].each do |itemref| + [:spine, :idref, :id].each do |attr| + itemref.__send__ "#{attr}=", attr.to_s + end + itemref.linear = false + end + base.properties = ['property1', 'property2'] + another.properties = ['property1', 'property2', 'property3'] + + assert_false base == another end end end end