/** * testItem method * * @access public * @return void */ function testItem() { $item = array('title' => 'My title', 'description' => 'My description', 'link' => 'http://www.google.com/'); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', 'My title', '/title', '<description', 'My description', '/description', '<link', 'http://www.google.com/', '/link', '<guid', 'http://www.google.com/', '/guid', '/item'); $this->assertTags($result, $expected); $item = array('title' => array('value' => 'My Title', 'cdata' => true), 'link' => 'http://www.example.com/1', 'description' => array('value' => 'descriptive words', 'cdata' => true), 'pubDate' => '2008-05-31 12:00:00', 'guid' => 'http://www.example.com/1'); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', '<![CDATA[My Title]]', '/title', '<link', 'http://www.example.com/1', '/link', '<description', '<![CDATA[descriptive words]]', '/description', '<pubDate', date('r', strtotime('2008-05-31 12:00:00')), '/pubDate', '<guid', 'http://www.example.com/1', '/guid', '/item'); $this->assertTags($result, $expected); $item = array('title' => array('value' => 'My Title & more', 'cdata' => true)); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', '<![CDATA[My Title & more]]', '/title', '/item'); $this->assertTags($result, $expected); $item = array('title' => array('value' => 'My Title & more', 'convertEntities' => false)); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', 'My Title & more', '/title', '/item'); $this->assertTags($result, $expected); $item = array('title' => array('value' => 'My Title & more', 'cdata' => true, 'convertEntities' => false)); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', '<![CDATA[My Title & more]]', '/title', '/item'); $this->assertTags($result, $expected); $item = array('category' => array('value' => 'CakePHP', 'cdata' => true, 'domain' => 'http://www.cakephp.org')); $result = $this->Rss->item(null, $item); $expected = array('<item', 'category' => array('domain' => 'http://www.cakephp.org'), '<![CDATA[CakePHP]]', '/category', '/item'); $this->assertTags($result, $expected); $item = array('category' => array(array('value' => 'CakePHP', 'cdata' => true, 'domain' => 'http://www.cakephp.org'), array('value' => 'Bakery', 'cdata' => true))); $result = $this->Rss->item(null, $item); $expected = array('<item', 'category' => array('domain' => 'http://www.cakephp.org'), '<![CDATA[CakePHP]]', '/category', '<category', '<![CDATA[Bakery]]', '/category', '/item'); $this->assertTags($result, $expected); $item = array('title' => array('value' => 'My Title', 'cdata' => true), 'link' => 'http://www.example.com/1', 'description' => array('value' => 'descriptive words', 'cdata' => true), 'enclosure' => array('url' => '/test.flv'), 'pubDate' => '2008-05-31 12:00:00', 'guid' => 'http://www.example.com/1', 'category' => array(array('value' => 'CakePHP', 'cdata' => true, 'domain' => 'http://www.cakephp.org'), array('value' => 'Bakery', 'cdata' => true))); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', '<![CDATA[My Title]]', '/title', '<link', 'http://www.example.com/1', '/link', '<description', '<![CDATA[descriptive words]]', '/description', 'enclosure' => array('url' => RssHelper::url('/test.flv', true)), '<pubDate', date('r', strtotime('2008-05-31 12:00:00')), '/pubDate', '<guid', 'http://www.example.com/1', '/guid', 'category' => array('domain' => 'http://www.cakephp.org'), '<![CDATA[CakePHP]]', '/category', '<category', '<![CDATA[Bakery]]', '/category', '/item'); $this->assertTags($result, $expected); $item = array('title' => 'Foo bar', 'link' => array('url' => 'http://example.com/foo?a=1&b=2', 'convertEntities' => false), 'description' => array('value' => 'descriptive words', 'cdata' => true), 'pubDate' => '2008-05-31 12:00:00'); $result = $this->Rss->item(null, $item); $expected = array('<item', '<title', 'Foo bar', '/title', '<link', 'http://example.com/foo?a=1&b=2', '/link', '<description', '<![CDATA[descriptive words]]', '/description', '<pubDate', date('r', strtotime('2008-05-31 12:00:00')), '/pubDate', '<guid', 'http://example.com/foo?a=1&b=2', '/guid', '/item'); $this->assertTags($result, $expected); }
function testChannelElementLevelAttrib() { $attrib = array(); $elements['title'] = 'title'; $elements['image'] = array('myImage', 'attrib' => array('href' => 'http://localhost')); $content = 'content'; $res = $this->Rss->channel($attrib, $elements, $content); $this->assertPattern('/^<channel>/', $res); $this->assertPattern('/<title>title<\\/title>/', $res); $this->assertPattern('/<image[^<>]+href="http:\\/\\/localhost">myImage<\\/image>/', $res); $this->assertPattern('/<link>' . str_replace('/', '\\/', RssHelper::url('/', true)) . '<\\/link>/', $res); $this->assertPattern('/<description \\/>/', $res); $this->assertPattern('/content<\\/channel>$/', $res); }