Added category handling to RssHelper. Additional tests added. Closes #5135

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7443 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-08-08 03:49:53 +00:00
parent cda0009723
commit 54fa1833e8
2 changed files with 79 additions and 9 deletions

View file

@ -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);
}

View file

@ -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(
'<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',
'Sat, 31 May 2008 12:00:00 ' . date('O'),
'/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);
}
/**
* testTime method