axlsx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/Rakefile +13 -0
  2. data/lib/axlsx.rb +38 -0
  3. data/lib/axlsx/content_type/content_type.rb +23 -0
  4. data/lib/axlsx/content_type/default.rb +32 -0
  5. data/lib/axlsx/content_type/override.rb +30 -0
  6. data/lib/axlsx/doc_props/app.rb +148 -0
  7. data/lib/axlsx/doc_props/core.rb +34 -0
  8. data/lib/axlsx/drawing/axis.rb +78 -0
  9. data/lib/axlsx/drawing/bar_3D_chart.rb +138 -0
  10. data/lib/axlsx/drawing/bar_series.rb +91 -0
  11. data/lib/axlsx/drawing/cat_axis.rb +58 -0
  12. data/lib/axlsx/drawing/chart.rb +120 -0
  13. data/lib/axlsx/drawing/drawing.rb +121 -0
  14. data/lib/axlsx/drawing/graphic_frame.rb +55 -0
  15. data/lib/axlsx/drawing/marker.rb +57 -0
  16. data/lib/axlsx/drawing/pie_3D_chart.rb +59 -0
  17. data/lib/axlsx/drawing/pie_series.rb +88 -0
  18. data/lib/axlsx/drawing/scaling.rb +53 -0
  19. data/lib/axlsx/drawing/series.rb +70 -0
  20. data/lib/axlsx/drawing/title.rb +69 -0
  21. data/lib/axlsx/drawing/two_cell_anchor.rb +88 -0
  22. data/lib/axlsx/drawing/val_axis.rb +34 -0
  23. data/lib/axlsx/drawing/view_3D.rb +72 -0
  24. data/lib/axlsx/package.rb +181 -0
  25. data/lib/axlsx/rels/relationship.rb +43 -0
  26. data/lib/axlsx/rels/relationships.rb +25 -0
  27. data/lib/axlsx/stylesheet/border.rb +52 -0
  28. data/lib/axlsx/stylesheet/border_pr.rb +65 -0
  29. data/lib/axlsx/stylesheet/cell_alignment.rb +96 -0
  30. data/lib/axlsx/stylesheet/cell_protection.rb +33 -0
  31. data/lib/axlsx/stylesheet/cell_style.rb +60 -0
  32. data/lib/axlsx/stylesheet/color.rb +57 -0
  33. data/lib/axlsx/stylesheet/fill.rb +31 -0
  34. data/lib/axlsx/stylesheet/font.rb +128 -0
  35. data/lib/axlsx/stylesheet/gradient_fill.rb +70 -0
  36. data/lib/axlsx/stylesheet/gradient_stop.rb +31 -0
  37. data/lib/axlsx/stylesheet/num_fmt.rb +61 -0
  38. data/lib/axlsx/stylesheet/pattern_fill.rb +64 -0
  39. data/lib/axlsx/stylesheet/styles.rb +296 -0
  40. data/lib/axlsx/stylesheet/table_style.rb +44 -0
  41. data/lib/axlsx/stylesheet/table_style_element.rb +66 -0
  42. data/lib/axlsx/stylesheet/table_styles.rb +39 -0
  43. data/lib/axlsx/stylesheet/xf.rb +117 -0
  44. data/lib/axlsx/util/constants.rb +189 -0
  45. data/lib/axlsx/util/simple_typed_list.rb +150 -0
  46. data/lib/axlsx/util/validators.rb +132 -0
  47. data/lib/axlsx/workbook/workbook.rb +130 -0
  48. data/lib/axlsx/workbook/worksheet/cell.rb +184 -0
  49. data/lib/axlsx/workbook/worksheet/row.rb +92 -0
  50. data/lib/axlsx/workbook/worksheet/worksheet.rb +194 -0
  51. data/lib/schema/dc.xsd +118 -0
  52. data/lib/schema/dcmitype.xsd +50 -0
  53. data/lib/schema/dcterms.xsd +331 -0
  54. data/lib/schema/dml-chart.xsd +1499 -0
  55. data/lib/schema/dml-chartDrawing.xsd +146 -0
  56. data/lib/schema/dml-compatibility.xsd +14 -0
  57. data/lib/schema/dml-diagram.xsd +1091 -0
  58. data/lib/schema/dml-lockedCanvas.xsd +11 -0
  59. data/lib/schema/dml-main.xsd +3048 -0
  60. data/lib/schema/dml-picture.xsd +23 -0
  61. data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
  62. data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
  63. data/lib/schema/opc-contentTypes.xsd +42 -0
  64. data/lib/schema/opc-coreProperties.xsd +50 -0
  65. data/lib/schema/opc-digSig.xsd +49 -0
  66. data/lib/schema/opc-relationships.xsd +33 -0
  67. data/lib/schema/pml.xsd +1676 -0
  68. data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
  69. data/lib/schema/shared-bibliography.xsd +144 -0
  70. data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
  71. data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
  72. data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
  73. data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
  74. data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
  75. data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
  76. data/lib/schema/shared-math.xsd +582 -0
  77. data/lib/schema/shared-relationshipReference.xsd +25 -0
  78. data/lib/schema/sml.xsd +4430 -0
  79. data/lib/schema/vml-main.xsd +569 -0
  80. data/lib/schema/vml-officeDrawing.xsd +509 -0
  81. data/lib/schema/vml-presentationDrawing.xsd +12 -0
  82. data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
  83. data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
  84. data/lib/schema/wml.xsd +3644 -0
  85. data/lib/schema/xml.xsd +117 -0
  86. data/test/content_type/tc_content_type.rb +81 -0
  87. data/test/content_type/tc_content_type.rb~ +81 -0
  88. data/test/content_type/tc_default.rb +40 -0
  89. data/test/content_type/tc_default.rb~ +40 -0
  90. data/test/content_type/tc_override.rb +40 -0
  91. data/test/content_type/tc_override.rb~ +40 -0
  92. data/test/doc_props/tc_app.rb +19 -0
  93. data/test/doc_props/tc_app.rb~ +19 -0
  94. data/test/doc_props/tc_core.rb +34 -0
  95. data/test/drawing/tc_axis.rb +39 -0
  96. data/test/drawing/tc_axis.rb~ +0 -0
  97. data/test/drawing/tc_bar_3D_chart.rb +66 -0
  98. data/test/drawing/tc_bar_3D_chart.rb~ +4 -0
  99. data/test/drawing/tc_bar_series.rb +34 -0
  100. data/test/drawing/tc_bar_series.rb~ +31 -0
  101. data/test/drawing/tc_cat_axis.rb +32 -0
  102. data/test/drawing/tc_cat_axis.rb~ +39 -0
  103. data/test/drawing/tc_chart.rb +59 -0
  104. data/test/drawing/tc_chart.rb~ +58 -0
  105. data/test/drawing/tc_drawing.rb +71 -0
  106. data/test/drawing/tc_graphic_frame.rb +26 -0
  107. data/test/drawing/tc_graphic_frame.rb~ +21 -0
  108. data/test/drawing/tc_marker.rb +45 -0
  109. data/test/drawing/tc_marker.rb~ +26 -0
  110. data/test/drawing/tc_pie_3D_chart.rb +33 -0
  111. data/test/drawing/tc_pie_3D_chart.rb~ +58 -0
  112. data/test/drawing/tc_pie_series.rb +35 -0
  113. data/test/drawing/tc_pie_series.rb~ +26 -0
  114. data/test/drawing/tc_scaling.rb +37 -0
  115. data/test/drawing/tc_scaling.rb~ +45 -0
  116. data/test/drawing/tc_series.rb +24 -0
  117. data/test/drawing/tc_series.rb~ +31 -0
  118. data/test/drawing/tc_title.rb +34 -0
  119. data/test/drawing/tc_title.rb~ +37 -0
  120. data/test/drawing/tc_two_cell_anchor.rb +37 -0
  121. data/test/drawing/tc_two_cell_anchor.rb~ +35 -0
  122. data/test/drawing/tc_val_axis.rb +20 -0
  123. data/test/drawing/tc_val_axis.rb~ +32 -0
  124. data/test/drawing/tc_view_3D.rb +46 -0
  125. data/test/drawing/tc_view_3D.rb~ +37 -0
  126. data/test/rels/tc_relationship.rb +16 -0
  127. data/test/rels/tc_relationship.rb~ +39 -0
  128. data/test/rels/tc_relationships.rb +32 -0
  129. data/test/rels/tc_relationships.rb~ +37 -0
  130. data/test/stylesheet/tc_border.rb +38 -0
  131. data/test/stylesheet/tc_border.rb~ +31 -0
  132. data/test/stylesheet/tc_border_pr.rb +33 -0
  133. data/test/stylesheet/tc_border_pr.rb~ +31 -0
  134. data/test/stylesheet/tc_cell_alignment.rb +77 -0
  135. data/test/stylesheet/tc_cell_alignment.rb~ +38 -0
  136. data/test/stylesheet/tc_cell_protection.rb +30 -0
  137. data/test/stylesheet/tc_cell_protection.rb~ +77 -0
  138. data/test/stylesheet/tc_cell_style.rb +58 -0
  139. data/test/stylesheet/tc_cell_style.rb~ +30 -0
  140. data/test/stylesheet/tc_color.rb +38 -0
  141. data/test/stylesheet/tc_color.rb~ +38 -0
  142. data/test/stylesheet/tc_fill.rb +19 -0
  143. data/test/stylesheet/tc_fill.rb~ +19 -0
  144. data/test/stylesheet/tc_font.rb +114 -0
  145. data/test/stylesheet/tc_font.rb~ +19 -0
  146. data/test/stylesheet/tc_gradient_fill.rb +65 -0
  147. data/test/stylesheet/tc_gradient_fill.rb~ +114 -0
  148. data/test/stylesheet/tc_gradient_stop.rb +32 -0
  149. data/test/stylesheet/tc_gradient_stop.rb~ +65 -0
  150. data/test/stylesheet/tc_num_fmt.rb +31 -0
  151. data/test/stylesheet/tc_num_fmt.rb~ +32 -0
  152. data/test/stylesheet/tc_pattern_fill.rb +38 -0
  153. data/test/stylesheet/tc_pattern_fill.rb~ +31 -0
  154. data/test/stylesheet/tc_styles.rb +64 -0
  155. data/test/stylesheet/tc_table_style.rb +37 -0
  156. data/test/stylesheet/tc_table_style.rb~ +38 -0
  157. data/test/stylesheet/tc_table_style_element.rb +37 -0
  158. data/test/stylesheet/tc_table_style_element.rb~ +37 -0
  159. data/test/stylesheet/tc_table_styles.rb +30 -0
  160. data/test/stylesheet/tc_table_styles.rb~ +37 -0
  161. data/test/stylesheet/tc_xf.rb +121 -0
  162. data/test/stylesheet/tc_xf.rb~ +30 -0
  163. data/test/tc_app.rb~ +19 -0
  164. data/test/tc_border_pr.rb~ +21 -0
  165. data/test/tc_package.rb +70 -0
  166. data/test/tc_package.rb~ +64 -0
  167. data/test/tc_pie_3D_chart.rb~ +66 -0
  168. data/test/tc_relationships.rb~ +37 -0
  169. data/test/tc_series.rb~ +31 -0
  170. data/test/tc_styles.rb~ +64 -0
  171. data/test/tc_validators.rb~ +77 -0
  172. data/test/tc_worksheet.rb~ +85 -0
  173. data/test/util/tc_simple_typed_list.rb +66 -0
  174. data/test/util/tc_validators.rb +76 -0
  175. data/test/workbook/tc_workbook.rb +53 -0
  176. data/test/workbook/worksheet/tc_cell.rb +78 -0
  177. data/test/workbook/worksheet/tc_row.rb +30 -0
  178. data/test/workbook/worksheet/tc_worksheet.rb +85 -0
  179. metadata +378 -0
@@ -0,0 +1,117 @@
1
+ <?xml version='1.0'?>
2
+ <!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" >
3
+ <xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
4
+
5
+ <xs:annotation>
6
+ <xs:documentation>
7
+ See http://www.w3.org/XML/1998/namespace.html and
8
+ http://www.w3.org/TR/REC-xml for information about this namespace.
9
+
10
+ This schema document describes the XML namespace, in a form
11
+ suitable for import by other schema documents.
12
+
13
+ Note that local names in this namespace are intended to be defined
14
+ only by the World Wide Web Consortium or its subgroups. The
15
+ following names are currently defined in this namespace and should
16
+ not be used with conflicting semantics by any Working Group,
17
+ specification, or document instance:
18
+
19
+ base (as an attribute name): denotes an attribute whose value
20
+ provides a URI to be used as the base for interpreting any
21
+ relative URIs in the scope of the element on which it
22
+ appears; its value is inherited. This name is reserved
23
+ by virtue of its definition in the XML Base specification.
24
+
25
+ lang (as an attribute name): denotes an attribute whose value
26
+ is a language code for the natural language of the content of
27
+ any element; its value is inherited. This name is reserved
28
+ by virtue of its definition in the XML specification.
29
+
30
+ space (as an attribute name): denotes an attribute whose
31
+ value is a keyword indicating what whitespace processing
32
+ discipline is intended for the content of the element; its
33
+ value is inherited. This name is reserved by virtue of its
34
+ definition in the XML specification.
35
+
36
+ Father (in any context at all): denotes Jon Bosak, the chair of
37
+ the original XML Working Group. This name is reserved by
38
+ the following decision of the W3C XML Plenary and
39
+ XML Coordination groups:
40
+
41
+ In appreciation for his vision, leadership and dedication
42
+ the W3C XML Plenary on this 10th day of February, 2000
43
+ reserves for Jon Bosak in perpetuity the XML name
44
+ xml:Father
45
+ </xs:documentation>
46
+ </xs:annotation>
47
+
48
+ <xs:annotation>
49
+ <xs:documentation>This schema defines attributes and an attribute group
50
+ suitable for use by
51
+ schemas wishing to allow xml:base, xml:lang or xml:space attributes
52
+ on elements they define.
53
+
54
+ To enable this, such a schema must import this schema
55
+ for the XML namespace, e.g. as follows:
56
+ &lt;schema . . .>
57
+ . . .
58
+ &lt;import namespace="http://www.w3.org/XML/1998/namespace"
59
+ schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
60
+
61
+ Subsequently, qualified reference to any of the attributes
62
+ or the group defined below will have the desired effect, e.g.
63
+
64
+ &lt;type . . .>
65
+ . . .
66
+ &lt;attributeGroup ref="xml:specialAttrs"/>
67
+
68
+ will define a type which will schema-validate an instance
69
+ element with any of those attributes</xs:documentation>
70
+ </xs:annotation>
71
+
72
+ <xs:annotation>
73
+ <xs:documentation>In keeping with the XML Schema WG's standard versioning
74
+ policy, this schema document will persist at
75
+ http://www.w3.org/2001/03/xml.xsd.
76
+ At the date of issue it can also be found at
77
+ http://www.w3.org/2001/xml.xsd.
78
+ The schema document at that URI may however change in the future,
79
+ in order to remain compatible with the latest version of XML Schema
80
+ itself. In other words, if the XML Schema namespace changes, the version
81
+ of this document at
82
+ http://www.w3.org/2001/xml.xsd will change
83
+ accordingly; the version at
84
+ http://www.w3.org/2001/03/xml.xsd will not change.
85
+ </xs:documentation>
86
+ </xs:annotation>
87
+
88
+ <xs:attribute name="lang" type="xs:language">
89
+ <xs:annotation>
90
+ <xs:documentation>In due course, we should install the relevant ISO 2- and 3-letter
91
+ codes as the enumerated possible values . . .</xs:documentation>
92
+ </xs:annotation>
93
+ </xs:attribute>
94
+
95
+ <xs:attribute name="space" default="preserve">
96
+ <xs:simpleType>
97
+ <xs:restriction base="xs:NCName">
98
+ <xs:enumeration value="default"/>
99
+ <xs:enumeration value="preserve"/>
100
+ </xs:restriction>
101
+ </xs:simpleType>
102
+ </xs:attribute>
103
+
104
+ <xs:attribute name="base" type="xs:anyURI">
105
+ <xs:annotation>
106
+ <xs:documentation>See http://www.w3.org/TR/xmlbase/ for
107
+ information about this attribute.</xs:documentation>
108
+ </xs:annotation>
109
+ </xs:attribute>
110
+
111
+ <xs:attributeGroup name="specialAttrs">
112
+ <xs:attribute ref="xml:base"/>
113
+ <xs:attribute ref="xml:lang"/>
114
+ <xs:attribute ref="xml:space"/>
115
+ </xs:attributeGroup>
116
+
117
+ </xs:schema>
@@ -0,0 +1,81 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestContentType < Test::Unit::TestCase
5
+ def setup
6
+ @package = Axlsx::Package.new
7
+ @doc = Nokogiri::XML(@package.send(:content_types).to_xml)
8
+ end
9
+
10
+ def test_valid_document
11
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
12
+ errors = []
13
+ schema.validate(@doc).each do |error|
14
+ puts error.message
15
+ errors << error
16
+ end
17
+ assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
18
+ end
19
+
20
+ def test_pre_built_types
21
+
22
+ o_path = "Types Override [@ContentType='%s']"
23
+ d_path = "Types Default [@ContentType='%s']"
24
+
25
+ #default
26
+ assert_equal(@doc.css("Types Default").size, 2, "There should be 2 default types")
27
+
28
+ node = @doc.css(d_path % Axlsx::XML_CT).first
29
+ assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid")
30
+
31
+ node = @doc.css(d_path % Axlsx::RELS_CT).first
32
+ assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid")
33
+
34
+ #overrride
35
+ assert_equal(@doc.css("Types Override").size, 4, "There should be 4 Override types")
36
+
37
+ node = @doc.css(o_path % Axlsx::APP_CT).first
38
+ assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
39
+
40
+ node = @doc.css(o_path % Axlsx::CORE_CT).first
41
+ assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
42
+
43
+ node = @doc.css(o_path % Axlsx::STYLES_CT).first
44
+ assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
45
+
46
+ node = @doc.css(o_path % Axlsx::WORKBOOK_CT).first
47
+ assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
48
+ end
49
+
50
+ def test_should_get_worksheet_for_worksheets
51
+ o_path = "Types Override [@ContentType='%s']"
52
+
53
+ ws = @package.workbook.add_worksheet
54
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
55
+ assert_equal(doc.css("Types Override").size, 5, "adding a worksheet should add another type")
56
+ assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
57
+
58
+ ws = @package.workbook.add_worksheet
59
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
60
+ assert_equal(doc.css("Types Override").size, 6, "adding workship should add another type")
61
+ assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
62
+
63
+ end
64
+
65
+ def test_drawings_and_charts_need_content_types
66
+ o_path = "Types Override [@ContentType='%s']"
67
+ ws = @package.workbook.add_worksheet
68
+
69
+ c = ws.add_chart Axlsx::Pie3DChart
70
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
71
+ assert_equal(doc.css("Types Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
72
+ assert_equal(doc.css(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
73
+ assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
74
+
75
+ c = ws.add_chart Axlsx::Pie3DChart
76
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
77
+ assert_equal(doc.css("Types Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
78
+ assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
79
+ end
80
+
81
+ end
@@ -0,0 +1,81 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestContentType < Test::Unit::TestCase
5
+ def setup
6
+ @package = Axlsx::Package.new
7
+ @doc = Nokogiri::XML(@package.send(:content_types).to_xml)
8
+ end
9
+
10
+ def test_valid_document
11
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
12
+ errors = []
13
+ schema.validate(@doc).each do |error|
14
+ puts error.message
15
+ errors << error
16
+ end
17
+ assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
18
+ end
19
+
20
+ def test_pre_built_types
21
+
22
+ o_path = "Types Override [@ContentType='%s']"
23
+ d_path = "Types Default [@ContentType='%s']"
24
+
25
+ #default
26
+ assert_equal(@doc.css("Types Default").size, 2, "There should be 2 default types")
27
+
28
+ node = @doc.css(d_path % Axlsx::XML_CT).first
29
+ assert_equal(node["Extension"], "#{Axlsx::XML_EX}", "xml content type invalid")
30
+
31
+ node = @doc.css(d_path % Axlsx::RELS_CT).first
32
+ assert_equal(node["Extension"],"#{Axlsx::RELS_EX}", "relationships content type invalid")
33
+
34
+ #overrride
35
+ assert_equal(@doc.css("Types Override").size, 4, "There should be 4 Override types")
36
+
37
+ node = @doc.css(o_path % Axlsx::APP_CT).first
38
+ assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
39
+
40
+ node = @doc.css(o_path % Axlsx::CORE_CT).first
41
+ assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
42
+
43
+ node = @doc.css(o_path % Axlsx::STYLES_CT).first
44
+ assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
45
+
46
+ node = @doc.css(o_path % Axlsx::WORKBOOK_CT).first
47
+ assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
48
+ end
49
+
50
+ def test_should_get_worksheet_for_worksheets
51
+ o_path = "Types Override [@ContentType='%s']"
52
+
53
+ ws = @package.workbook.add_worksheet
54
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
55
+ assert_equal(doc.css("Types Override").size, 5, "adding a worksheet should add another type")
56
+ assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
57
+
58
+ ws = @package.workbook.add_worksheet
59
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
60
+ assert_equal(doc.css("Types Override").size, 6, "adding workship should add another type")
61
+ assert_equal(doc.css(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
62
+
63
+ end
64
+
65
+ def test_drawings_and_charts_need_content_types
66
+ o_path = "Types Override [@ContentType='%s']"
67
+ ws = @package.workbook.add_worksheet
68
+
69
+ c = ws.add_chart Axlsx::Pie3DChart
70
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
71
+ assert_equal(doc.css("Types Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
72
+ assert_equal(doc.css(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
73
+ assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
74
+
75
+ c = ws.add_chart Axlsx::Pie3DChart
76
+ doc = Nokogiri::XML(@package.send(:content_types).to_xml)
77
+ assert_equal(doc.css("Types Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
78
+ assert_equal(doc.css(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
79
+ end
80
+
81
+ end
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestDefault < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+ def test_initialization_requires_Extension_and_ContentType
10
+ assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new }
11
+ assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :Extension=>"xml" }
12
+ assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :ContentType=>"asdf" }
13
+
14
+ assert_nothing_raised {Axlsx::Default.new :Extension=>"foo", :ContentType=>Axlsx::XML_CT}
15
+
16
+ end
17
+ def test_content_type_restriction
18
+ assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" }
19
+ end
20
+
21
+ def test_to_xml
22
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
23
+ type = Axlsx::Default.new :Extension=>"xml", :ContentType=>Axlsx::XML_CT
24
+ builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
25
+ xml.Types(:xmlns => Axlsx::XML_NS_T) {
26
+ type.to_xml(xml)
27
+ }
28
+ end
29
+ doc = Nokogiri::XML(builder.to_xml)
30
+ errors = []
31
+ schema.validate(doc).each do |error|
32
+ puts error.message
33
+ errors << error
34
+ end
35
+ assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestDefault < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+ def test_initialization_requires_Extension_and_ContentType
10
+ assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new }
11
+ assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :Extension=>"xml" }
12
+ assert_raise(ArgumentError, "raises argument error if Extension and/or ContentType are not specified") { Axlsx::Default.new :ContentType=>"asdf" }
13
+
14
+ assert_nothing_raised {Axlsx::Default.new :Extension=>"foo", :ContentType=>Axlsx::XML_CT}
15
+
16
+ end
17
+ def test_content_type_restriction
18
+ assert_raise(ArgumentError, "raises argument error if invlalid ContentType is") { Axlsx::Default.new :ContentType=>"asdf" }
19
+ end
20
+
21
+ def test_to_xml
22
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
23
+ type = Axlsx::Default.new :Extension=>"xml", :ContentType=>Axlsx::XML_CT
24
+ builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
25
+ xml.Types(:xmlns => Axlsx::XML_NS_T) {
26
+ type.to_xml(xml)
27
+ }
28
+ end
29
+ doc = Nokogiri::XML(builder.to_xml)
30
+ errors = []
31
+ schema.validate(doc).each do |error|
32
+ puts error.message
33
+ errors << error
34
+ end
35
+ assert_equal(errors.size, 0, "[Content Types].xml Invalid" + errors.map{ |e| e.message }.to_s)
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestOverride < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+ def test_initialization_requires_Extension_and_ContentType
10
+ err = "requires PartName and ContentType options"
11
+ assert_raise(ArgumentError, err) { Axlsx::Override.new }
12
+ assert_raise(ArgumentError, err) { Axlsx::Override.new :PartName=>"xml" }
13
+ assert_raise(ArgumentError, err) { Axlsx::Override.new :ContentType=>"asdf" }
14
+ assert_nothing_raised {Axlsx::Override.new :PartName=>"foo", :ContentType=>Axlsx::CHART_CT}
15
+ end
16
+
17
+ def test_content_type_restriction
18
+ assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType=>"asdf" }
19
+ end
20
+
21
+ def test_to_xml
22
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
23
+ type = Axlsx::Override.new :PartName=>"somechart.xml", :ContentType=>Axlsx::CHART_CT
24
+ builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
25
+ xml.Types(:xmlns => Axlsx::XML_NS_T) {
26
+ type.to_xml(xml)
27
+ }
28
+ end
29
+ doc = Nokogiri::XML(builder.to_xml)
30
+ errors = []
31
+ schema.validate(doc).each do |error|
32
+ puts error.message
33
+ errors << error
34
+ end
35
+ assert_equal(errors.size, 0, "Override content type caused invalid content_type doc" + errors.map{ |e| e.message }.to_s)
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestOverride < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+ def test_initialization_requires_Extension_and_ContentType
10
+ err = "requires PartName and ContentType options"
11
+ assert_raise(ArgumentError, err) { Axlsx::Override.new }
12
+ assert_raise(ArgumentError, err) { Axlsx::Override.new :PartName=>"xml" }
13
+ assert_raise(ArgumentError, err) { Axlsx::Override.new :ContentType=>"asdf" }
14
+ assert_nothing_raised {Axlsx::Override.new :PartName=>"foo", :ContentType=>Axlsx::CHART_CT}
15
+ end
16
+
17
+ def test_content_type_restriction
18
+ assert_raise(ArgumentError, "requires known content type") { Axlsx::Override.new :ContentType=>"asdf" }
19
+ end
20
+
21
+ def test_to_xml
22
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
23
+ type = Axlsx::Override.new :PartName=>"somechart.xml", :ContentType=>Axlsx::CHART_CT
24
+ builder = Nokogiri::XML::Builder.new(:encoding => Axlsx::ENCODING) do |xml|
25
+ xml.Types(:xmlns => Axlsx::XML_NS_T) {
26
+ type.to_xml(xml)
27
+ }
28
+ end
29
+ doc = Nokogiri::XML(builder.to_xml)
30
+ errors = []
31
+ schema.validate(doc).each do |error|
32
+ puts error.message
33
+ errors << error
34
+ end
35
+ assert_equal(errors.size, 0, "Override content type caused invalid content_type doc" + errors.map{ |e| e.message }.to_s)
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'axlsx.rb'
3
+
4
+ class TestApp < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+
10
+ def test_valid_document
11
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::APP_XSD))
12
+ doc = Nokogiri::XML(Axlsx::App.new.to_xml)
13
+ errors = []
14
+ schema.validate(doc).each do |error|
15
+ errors << error
16
+ end
17
+ assert_equal(errors.size, 0, "app.xml invalid" + errors.map{ |e| e.message }.to_s)
18
+ end
19
+ end