Changeset 2252

Show
Ignore:
Timestamp:
06/23/09 19:56:35 (13 months ago)
Author:
mikey
Message:

fix defect #205: empty document fragments should be serialized as tag only

Location:
framework/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • framework/trunk/src/main/php/net/stubbles/xml/serializer/stubXMLSerializer.php

    r2207 r2252  
    177177                if (null != $data['tagName']) { 
    178178                    $xmlWriter->writeStartElement($data['tagName']); 
    179                     if (true === $data['nl2br']) { 
    180                         $value = str_replace('&', '&', nl2br($value)); 
     179                    if (empty($value) === false) { 
     180                        if (true === $data['nl2br']) { 
     181                            $value = str_replace('&', '&', nl2br($value)); 
     182                        } 
     183                         
     184                        $xmlWriter->writeXmlFragment($value); 
    181185                    } 
    182186                     
    183                     $xmlWriter->writeXmlFragment($value); 
    184187                    $xmlWriter->writeEndElement(); 
    185                 } else { 
     188                } elseif (empty($value) === false) { 
    186189                    $xmlWriter->writeXmlFragment($value); 
    187190                } 
  • framework/trunk/src/test/php/net/stubbles/xml/serializer/stubXMLSerializerTestCase.php

    r2207 r2252  
    192192     */ 
    193193    public $xml3 = "foo\nb&ar\n\nbaz"; 
     194} 
     195 
     196/** 
     197 * Simple Test class to test the XMLSerializer 
     198 * 
     199 * @XMLTag(tagName='test') 
     200 */ 
     201class XMLSerializerFragmentTest2 
     202{ 
     203    /** 
     204     * Property containing no XML 
     205     * 
     206     * @XMLFragment(tagName='noXml'); 
     207     * @var string 
     208     */ 
     209    public $noXml = 'bar'; 
     210    /** 
     211     * Property containing no data 
     212     * 
     213     * @XMLFragment(tagName='noData'); 
     214     * @var string 
     215     */ 
     216    public $noData; 
     217    /** 
     218     * Property containing no data 
     219     * 
     220     * @XMLFragment(tagName=false); 
     221     * @var string 
     222     */ 
     223    public $noData2; 
    194224} 
    195225 
     
    577607 
    578608    /** 
     609     * Test serializing an object with an invalid xml fragment 
     610     * 
     611     * @test 
     612     */ 
     613    public function objectInvalidFragmentProperty() 
     614    { 
     615        $writer = new stubDomXMLStreamWriter(); 
     616        $obj    = new XMLSerializerFragmentTest2(); 
     617        $this->serializer->serialize($obj, $writer); 
     618        $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<test><noXml>bar</noXml><noData/></test>', $writer->asXML()); 
     619    } 
     620 
     621    /** 
    579622     * Test serializing an object with empty attributes 
    580623     *