From cfa22296890894e70ab681f68544c5bf3dacd107 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 24 Nov 2008 23:10:29 +0000 Subject: [PATCH] Fixing incorrect implementation of RssHelper::channel(). Test cases added. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7887 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/rss.php | 14 ++++- .../cases/libs/view/helpers/rss.test.php | 56 +++++++++++-------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/cake/libs/view/helpers/rss.php b/cake/libs/view/helpers/rss.php index 827483a49..74e1274d3 100644 --- a/cake/libs/view/helpers/rss.php +++ b/cake/libs/view/helpers/rss.php @@ -138,9 +138,17 @@ class RssHelper extends XmlHelper { $elems = ''; foreach ($elements as $elem => $data) { $attributes = array(); - if (is_array($data) && isset($data['attrib']) && is_array($data['attrib'])) { - $attributes = $data['attrib']; - unset($data['attrib']); + if (is_array($data)) { + if (strtolower($elem) == 'cloud') { + $attributes = $data; + $data = array(); + } else { + $innerElements = ''; + foreach ($data as $subElement => $value) { + $innerElements .= $this->elem($subElement, array(), $value); + } + $data = $innerElements; + } } $elems .= $this->elem($elem, $attributes, $data); } diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php index 772e065ed..08b0db33c 100644 --- a/cake/tests/cases/libs/view/helpers/rss.test.php +++ b/cake/tests/cases/libs/view/helpers/rss.test.php @@ -173,41 +173,51 @@ class RssTest extends CakeTestCase { $this->assertTags($result, $expected); } /** - * testChannelElementLevelAttrib method + * test correct creation of channel sub elements. * * @access public * @return void */ - function testChannelElementLevelAttrib() { + function testChannelElements() { $attrib = array(); $elements = array( - 'title' => 'title', + 'title' => 'Title of RSS Feed', + 'link' => 'http://example.com', + 'description' => 'Description of RSS Feed', 'image' => array( - 'myImage', - 'attrib' => array( - 'href' => 'http://localhost' - ) + 'title' => 'Title of image', + 'url' => 'http://example.com/example.png', + 'link' => 'http://example.com' + ), + 'cloud' => array( + 'domain' => "rpc.sys.com", + 'port' => "80", + 'path' =>"/RPC2", + 'registerProcedure' => "myCloud.rssPleaseNotify", + 'protocol' => "xml-rpc" ) ); - $content = 'content'; - + $content = 'content-here'; $result = $this->Rss->channel($attrib, $elements, $content); $expected = array( ' array( - 'href' => 'http://localhost' - ), - ' array( + 'domain' => "rpc.sys.com", + 'port' => "80", + 'path' =>"/RPC2", + 'registerProcedure' => "myCloud.rssPleaseNotify", + 'protocol' => "xml-rpc" + ), + 'content-here', + '/channel', ); $this->assertTags($result, $expected); }