Sha256: 35cef02360c23cc3ff0efb4370bec2a11e7a55e081532a1557c1aa1d06cb029d

Contents?: true

Size: 1.78 KB

Versions: 10

Compression:

Stored size: 1.78 KB

Contents

# -*- encoding: utf-8 -*-

require 'test_helper'
require 'hexapdf/document'
require 'hexapdf/type/acro_form/field'

describe HexaPDF::Type::AcroForm::Field do
  before do
    @doc = HexaPDF::Document.new
    @field = @doc.add({}, type: :XXAcroFormField)
  end

  it "must always be an indirect object" do
    assert(@field.must_be_indirect?)
  end

  it "resolves inherited field values" do
    assert_nil(@field[:FT])

    @field[:Parent] = {FT: :Tx}
    assert_equal(:Tx, @field[:FT])

    @field[:FT] = :Ch
    assert_equal(:Ch, @field[:FT])
  end

  it "returns the field type" do
    assert_nil(@field.field_type)

    @field[:FT] = :Tx
    assert_equal(:Tx, @field.field_type)
  end

  it "returns the full name of the field" do
    assert_nil(@field.full_name)

    @field[:T] = "Test"
    assert_equal("Test", @field.full_name)

    @field[:Parent] = {}
    assert_equal("Test", @field.full_name)

    @field[:Parent] = {T: 'Parent'}
    assert_equal("Parent.Test", @field.full_name)
  end

  it "returns whether the field is a terminal field" do
    assert(@field.terminal_field?)

    @field[:Kids] = []
    assert(@field.terminal_field?)

    @field[:Kids] = [{Subtype: :Widget}]
    assert(@field.terminal_field?)

    @field[:Kids] = [{FT: :Tx}]
    refute(@field.terminal_field?)
  end

  describe "perform_validation" do
    before do
      @field[:FT] = :Tx
    end

    it "requires the /FT key to be present for terminal fields" do
      assert(@field.validate)

      @field.delete(:FT)
      refute(@field.validate)

      @field[:Kids] = [{}]
      assert(@field.validate)
    end

    it "doesn't allow periods in partial field names" do
      assert(@field.validate)

      @field[:T] = "Test"
      assert(@field.validate)

      @field[:T] = "Te.st"
      refute(@field.validate)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hexapdf-0.11.9 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.8 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.7 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.6 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.5 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.4 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.3 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.2 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.1 test/hexapdf/type/acro_form/test_field.rb
hexapdf-0.11.0 test/hexapdf/type/acro_form/test_field.rb