silverstripe-framework/tests/api/XMLDataFormatterTest.php
Sean Harvey 2b0729d435 ENHANCEMENT XMLDataFormatter::convertDataObjectWithoutHeader() now escapes HTML fields using CDATA (thanks random-value!)
MINOR Added unit test for XMLDataFormatter::convertDataObjectWithoutHeader()


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@115229 467b73ca-7a2a-4603-9d3b-597d59a354a9
2010-12-20 04:51:24 +00:00

40 lines
1.4 KiB
PHP

<?php
class XMLDataFormatterTest extends SapphireTest {
public static $fixture_file = 'sapphire/tests/api/XMLDataFormatterTest.yml';
protected $extraDataObjects = array(
'XMLDataFormatterTest_DataObject'
);
public function testConvertDataObjectWithoutHeader() {
$formatter = new XMLDataFormatter();
$obj = $this->objFromFixture('XMLDataFormatterTest_DataObject', 'test-do');
$xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($obj));
$this->assertEquals(
Director::absoluteBaseURL() . sprintf('api/v1/XMLDataFormatterTest_DataObject/%d.xml', $obj->ID),
(string) $xml['href']
);
$this->assertEquals('Test DataObject', (string) $xml->Name);
$this->assertEquals('Test Company', (string) $xml->Company);
$this->assertEquals($obj->ID, (int) $xml->ID);
$this->assertEquals(
'<Content><![CDATA[<a href="http://mysite.com">mysite.com</a> is a link in this HTML content. <![CDATA[this is some nested CDATA]]]]><![CDATA[>]]></Content>',
$xml->Content->asXML()
);
$this->assertEquals(
'<a href="http://mysite.com">mysite.com</a> is a link in this HTML content. <![CDATA[this is some nested CDATA]]>',
(string) $xml->Content
);
}
}
class XMLDataFormatterTest_DataObject extends DataObject implements TestOnly {
public static $db = array(
'Name' => 'Varchar(50)',
'Company' => 'Varchar(50)',
'Content' => 'HTMLText'
);
}