# encoding: UTF-8 require 'tc_helper.rb' # # # # # # # # # # # # # # # # # # # class TestSheetProtection < Test::Unit::TestCase def setup #inverse defaults @boolean_options = { :sheet => false, :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 } @string_options = { :password => nil } @options = @boolean_options.merge(@string_options) @sp = Axlsx::SheetProtection.new(@options) end def test_initialize sp = Axlsx::SheetProtection.new @boolean_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 end def test_boolean_attribute_validation @boolean_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' # -> CA3F 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