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
This commit is contained in:
mark_story 2008-11-24 23:10:29 +00:00
parent acb9e72355
commit cfa2229689
2 changed files with 44 additions and 26 deletions

View file

@ -138,9 +138,17 @@ class RssHelper extends XmlHelper {
$elems = ''; $elems = '';
foreach ($elements as $elem => $data) { foreach ($elements as $elem => $data) {
$attributes = array(); $attributes = array();
if (is_array($data) && isset($data['attrib']) && is_array($data['attrib'])) { if (is_array($data)) {
$attributes = $data['attrib']; if (strtolower($elem) == 'cloud') {
unset($data['attrib']); $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); $elems .= $this->elem($elem, $attributes, $data);
} }

View file

@ -173,41 +173,51 @@ class RssTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
} }
/** /**
* testChannelElementLevelAttrib method * test correct creation of channel sub elements.
* *
* @access public * @access public
* @return void * @return void
*/ */
function testChannelElementLevelAttrib() { function testChannelElements() {
$attrib = array(); $attrib = array();
$elements = array( $elements = array(
'title' => 'title', 'title' => 'Title of RSS Feed',
'link' => 'http://example.com',
'description' => 'Description of RSS Feed',
'image' => array( 'image' => array(
'myImage', 'title' => 'Title of image',
'attrib' => array( 'url' => 'http://example.com/example.png',
'href' => 'http://localhost' '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); $result = $this->Rss->channel($attrib, $elements, $content);
$expected = array( $expected = array(
'<channel', '<channel',
'<title', '<title', 'Title of RSS Feed', '/title',
'title', '<link', 'http://example.com', '/link',
'/title', '<description', 'Description of RSS Feed', '/description',
'image' => array( '<image',
'href' => 'http://localhost' '<title', 'Title of image', '/title',
), '<url', 'http://example.com/example.png', '/url',
'<myImage', '<link', 'http://example.com', '/link',
'/image', '/image',
'<link', 'cloud' => array(
RssHelper::url('/', true), 'domain' => "rpc.sys.com",
'/link', 'port' => "80",
'<description', 'path' =>"/RPC2",
'content', 'registerProcedure' => "myCloud.rssPleaseNotify",
'/channel' 'protocol' => "xml-rpc"
),
'content-here',
'/channel',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
} }