diff options
| author | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
| commit | e53f04284618713b0a90b7a691425c380e829476 (patch) | |
| tree | 801fea138160f9af426d62bf94ad5bf97123ece9 /test/stylesheet/tc_styles.rb | |
| download | caxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip | |
first commit
Diffstat (limited to 'test/stylesheet/tc_styles.rb')
| -rw-r--r-- | test/stylesheet/tc_styles.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb new file mode 100644 index 00000000..0c9b3fba --- /dev/null +++ b/test/stylesheet/tc_styles.rb @@ -0,0 +1,64 @@ +require 'test/unit' +require 'axlsx.rb' + +class TestStyles < Test::Unit::TestCase + def setup + @styles = Axlsx::Styles.new + end + def teardown + end + + def test_valid_document + schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) + doc = Nokogiri::XML(@styles.to_xml) + errors = [] + schema.validate(doc).each do |error| + errors.push error + puts error.message + end + assert(errors.size == 0) + end + + + def test_add_style + fill_count = @styles.fills.size + font_count = @styles.fonts.size + xf_count = @styles.cellXfs.size + + @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :num_fmt=>Axlsx::NUM_FMT_PERCENT, :alignment=>{:horizontal=>:left}, :border=>Axlsx::STYLE_THIN_BORDER, :hidden=>true, :locked=>true + assert_equal(@styles.fills.size, fill_count+1) + assert_equal(@styles.fonts.size, font_count+1) + assert_equal(@styles.cellXfs.size, xf_count+1) + xf = @styles.cellXfs.last + assert_equal(xf.fillId, (@styles.fills.size-1), "points to the last created fill") + assert_equal(@styles.fills.last.fill_type.fgColor.rgb, "FF000000", "fill created with color") + + assert_equal(xf.fontId, (@styles.fonts.size-1), "points to the last created font") + assert_equal(@styles.fonts.last.sz, 13, "font sz applied") + assert_equal(@styles.fonts.last.color.rgb, "FFFFFFFF", "font color applied") + + assert_equal(xf.borderId, Axlsx::STYLE_THIN_BORDER, "border id is set") + assert_equal(xf.numFmtId, Axlsx::NUM_FMT_PERCENT, "number format id is set") + + assert(xf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created") + assert_equal(xf.alignment.horizontal, :left, "horizontal alignment applied") + assert_equal(xf.applyProtection, 1, "protection applied") + assert_equal(xf.protection.hidden, true, "hidden protection set") + assert_equal(xf.protection.locked, true, "cell locking set") + assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 2 } + + end + + + #:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :dxfs, :tableStyles + def test_ensure_locking + assert_equal(@styles.numFmts.locked_at, 2, "numFmts should be locked at 2") + assert_equal(@styles.fonts.locked_at, 1, "fonts should be locked at 1" ) + assert_equal(@styles.fills.locked_at, 2, "fills should be locked at 2" ) + assert_equal(@styles.borders.locked_at, 2, "borders should be locked at two" ) + assert_equal(@styles.cellStyleXfs.locked_at, 1, "cellStyleXfs should be locked at two" ) + assert_equal(@styles.cellXfs.locked_at, 2, "cellXfs should be locked at 2" ) + assert_equal(@styles.dxfs.locked_at, 0, "dxfs should be locked at 0" ) + assert_equal(@styles.tableStyles.locked_at, 0, "tableStyles should be locked at 0" ) + end +end |
