Rss = new RssView(); $this->baseUrl = php_sapi_name() === 'cli' ? 'http://localhost' : HTTP_BASE; } /** * TestTime method * * @return void */ public function testTime() { $now = time(); $time = $this->Rss->time($now); $this->assertEquals(date('r', $now), $time); } /** * RssViewTest::testSerialize() * * @return void */ public function testSerialize() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $data = array( 'channel' => array( 'title' => 'Channel title', 'link' => 'http://channel.example.org', 'description' => 'Channel description' ), 'items' => array( array('title' => 'Title One', 'link' => 'http://example.org/one', 'author' => 'one@example.org', 'description' => 'Content one'), array('title' => 'Title Two', 'link' => 'http://example.org/two', 'author' => 'two@example.org', 'description' => 'Content two'), )); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); $expected = << Channel title http://channel.example.org Channel description Title One http://example.org/one one@example.org Content one Title Two http://example.org/two two@example.org Content two RSS; //debug($result); $this->assertSame('application/rss+xml', $Response->type()); $this->assertTextEquals($expected, $result); } /** * RssViewTest::testSerialize() * * @return void */ public function testSerializeWithPrefixes() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $time = time(); $data = array( 'channel' => array( 'title' => 'Channel title', 'link' => 'http://channel.example.org', 'description' => 'Channel description', 'sy:updatePeriod' => 'hourly', 'sy:updateFrequency' => 1 ), 'items' => array( array('title' => 'Title One', 'link' => 'http://example.org/one', 'dc:creator' => 'Author One', 'pubDate' => $time), array('title' => 'Title Two', 'link' => 'http://example.org/two', 'dc:creator' => 'Author Two', 'pubDate' => $time), ) ); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); $time = date('r', $time); $expected = << Channel title http://channel.example.org Channel description hourly 1 Title One http://example.org/one Author One $time Title Two http://example.org/two Author Two $time RSS; //debug($result); $this->assertSame('application/rss+xml', $Response->type()); $this->assertTextEquals($expected, $result); } /** * RssViewTest::testSerializeWithUnconfiguredPrefix() * * @expectedException RuntimeException * @return void */ public function testSerializeWithUnconfiguredPrefix() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $data = array( 'channel' => array( 'foo:bar' => 'something', ), 'items' => array( array('title' => 'Title Two'), ) ); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); } /** * RssViewTest::testSerializeWithArrayLinks() * * `'atom:link' => array('@href' => array(...)` becomes * '@rel' => 'self', '@type' => 'application/rss+xml' automatically set for atom:link * * @return void */ public function testSerializeWithArrayLinks() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $data = array( 'channel' => array( 'title' => 'Channel title', 'link' => 'http://channel.example.org', 'atom:link' => array('@href' => array('controller' => 'foo', 'action' => 'bar')), 'description' => 'Channel description', ), 'items' => array( array('title' => 'Title One', 'link' => array('controller' => 'foo', 'action' => 'bar'), 'description' => 'Content one'), array('title' => 'Title Two', 'link' => array('controller' => 'foo', 'action' => 'bar'), 'description' => 'Content two'), ) ); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); $expected = << Channel title http://channel.example.org Channel description Title One $this->baseUrl/foo/bar Content one Title Two $this->baseUrl/foo/bar Content two RSS; //debug($result); $this->assertSame('application/rss+xml', $Response->type()); $this->assertTextEquals($expected, $result); } /** * RssViewTest::testSerializeWithContent() * * @return void */ public function testSerializeWithContent() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $data = array( 'channel' => array( 'title' => 'Channel title', 'link' => 'http://channel.example.org', 'guid' => array('url' => 'http://channel.example.org', '@isPermaLink' => 'true'), 'atom:link' => array('@href' => array('controller' => 'foo', 'action' => 'bar')), ), 'items' => array( array('title' => 'Title One', 'link' => array('controller' => 'foo', 'action' => 'bar'), 'description' => 'Content one', 'content:encoded' => 'HTML content one'), array('title' => 'Title Two', 'link' => array('controller' => 'foo', 'action' => 'bar'), 'description' => 'Content two', 'content:encoded' => 'HTML content two'), ) ); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); $expected = << Channel title http://channel.example.org http://channel.example.org Title One $this->baseUrl/foo/bar Content one content one]]> Title Two $this->baseUrl/foo/bar Content two content two]]> RSS; //debug($output); $this->assertTextEquals($expected, $result); } /** * RssViewTest::testSerializeWithCustomNamespace() * * @return void */ public function testSerializeWithCustomNamespace() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $data = array( 'document' => array( 'namespace' => array( 'admin' => 'http://webns.net/mvcb/', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' ) ), 'channel' => array( 'title' => 'Channel title', 'admin:errorReportsTo' => array('@rdf:resource' => 'mailto:me@example.com') ), 'items' => array( array('title' => 'Title One', 'link' => array('controller' => 'foo', 'action' => 'bar')), ) ); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); $expected = << Channel title $this->baseUrl/ Title One $this->baseUrl/foo/bar RSS; //debug($result); $this->assertTextEquals($expected, $result); } /** * RssViewTest::testSerializeWithImage() * * @return void */ public function testSerializeWithImage() { $Request = new CakeRequest(); $Response = new CakeResponse(); $Controller = new Controller($Request, $Response); $url = array('controller' => 'topics', 'action' => 'feed', 'ext' => 'rss'); $data = array( 'channel' => array( 'title' => 'Channel title', 'guid' => array('url' => $url, '@isPermaLink' => 'true'), 'image' => array( 'url' => '/img/logo_rss.png', 'link' => '/' ) ), 'items' => array( array('title' => 'Title One', 'link' => array('controller' => 'foo', 'action' => 'bar')), ) ); $Controller->set(array('channel' => $data, '_serialize' => 'channel')); $View = new RssView($Controller); $result = $View->render(false); $expected = << Channel title $this->baseUrl/topics/feed.rss $this->baseUrl/img/logo_rss.png $this->baseUrl/ Channel title $this->baseUrl/ Title One $this->baseUrl/foo/bar RSS; //debug($result); $this->assertTextEquals($expected, $result); } }