summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/workbook/worksheet/tc_sheet_protection.rb120
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb6
2 files changed, 126 insertions, 0 deletions
diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb
new file mode 100644
index 00000000..b29e2d32
--- /dev/null
+++ b/test/workbook/worksheet/tc_sheet_protection.rb
@@ -0,0 +1,120 @@
+# encoding: UTF-8
+require 'tc_helper.rb'
+
+# <xsd:complexType name="CT_SheetProtection">
+# <xsd:attribute name="algorithmName" type="s:ST_Xstring" use="optional"/>
+# <xsd:attribute name="hashValue" type="xsd:base64Binary" use="optional"/>
+# <xsd:attribute name="saltValue" type="xsd:base64Binary" use="optional"/>
+# <xsd:attribute name="spinCount" type="xsd:unsignedInt" use="optional"/>
+# <xsd:attribute name="sheet" type="xsd:boolean" use="optional" default="false"/>
+# <xsd:attribute name="objects" type="xsd:boolean" use="optional" default="false"/>
+# <xsd:attribute name="scenarios" type="xsd:boolean" use="optional" default="false"/>
+# <xsd:attribute name="formatCells" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="formatColumns" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="formatRows" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="insertColumns" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="insertRows" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="insertHyperlinks" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="deleteColumns" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="deleteRows" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="selectLockedCells" type="xsd:boolean" use="optional" default="false"/>
+# <xsd:attribute name="sort" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="autoFilter" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="pivotTables" type="xsd:boolean" use="optional" default="true"/>
+# <xsd:attribute name="selectUnlockedCells" type="xsd:boolean" use="optional" default="false"/>
+# </xsd:complexType>
+
+class TestSheetProtection < Test::Unit::TestCase
+ def setup
+ #inverse defaults
+ @options = { :sheet => true, :objects => true, :scenarios => true, :format_cells => false,
+ :format_columns => false, :format_rows => false, :insert_columns => false, :insert_rows => false,
+ :insert_hyperlinks => false, :delete_columns => false, :delete_rows => false, :select_locked_cells => true,
+ :sort => false, :auto_filter => false, :pivot_tables => false, :select_unlocked_cells => true }
+ @sp = Axlsx::SheetProtection.new(@options)
+ end
+
+ def test_initialize
+ sp = Axlsx::SheetProtection.new
+ @options.each do |key, value|
+ assert_equal(!value, sp.send(key.to_sym), "initialized default #{key} should be #{!value}")
+ assert_equal(value, @sp.send(key.to_sym), "initialized options #{key} should be #{value}")
+ end
+ { :algorithm_name => nil }.each do |key, value|
+ assert_equal(value, @sp.send(key.to_sym), "initialized default #{key} should be #{value}")
+ assert_equal(value, sp.send(key.to_sym), "initialized default #{key} should be #{value}")
+ end
+ end
+
+ def test_boolean_attribute_validation
+ @options.each do |key, value|
+ assert_raise(ArgumentError, "#{key} must be boolean") { @sp.send("#{key}=".to_sym, 'A') }
+ assert_nothing_raised { @sp.send("#{key}=".to_sym, true) }
+ assert_nothing_raised { @sp.send("#{key}=".to_sym, true) }
+ end
+ end
+
+
+ def test_to_xml_string
+ @sp.password = 'fish'
+ doc = Nokogiri::XML(@sp.to_xml_string)
+ @options.each do |key, value|
+ assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/){ $1.upcase }}='#{value}']"))
+ end
+ end
+
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 857437d8..8a9d0adb 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -252,6 +252,12 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1)
end
+ def test_to_xml_string_sheet_protection
+ @ws.sheet_protection.password = 'fish'
+ doc = Nokogiri::XML(@ws.to_xml_string)
+ assert(doc.xpath('//sheetProtection'))
+ end
+
def test_to_xml_string_page_margins
@ws.page_margins do |pm|
pm.left = 9