diff --git a/cake/libs/view/helpers/rss.php b/cake/libs/view/helpers/rss.php
index deecb45b8..5fc8ea958 100644
--- a/cake/libs/view/helpers/rss.php
+++ b/cake/libs/view/helpers/rss.php
@@ -131,12 +131,20 @@ class RssHelper extends XmlHelper {
}
if (!isset($elements['link'])) {
$elements['link'] = '/';
- }
+ }
+ if (!isset($elements['description'])) {
+ $elements['description'] = '';
+ }
$elements['link'] = $this->url($elements['link'], true);
$elems = '';
foreach ($elements as $elem => $data) {
- $elems .= $this->elem($elem, array(), $data);
+ $attributes = array();
+ if (is_array($data) && isset($data['attrib']) && is_array($data['attrib'])) {
+ $attributes = $data['attrib'];
+ unset($data['attrib']);
+ }
+ $elems .= $this->elem($elem, $attributes, $data);
}
return $this->elem('channel', $attrib, $elems . $this->__composeContent($content), !($content === null));
}
@@ -169,7 +177,7 @@ class RssHelper extends XmlHelper {
* @param array $elements The list of elements contained in this
* @return string An RSS element
*/
- function item($attrib = array(), $elements = array()) {
+ function item($att = array(), $elements = array()) {
$content = null;
foreach ($elements as $key => $val) {
@@ -210,7 +218,7 @@ class RssHelper extends XmlHelper {
$attrib = $val;
$val = null;
break;
- }
+ }
if ($val != null) {
$val = h($val);
}
@@ -224,8 +232,7 @@ class RssHelper extends XmlHelper {
if (!empty($elements)) {
$content = join('', $elements);
}
-
- return $this->output($this->elem('item', $attrib, $content, !($content === null)));
+ return $this->output($this->elem('item', $att, $content, !($content === null)));
}
/**
* Converts a time in any format to an RSS time
@@ -238,5 +245,4 @@ class RssHelper extends XmlHelper {
return $this->Time->toRSS($time);
}
}
-
?>
\ No newline at end of file
diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php
index a578898ec..f8b6e50f5 100644
--- a/cake/tests/cases/libs/view/helpers/rss.test.php
+++ b/cake/tests/cases/libs/view/helpers/rss.test.php
@@ -41,10 +41,6 @@ uses('controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view
*/
class RssTest extends UnitTestCase {
- function skip() {
- $this->skipif (true, 'RssHelper test not implemented');
- }
-
function setUp() {
$this->Rss = new RssHelper();
}
@@ -52,6 +48,66 @@ class RssTest extends UnitTestCase {
function tearDown() {
unset($this->Rss);
}
-}
+ function testDocument() {
+ $res = $this->Rss->document();
+ $this->assertPattern('/^$/', $res);
+
+ $res = $this->Rss->document(array('contrived' => 'parameter'));
+ $this->assertPattern('/^<\/rss>$/', $res);
+
+ $res = $this->Rss->document(null, 'content');
+ $this->assertPattern('/^content<\/rss>$/', $res);
+
+ $res = $this->Rss->document(array('contrived' => 'parameter'), 'content');
+ $this->assertPattern('/^]+version="2.0"[^<>]*>/', $res);
+ $this->assertPattern('/]+contrived="parameter"[^<>]*>/', $res);
+ $this->assertNoPattern('/]+[^version|contrived]=[^<>]*>/', $res);
+ }
+
+ function testChannel() {
+ $attrib = array('a' => '1', 'b' => '2');
+ $elements['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('/'.str_replace('/', '\/', RssHelper::url('/', true)).'<\/link>/', $res);
+ $this->assertPattern('//', $res);
+ $this->assertPattern('/content<\/channel>$/', $res);
+ }
+
+ 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('/^/', $res);
+ $this->assertPattern('/title<\/title>/', $res);
+ $this->assertPattern('/]+href="http:\/\/localhost">myImage<\/image>/', $res);
+ $this->assertPattern('/'.str_replace('/', '\/', RssHelper::url('/', true)).'<\/link>/', $res);
+ $this->assertPattern('//', $res);
+ $this->assertPattern('/content<\/channel>$/', $res);
+ }
+
+ function testItems() {
+ }
+
+ function testItem() {
+ }
+
+ function testTime() {
+ }
+
+ function testElementAttrNotInParent() {
+ $attributes = array('title' => 'Some Title', 'link' => 'http://link.com', 'description' => 'description');
+ $elements = array('enclosure' => array('url' => 'http://somewhere.com'));
+
+ $result = $this->Rss->item($attributes, $elements);
+ $this->assertPattern('/^- <\/item>$/', $result);
+ }
+}
?>
\ No newline at end of file