Sha256: 60a72877144323dd7666516c5490d27819150c72ca9abd941062501bf1ce4c53

Contents?: true

Size: 1.95 KB

Versions: 19

Compression:

Stored size: 1.95 KB

Contents

# -*- coding: utf-8 -*-
require 'helper'
require 'write_xlsx/workbook'
require 'write_xlsx/worksheet'
require 'stringio'

class TestWriteHeaderFooter < Minitest::Test
  def setup
    @workbook = WriteXLSX.new(StringIO.new)
    @worksheet = @workbook.add_worksheet('')
    @writer    = @worksheet.instance_variable_get(:@writer)
  end

  def test_write_odd_header
    @worksheet.set_header('Page &P of &N')
    @worksheet.
      instance_variable_get(:@page_setup).
      __send__('write_odd_header', @writer)
    result = @writer.string
    expected = '<oddHeader>Page &amp;P of &amp;N</oddHeader>'
    assert_equal(expected, result)
  end

  def test_write_odd_footer
    @worksheet.set_footer('&F')
    @worksheet.
      instance_variable_get(:@page_setup).
      __send__('write_odd_footer', @writer)
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<oddFooter>&amp;F</oddFooter>'
    assert_equal(expected, result)
  end

  def test_write_haeder_footer_only_header
    @worksheet.set_header('Page &P of &N')
    @worksheet.__send__('write_header_footer')
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<headerFooter><oddHeader>Page &amp;P of &amp;N</oddHeader></headerFooter>'
    assert_equal(expected, result)
  end

  def test_write_haeder_footer_only_footer
    @worksheet.set_footer('&F')
    @worksheet.__send__('write_header_footer')
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<headerFooter><oddFooter>&amp;F</oddFooter></headerFooter>'
    assert_equal(expected, result)
  end

  def test_write_haeder_footer_both_header_and_footer
    @worksheet.set_header('Page &P of &N')
    @worksheet.set_footer('&F')
    @worksheet.__send__('write_header_footer')
    result = @worksheet.instance_variable_get(:@writer).string
    expected = '<headerFooter><oddHeader>Page &amp;P of &amp;N</oddHeader><oddFooter>&amp;F</oddFooter></headerFooter>'
    assert_equal(expected, result)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
write_xlsx-1.09.4 test/worksheet/test_write_header_footer.rb
write_xlsx-1.09.3 test/worksheet/test_write_header_footer.rb
write_xlsx-1.09.2 test/worksheet/test_write_header_footer.rb
write_xlsx-1.09.1 test/worksheet/test_write_header_footer.rb
write_xlsx-1.09.0 test/worksheet/test_write_header_footer.rb
write_xlsx-1.08.2 test/worksheet/test_write_header_footer.rb
write_xlsx-1.08.1 test/worksheet/test_write_header_footer.rb
write_xlsx-1.08.0 test/worksheet/test_write_header_footer.rb
write_xlsx-1.07.0 test/worksheet/test_write_header_footer.rb
write_xlsx-1.04.0 test/worksheet/test_write_header_footer.rb
write_xlsx-1.02.0 test/worksheet/test_write_header_footer.rb
write_xlsx-1.01.0 test/worksheet/test_write_header_footer.rb
write_xlsx-1.00.0 test/worksheet/test_write_header_footer.rb
write_xlsx-0.99.0 test/worksheet/test_write_header_footer.rb
write_xlsx-0.97.0 test/worksheet/test_write_header_footer.rb
write_xlsx-0.90.0 test/worksheet/test_write_header_footer.rb
write_xlsx-0.89.0 test/worksheet/test_write_header_footer.rb
write_xlsx-0.88.0 test/worksheet/test_write_header_footer.rb
write_xlsx-0.87.0 test/worksheet/test_write_header_footer.rb