diff --git a/cake/libs/view/helpers/rss.php b/cake/libs/view/helpers/rss.php index f9b361a19..80cdc65d6 100644 --- a/cake/libs/view/helpers/rss.php +++ b/cake/libs/view/helpers/rss.php @@ -35,11 +35,12 @@ App::import('Helper', 'Xml'); class RssHelper extends XmlHelper { - - var $Html = null; - - var $Time = null; - +/** + * Helpers used by RSS Helper + * + * @var array + * @access public + **/ var $helpers = array('Time'); /** * Base URL @@ -189,6 +190,22 @@ class RssHelper extends XmlHelper { case 'pubDate' : $val = $this->time($val); break; + case 'category' : + if (is_array($val) && !empty($val[0])) { + foreach ($val as $category) { + $attrib = array(); + if (isset($category['domain'])) { + $attrib['domain'] = $category['domain']; + unset($category['domain']); + } + $categories[] = $this->elem($key, $attrib, $category); + } + $elements[$key] = join('', $categories); + continue 2; + } else if (is_array($val) && isset($val['domain'])) { + $attrib['domain'] = $val['domain']; + } + break; case 'link': case 'guid': case 'comments': @@ -232,7 +249,6 @@ class RssHelper extends XmlHelper { } $elements[$key] = $this->elem($key, $attrib, $val); } - if (!empty($elements)) { $content = join('', $elements); } diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php index eec023eae..735e63df0 100644 --- a/cake/tests/cases/libs/view/helpers/rss.test.php +++ b/cake/tests/cases/libs/view/helpers/rss.test.php @@ -26,9 +26,6 @@ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { - define('CAKEPHP_UNIT_TEST_EXECUTION', 1); -} App::import('Helper', array('Rss', 'Time')); /** @@ -254,6 +251,7 @@ class RssTest extends CakeTestCase { $expected = ''; $this->assertEqual($result, $expected); } + /** * testItem method * @@ -411,6 +409,62 @@ class RssTest extends CakeTestCase { '/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( + ' array('url' => RssHelper::url('/test.flv', true)), + ' array('domain' => 'http://www.cakephp.org'), + 'assertTags($result, $expected); } /** * testTime method