Sha256: f48e49e36813ddf3043a4c39e7fee8d97ca06be981db6e92d248f22389665d7d

Contents?: true

Size: 1.91 KB

Versions: 115

Compression:

Stored size: 1.91 KB

Contents

require "helper"

module Nokogiri
  module XML
    class TestAttr < Nokogiri::TestCase
      def test_new
        100.times {
          doc = Nokogiri::XML::Document.new
          assert doc
          assert Nokogiri::XML::Attr.new(doc, 'foo')
        }
      end

      def test_content=
        xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
        address = xml.xpath('//address')[3]
        street = address.attributes['street']
        street.content = "Y&ent1;"
        assert_equal "Y&ent1;", street.value
      end

      def test_value=
        xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
        address = xml.xpath('//address')[3]
        street = address.attributes['street']
        street.value = "Y&ent1;"
        assert_equal "Y&ent1;", street.value
      end

      def test_unlink # aliased as :remove
        xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
        address = xml.xpath('/staff/employee/address').first
        assert_equal 'Yes', address['domestic']

        attr = address.attribute_nodes.first
        return_val = attr.unlink
        assert_nil address['domestic']
        assert_equal attr, return_val
      end

      def test_parsing_attribute_namespace
        doc = Nokogiri::XML <<-EOXML
<root xmlns='http://google.com/' xmlns:f='http://flavorjon.es/'>
  <div f:myattr='foo'></div>
</root>
        EOXML

        node = doc.at_css "div"
        attr = node.attributes["myattr"]
        assert_equal "http://flavorjon.es/", attr.namespace.href
      end

      def test_setting_attribute_namespace
        doc = Nokogiri::XML <<-EOXML
<root xmlns='http://google.com/' xmlns:f='http://flavorjon.es/'>
  <div f:myattr='foo'></div>
</root>
        EOXML

        node = doc.at_css "div"
        attr = node.attributes["myattr"]
        attr.add_namespace("fizzle", "http://fizzle.com/")
        assert_equal "http://fizzle.com/", attr.namespace.href
      end
    end
  end
end

Version data entries

115 entries across 111 versions & 13 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/nokogiri-1.7.1/test/xml/test_attr.rb
tdiary-5.0.5 vendor/bundle/gems/nokogiri-1.7.1/test/xml/test_attr.rb
nokogiri-1.7.2 test/xml/test_attr.rb
nokogiri-1.7.2-x86-mingw32 test/xml/test_attr.rb
nokogiri-1.7.2-x64-mingw32 test/xml/test_attr.rb
nokogiri-1.7.2-java test/xml/test_attr.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/nokogiri-1.7.1/test/xml/test_attr.rb
tdiary-5.0.4 vendor/bundle/gems/nokogiri-1.7.1/test/xml/test_attr.rb
nokogiri-1.7.1 test/xml/test_attr.rb
nokogiri-1.7.1-x86-mingw32 test/xml/test_attr.rb
nokogiri-1.7.1-x64-mingw32 test/xml/test_attr.rb
nokogiri-1.7.1-java test/xml/test_attr.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.7.0.1/test/xml/test_attr.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/nokogiri-1.6.8.1/test/xml/test_attr.rb