Sha256: 361b76c64ac41e6ea492b9fc87fe7e9674347c1e7678483025685c90901ffe75

Contents?: true

Size: 1.81 KB

Versions: 19

Compression:

Stored size: 1.81 KB

Contents

require 'tc_helper.rb'

class TestWorksheetHyperlink < Test::Unit::TestCase
  def setup
    p = Axlsx::Package.new
    wb = p.workbook
    @ws = wb.add_worksheet
    @options = { :location => 'https://github.com/randym/axlsx?foo=1&bar=2', :tooltip => 'axlsx', :ref => 'A1', :display => 'AXSLX', :target => :internal }
    @a = @ws.add_hyperlink @options
  end

  def test_initailize
    assert_raise(ArgumentError) { Axlsx::WorksheetHyperlink.new }
  end

  def test_location
    assert_equal(@options[:location], @a.location)
  end

  def test_tooltip
    assert_equal(@options[:tooltip], @a.tooltip)
  end

  def test_target
    assert_equal(@options[:target], @a.instance_values['target'])
  end

  def test_display
    assert_equal(@options[:display], @a.display)
  end
  def test_ref
    assert_equal(@options[:ref], @a.ref)
  end

  def test_to_xml_string_with_non_external
    doc = Nokogiri::XML(@ws.to_xml_string)
    assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@r:id]").size, 0)
  end

  def test_to_xml_stirng_with_external
    @a.target = :external
    doc = Nokogiri::XML(@ws.to_xml_string)
    assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1)
    assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 0)
    assert_equal(doc.xpath("//xmlns:hyperlink[@r:id='#{@a.relationship.Id}']").size, 1)
  end
end


Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
caxlsx-3.1.1 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-3.1.0 test/workbook/worksheet/tc_worksheet_hyperlink.rb
bonio-axlsx-2.2.3 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-3.0.4 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-3.0.3 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-3.0.2 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-2.0.2 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-3.0.1 test/workbook/worksheet/tc_worksheet_hyperlink.rb
caxlsx-3.0.0 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-alt-3.0.1 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-alt-3.0.0 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-3.0.0.pre test/workbook/worksheet/tc_worksheet_hyperlink.rb
bonio-axlsx-2.2.2 test/workbook/worksheet/tc_worksheet_hyperlink.rb
bonio-axlsx-2.2.1 test/workbook/worksheet/tc_worksheet_hyperlink.rb
dg-axlsx-2.1.0 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-2.1.0.pre test/workbook/worksheet/tc_worksheet_hyperlink.rb
l_axlsx-2.0.1 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-2.0.1 test/workbook/worksheet/tc_worksheet_hyperlink.rb
axlsx-2.0.0 test/workbook/worksheet/tc_worksheet_hyperlink.rb