summaryrefslogtreecommitdiffhomepage
path: root/test/doc_props/tc_core.rb
blob: 5a04a615021399125e8e1a36f93006f277d599c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'tc_helper'

class TestCore < Test::Unit::TestCase
  def setup
    @core = Axlsx::Core.new
    # could still see some false positives if the second changes between the next two calls
    @time = Time.now.strftime('%Y-%m-%dT%H:%M:%SZ')
    @doc = Nokogiri::XML(@core.to_xml_string)
  end

  def test_valid_document
    schema = Nokogiri::XML::Schema(File.open(Axlsx::CORE_XSD))
    errors = []
    schema.validate(@doc).each do |error|
      puts error.message
      errors << error
    end

    assert_equal(0, errors.size, "core.xml Invalid#{errors.map(&:message)}")
  end

  def test_populates_created
    assert_equal(@doc.xpath('//dcterms:created').text, @time, "dcterms:created incorrect")
  end

  def test_created_as_option
    time = Time.utc(2013, 1, 1, 12, 0)
    c = Axlsx::Core.new created: time
    doc = Nokogiri::XML(c.to_xml_string)

    assert_equal(doc.xpath('//dcterms:created').text, time.xmlschema, "dcterms:created incorrect")
  end

  def test_populates_default_name
    assert_equal("axlsx", @doc.xpath('//dc:creator').text, "Default name not populated")
  end

  def test_creator_as_option
    c = Axlsx::Core.new creator: "some guy"
    doc = Nokogiri::XML(c.to_xml_string)

    assert_equal("some guy", doc.xpath('//dc:creator').text)
  end
end