public function testShortcodesInDataObject()
 {
     $formatter = new XMLDataFormatter();
     $page = new XMLDataFormatterTest_DataObject();
     $page->Content = 'This is some test content [test_shortcode]test[/test_shortcode]';
     $xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page));
     $this->assertEquals('This is some test content test', (string) $xml->Content);
     $page->Content = '[test_shortcode,id=-1]';
     $xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page));
     $this->assertEmpty('', (string) $xml->Content);
     $page->Content = '[bad_code,id=1]';
     $xml = new SimpleXMLElement('<?xml version="1.0"?>' . $formatter->convertDataObjectWithoutHeader($page));
     $this->assertContains('[bad_code,id=1]', (string) $xml->Content);
 }
Пример #2
0
 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);
 }
 /**
  * Write back to the content source
  */
 public function remoteWrite($member = null)
 {
     foreach ($this->remoteProperties as $prop => $val) {
         $this->wrappedObject->{$prop} = $val;
     }
     $this->wrappedObject->ID = $this->getSS_ID();
     $xmlFormatter = new XMLDataFormatter();
     $xmlFormatter->relationDepth = 0;
     $xml = $xmlFormatter->convertDataObjectWithoutHeader($this->wrappedObject);
     $params = array('raw_body' => $xml, 'ClassName' => $this->getType(), 'ID' => $this->getSS_ID());
     $this->getSource()->getRemoteRepository()->saveObject($params);
 }