From 5319e89b5cccc3713eff37820148d66f8f31834e Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Tue, 5 Aug 2008 03:24:18 +0000 Subject: [PATCH] Refactoring RssHelper tests. Adding tests to multiple category inside item. Refs #5135. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7434 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/view/helpers/rss.test.php | 240 ++++++++++++++---- 1 file changed, 190 insertions(+), 50 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php index 1e3b2efeb..eec023eae 100644 --- a/cake/tests/cases/libs/view/helpers/rss.test.php +++ b/cake/tests/cases/libs/view/helpers/rss.test.php @@ -74,8 +74,14 @@ class RssTest extends CakeTestCase { $this->Rss->removeNs('custom'); $this->Rss->addNs('dummy', 'http://dummy.com/1.0/'); - $res = $this->Rss->document(); - $this->assertPattern('/^$/', $res); + $result = $this->Rss->document(); + $expected = array( + 'rss' => array( + 'xmlns:dummy' => 'http://dummy.com/1.0/', + 'version' => '2.0' + ) + ); + $this->assertTags($result, $expected); $this->Rss->removeNs('dummy'); } @@ -104,19 +110,41 @@ class RssTest extends CakeTestCase { * @return void */ function testDocument() { - $res = $this->Rss->document(); - $this->assertPattern('/^$/', $res); + $result = $this->Rss->document(); + $expected = array( + 'rss' => array( + 'version' => '2.0' + ) + ); + $this->assertTags($result, $expected); - $res = $this->Rss->document(array('contrived' => 'parameter')); - $this->assertPattern('/^<\/rss>$/', $res); + $result = $this->Rss->document(array('contrived' => 'parameter')); + $expected = array( + 'rss' => array( + 'version' => '2.0' + ), + 'assertTags($result, $expected); - $res = $this->Rss->document(null, 'content'); - $this->assertPattern('/^content<\/rss>$/', $res); + $result = $this->Rss->document(null, 'content'); + $expected = array( + 'rss' => array( + 'version' => '2.0' + ), + 'content' + ); + $this->assertTags($result, $expected); - $res = $this->Rss->document(array('contrived' => 'parameter'), 'content'); - $this->assertPattern('/^]+version="2.0"[^<>]*>/', $res); - $this->assertPattern('/]+contrived="parameter"[^<>]*>/', $res); - $this->assertNoPattern('/]+[^version|contrived]=[^<>]*>/', $res); + $result = $this->Rss->document(array('contrived' => 'parameter'), 'content'); + $expected = array( + 'rss' => array( + 'contrived' => 'parameter', + 'version' => '2.0' + ), + 'content' + ); + $this->assertTags($result, $expected); } /** * testChannel method @@ -126,16 +154,26 @@ class RssTest extends CakeTestCase { */ function testChannel() { $attrib = array('a' => '1', 'b' => '2'); - $elements['title'] = 'title'; + $elements = array('title' => 'title'); $content = 'content'; - $res = $this->Rss->channel($attrib, $elements, $content); - $this->assertPattern('/^]+a="1"[^<>]*>/', $res); - $this->assertPattern('/^]+b="2"[^<>]*>/', $res); - $this->assertNoPattern('/^]+[^a|b]=[^<>]*/', $res); - $this->assertPattern('/title<\/title>/', $res); - $this->assertPattern('/<link>'.str_replace('/', '\/', RssHelper::url('/', true)).'<\/link>/', $res); - $this->assertPattern('/<description \/>/', $res); - $this->assertPattern('/content<\/channel>$/', $res); + + $result = $this->Rss->channel($attrib, $elements, $content); + $expected = array( + 'channel' => array( + 'a' => '1', + 'b' => '2' + ), + '<title', + 'title', + '/title', + '<link', + RssHelper::url('/', true), + '/link', + '<description', + 'content', + '/channel' + ); + $this->assertTags($result, $expected); } /** * testChannelElementLevelAttrib method @@ -145,16 +183,36 @@ class RssTest extends CakeTestCase { */ function testChannelElementLevelAttrib() { $attrib = array(); - $elements['title'] = 'title'; - $elements['image'] = array('myImage', 'attrib' => array('href' => 'http://localhost')); + $elements = array( + 'title' => 'title', + '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); + + $result = $this->Rss->channel($attrib, $elements, $content); + $expected = array( + '<channel', + '<title', + 'title', + '/title', + 'image' => array( + 'href' => 'http://localhost' + ), + '<myImage', + '/image', + '<link', + RssHelper::url('/', true), + '/link', + '<description', + 'content', + '/channel' + ); + $this->assertTags($result, $expected); } /** * testItems method @@ -170,22 +228,31 @@ class RssTest extends CakeTestCase { ); $result = $this->Rss->items($items); - $this->assertPattern('/^<item>.*<\/item><item>.*<\/item><item>.*<\/item>$/', $result); - $this->assertPattern('/<item>.*<title>title1<\/title>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<guid>' . str_replace('/', '\/', 'http://www.example.com/guid1') . '<\/guid>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<link>' . str_replace('/', '\/', 'http://www.example.com/link1') . '<\/link>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<description>description1<\/description>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<title>title2<\/title>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<guid>' . str_replace('/', '\/', 'http://www.example.com/guid2') . '<\/guid>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<link>' . str_replace('/', '\/', 'http://www.example.com/link2') . '<\/link>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<description>description2<\/description>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<title>title3<\/title>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<guid>' . str_replace('/', '\/', 'http://www.example.com/guid3') . '<\/guid>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<link>' . str_replace('/', '\/', 'http://www.example.com/link3') . '<\/link>.*<\/item>/', $result); - $this->assertPattern('/<item>.*<description>description3<\/description>.*<\/item>/', $result); + $expected = array( + '<item', + '<title', 'title1', '/title', + '<guid', 'http://www.example.com/guid1', '/guid', + '<link', 'http://www.example.com/link1', '/link', + '<description', 'description1', '/description', + '/item', + '<item', + '<title', 'title2', '/title', + '<guid', 'http://www.example.com/guid2', '/guid', + '<link', 'http://www.example.com/link2', '/link', + '<description', 'description2', '/description', + '/item', + '<item', + '<title', 'title3', '/title', + '<guid', 'http://www.example.com/guid3', '/guid', + '<link', 'http://www.example.com/link3', '/link', + '<description', 'description3', '/description', + '/item' + ); + $this->assertTags($result, $expected); $result = $this->Rss->items(array()); - $this->assertEqual($result, ''); + $expected = ''; + $this->assertEqual($result, $expected); } /** * testItem method @@ -194,9 +261,29 @@ class RssTest extends CakeTestCase { * @return void */ function testItem() { - $result = $this->Rss->item(null, array("title"=>"My title","description"=>"My description","link"=>"http://www.google.com/")); - $expecting = '<item><title>My titleMy descriptionhttp://www.google.com/http://www.google.com/'; - $this->assertEqual($result, $expecting); + $item = array( + 'title' => 'My title', + 'description' => 'My description', + 'link' => 'http://www.google.com/' + ); + $result = $this->Rss->item(null, $item); + $expected = array( + 'assertTags($result, $expected); $item = array( 'title' => array( @@ -281,6 +368,49 @@ class RssTest extends CakeTestCase { '/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( + ' array('domain' => 'http://www.cakephp.org'), + '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( + ' array('domain' => 'http://www.cakephp.org'), + 'assertTags($result, $expected); } /** * testTime method @@ -297,13 +427,23 @@ class RssTest extends CakeTestCase { * @return void */ function testElementAttrNotInParent() { - $attributes = array('title' => 'Some Title', 'link' => 'http://link.com', 'description' => 'description'); + $attributes = array( + 'title' => 'Some Title', + 'link' => 'http://link.com', + 'description' => 'description' + ); $elements = array('enclosure' => array('url' => 'http://test.com')); $result = $this->Rss->item($attributes, $elements); $expected = array( - 'item' => array('title' => 'Some Title', 'link' => 'http://link.com', 'description' => 'description'), - 'enclosure' => array('url' => 'http://test.com'), + 'item' => array( + 'title' => 'Some Title', + 'link' => 'http://link.com', + 'description' => 'description' + ), + 'enclosure' => array( + 'url' => 'http://test.com' + ), '/item' ); $this->assertTags($result, $expected);