2010-12-20 05:51:24 +01:00
< ? php
class XMLDataFormatterTest extends SapphireTest {
2011-03-30 08:49:11 +02:00
public static $fixture_file = 'XMLDataFormatterTest.yml' ;
2010-12-20 05:51:24 +01:00
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'
);
2012-03-24 04:04:52 +01:00
}