浏览代码

Test for an attribute with a namespace not registered at root element

Antonio J. García Lagar 12 年之前
父节点
当前提交
fe9c6da644

+ 8 - 1
tests/JMS/Serializer/Tests/Fixtures/ObjectWithXmlNamespaces.php

@@ -62,12 +62,19 @@ class ObjectWithXmlNamespaces
      * @XmlElement(namespace="http://www.w3.org/2005/Atom")
      * @XmlElement(namespace="http://www.w3.org/2005/Atom")
      */
      */
     private $author;
     private $author;
+    
+    /**
+     * @Type("string")
+     * @XmlAttribute(namespace="http://purl.org/dc/elements/1.1/");
+     */
+    private $language;
 
 
-    public function __construct($title, $author, \DateTime $createdAt)
+    public function __construct($title, $author, \DateTime $createdAt, $language)
     {
     {
         $this->title = $title;
         $this->title = $title;
         $this->author = $author;
         $this->author = $author;
         $this->createdAt = $createdAt;
         $this->createdAt = $createdAt;
+        $this->language = $language;
         $this->etag = sha1($this->createdAt->format(\DateTime::ISO8601));
         $this->etag = sha1($this->createdAt->format(\DateTime::ISO8601));
     }
     }
 }
 }

+ 3 - 1
tests/JMS/Serializer/Tests/Serializer/XmlSerializationTest.php

@@ -181,7 +181,7 @@ class XmlSerializationTest extends BaseSerializationTest
     
     
     public function testObjectWithXmlNamespaces()
     public function testObjectWithXmlNamespaces()
     {
     {
-        $object = new ObjectWithXmlNamespaces('This is a nice title.', 'Foo Bar', new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')));
+        $object = new ObjectWithXmlNamespaces('This is a nice title.', 'Foo Bar', new \DateTime('2011-07-30 00:00', new \DateTimeZone('UTC')), 'en');
         
         
         $xml = simplexml_load_string($this->serialize($object));
         $xml = simplexml_load_string($this->serialize($object));
         $xml->registerXPathNamespace('ns1', "http://purl.org/dc/elements/1.1/");
         $xml->registerXPathNamespace('ns1', "http://purl.org/dc/elements/1.1/");
@@ -190,6 +190,7 @@ class XmlSerializationTest extends BaseSerializationTest
         
         
         $this->assertEquals('2011-07-30T00:00:00+0000', $this->xpathFirstToString($xml, './@created_at'));
         $this->assertEquals('2011-07-30T00:00:00+0000', $this->xpathFirstToString($xml, './@created_at'));
         $this->assertEquals('1edf9bf60a32d89afbb85b2be849e3ceed5f5b10', $this->xpathFirstToString($xml, './@ns2:etag'));
         $this->assertEquals('1edf9bf60a32d89afbb85b2be849e3ceed5f5b10', $this->xpathFirstToString($xml, './@ns2:etag'));
+        $this->assertEquals('en', $this->xpathFirstToString($xml, './@ns1:language'));
         $this->assertEquals('This is a nice title.', $this->xpathFirstToString($xml, './ns1:title'));
         $this->assertEquals('This is a nice title.', $this->xpathFirstToString($xml, './ns1:title'));
         $this->assertEquals('Foo Bar', $this->xpathFirstToString($xml, './ns3:author'));
         $this->assertEquals('Foo Bar', $this->xpathFirstToString($xml, './ns3:author'));
 
 
@@ -197,6 +198,7 @@ class XmlSerializationTest extends BaseSerializationTest
         $this->assertEquals('2011-07-30T00:00:00+0000', $this->getField($deserialized, 'createdAt')->format(\DateTime::ISO8601));
         $this->assertEquals('2011-07-30T00:00:00+0000', $this->getField($deserialized, 'createdAt')->format(\DateTime::ISO8601));
         $this->assertAttributeEquals('This is a nice title.', 'title', $deserialized);
         $this->assertAttributeEquals('This is a nice title.', 'title', $deserialized);
         $this->assertAttributeSame('1edf9bf60a32d89afbb85b2be849e3ceed5f5b10', 'etag', $deserialized);
         $this->assertAttributeSame('1edf9bf60a32d89afbb85b2be849e3ceed5f5b10', 'etag', $deserialized);
+        $this->assertAttributeSame('en', 'language', $deserialized);
         $this->assertAttributeEquals('Foo Bar', 'author', $deserialized);
         $this->assertAttributeEquals('Foo Bar', 'author', $deserialized);
 
 
     }
     }

+ 1 - 1
tests/JMS/Serializer/Tests/Serializer/xml/object_with_xml_namespaces.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<test-object xmlns="http://example.com/namespace" xmlns:name1="http://schemas.google.com/g/2005" xmlns:name2="http://www.w3.org/2005/Atom" xmlns:name3="http://purl.org/dc/elements/1.1/" created_at="2011-07-30T00:00:00+0000" name1:etag="1edf9bf60a32d89afbb85b2be849e3ceed5f5b10">
+<test-object xmlns="http://example.com/namespace" xmlns:name1="http://schemas.google.com/g/2005" xmlns:name2="http://www.w3.org/2005/Atom" xmlns:name3="http://purl.org/dc/elements/1.1/" created_at="2011-07-30T00:00:00+0000" name1:etag="1edf9bf60a32d89afbb85b2be849e3ceed5f5b10" name3:language="en">
   <name3:title><![CDATA[This is a nice title.]]></name3:title>
   <name3:title><![CDATA[This is a nice title.]]></name3:title>
   <name2:author><![CDATA[Foo Bar]]></name2:author>
   <name2:author><![CDATA[Foo Bar]]></name2:author>
 </test-object>
 </test-object>