summaryrefslogtreecommitdiffhomepage
path: root/test/content_type
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
committerRandy Morgan <[email protected]>2012-04-01 00:35:26 +0900
commit22a341841f191a5aa00e87b1f166b4f25cc67f0a (patch)
tree505f46708d5cac7d33d0dd6679c125e2eb819075 /test/content_type
parentbb2117ba17297e02a0fc6d5ad5a22462e72a9a79 (diff)
downloadcaxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.tar.gz
caxlsx-22a341841f191a5aa00e87b1f166b4f25cc67f0a.zip
part way through changing all serialization to use string concatenation prior to dropping Nokogiri dep in production.
Diffstat (limited to 'test/content_type')
-rw-r--r--test/content_type/tc_content_type.rb10
-rw-r--r--test/content_type/tc_default.rb23
-rw-r--r--test/content_type/tc_override.rb21
3 files changed, 14 insertions, 40 deletions
diff --git a/test/content_type/tc_content_type.rb b/test/content_type/tc_content_type.rb
index 79141748..e353b1bb 100644
--- a/test/content_type/tc_content_type.rb
+++ b/test/content_type/tc_content_type.rb
@@ -4,7 +4,7 @@ require 'tc_helper.rb'
class TestContentType < Test::Unit::TestCase
def setup
@package = Axlsx::Package.new
- @doc = Nokogiri::XML(@package.send(:content_types).to_xml)
+ @doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
end
def test_valid_document
@@ -51,12 +51,12 @@ class TestContentType < Test::Unit::TestCase
o_path = "//xmlns:Override[@ContentType='%s']"
ws = @package.workbook.add_worksheet
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(doc.xpath("//xmlns:Override").size, 5, "adding a worksheet should add another type")
assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
ws = @package.workbook.add_worksheet
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(doc.xpath("//xmlns:Override").size, 6, "adding workship should add another type")
assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
@@ -67,13 +67,13 @@ class TestContentType < Test::Unit::TestCase
ws = @package.workbook.add_worksheet
c = ws.add_chart Axlsx::Pie3DChart
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(doc.xpath("//xmlns:Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
assert_equal(doc.xpath(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
c = ws.add_chart Axlsx::Pie3DChart
- doc = Nokogiri::XML(@package.send(:content_types).to_xml)
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(doc.xpath("//xmlns:Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
end
diff --git a/test/content_type/tc_default.rb b/test/content_type/tc_default.rb
index e5245b38..2fe0d965 100644
--- a/test/content_type/tc_default.rb
+++ b/test/content_type/tc_default.rb
@@ -2,10 +2,7 @@
require 'tc_helper.rb'
class TestDefault < Test::Unit::TestCase
- def setup
- end
- def teardown
- end
+
def test_initialization_requires_Extension_and_ContentType
assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new }
assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :Extension=>"xml" }
@@ -18,21 +15,11 @@ class TestDefault < Test::Unit::TestCase
assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" }
end
- def test_to_xml
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
+ def test_to_xml_string
type = Axlsx::Default.new :Extension=>"xml", :ContentType=>Axlsx::XML_CT
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
- type.to_xml(xml)
- }
- end
- doc = Nokogiri::XML(builder.to_xml)
- errors = []
- schema.validate(doc).each do |error|
- puts error.message
- errors << error
- end
- assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
+ doc = Nokogiri::XML(type.to_xml_string)
+ assert_equal(doc.xpath("Default[@ContentType='#{Axlsx::XML_CT}']").size, 1)
+ assert_equal(doc.xpath("Default[@Extension='xml']").size, 1)
end
diff --git a/test/content_type/tc_override.rb b/test/content_type/tc_override.rb
index 5005d12d..920f1667 100644
--- a/test/content_type/tc_override.rb
+++ b/test/content_type/tc_override.rb
@@ -2,10 +2,7 @@
require 'tc_helper.rb'
class TestOverride < Test::Unit::TestCase
- def setup
- end
- def teardown
- end
+
def test_initialization_requires_Extension_and_ContentType
err = "requires PartName and ContentType options"
assert_raise(ArgumentError, err) { Axlsx::Override.new }
@@ -19,20 +16,10 @@ class TestOverride < Test::Unit::TestCase
end
def test_to_xml
- schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
type = Axlsx::Override.new :PartName=>"somechart.xml", :ContentType=>Axlsx::CHART_CT
- builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
- xml.Types(:xmlns => Axlsx::XML_NS_T) {
- type.to_xml(xml)
- }
- end
- doc = Nokogiri::XML(builder.to_xml)
- errors = []
- schema.validate(doc).each do |error|
- puts error.message
- errors << error
- end
- assert_equal(errors.size, 0, "Override content type caused invalid content_type doc" + errors.map{ |e| e.message }.to_s)
+ doc = Nokogiri::XML(type.to_xml_string)
+ assert_equal(doc.xpath("Override[@ContentType='#{Axlsx::CHART_CT}']").size, 1)
+ assert_equal(doc.xpath("Override[@PartName='somechart.xml']").size, 1)
end