Added tests to use Xml with RSS.

This commit is contained in:
Juan Basso 2010-09-01 20:06:56 -03:00
parent 52b09188f7
commit edcb5e4370

View file

@ -406,6 +406,61 @@ class XmlTest extends CakeTestCase {
$this->assertEqual(Xml::toArray($obj), $expected);
}
/**
* testToArrayRss
*
* @return void
*/
function testToArrayRss() {
$rss = <<<EOF
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://bakery.cakephp.org/articles/rss" rel="self" type="application/rss+xml" />
<title>The Bakery: </title>
<link>http://bakery.cakephp.org/</link>
<description>Recent Articles at The Bakery.</description>
<language>en-us</language>
<pubDate>Wed, 01 Sep 2010 12:09:25 -0500</pubDate>
<docs>http://validator.w3.org/feed/docs/rss2.html</docs>
<generator>CakePHP Bakery</generator>
<managingEditor>mariano@cricava.com (Mariano Iglesias)</managingEditor>
<webMaster>gwoo@cakephp.org (Garrett Woodworth)</webMaster>
<item>
<title>EpisodeCMS</title>
<link>http://bakery.cakephp.org/articles/view/episodecms</link>
<description>EpisodeCMS is CakePHP based content management system.
Features: control panel, events API, module management, multilanguage and translations, themes
http://episodecms.com/
Please help me to improve it. Thanks.</description>
<pubDate>Tue, 31 Aug 2010 02:07:02 -0500</pubDate>
<guid>http://bakery.cakephp.org/articles/view/episodecms</guid>
</item>
<item>
<title>Alertpay automated sales via IPN</title>
<link>http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn</link>
<description>I&#039;m going to show you how I implemented a payment module via the Alertpay payment processor.</description>
<pubDate>Tue, 31 Aug 2010 01:42:00 -0500</pubDate>
<guid>http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn</guid>
</item>
</channel>
</rss>
EOF;
$rssAsArray = Xml::toArray(Xml::build($rss));
$this->assertEqual($rssAsArray['rss']['@version'], '2.0');
$this->assertEqual(count($rssAsArray['rss']['channel']['item']), 2);
$expected = array(
'title' => 'Alertpay automated sales via IPN',
'link' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn',
'description' => 'I\'m going to show you how I implemented a payment module via the Alertpay payment processor.',
'pubDate' => 'Tue, 31 Aug 2010 01:42:00 -0500',
'guid' => 'http://bakery.cakephp.org/articles/view/alertpay-automated-sales-via-ipn'
);
$this->assertIdentical($rssAsArray['rss']['channel']['item'][1], $expected);
}
/**
* data provider for toArray() failures
*