2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* RssHelperTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('RssHelper', 'View/Helper');
|
|
|
|
App::uses('TimeHelper', 'View/Helper');
|
2011-09-10 10:49:49 +00:00
|
|
|
App::uses('File', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* RssHelperTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-03-19 21:10:13 +00:00
|
|
|
class RssHelperTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-10-23 17:11:50 +00:00
|
|
|
parent::setUp();
|
2010-11-16 03:53:49 +00:00
|
|
|
$controller = null;
|
2010-07-03 16:16:40 +00:00
|
|
|
$this->View = new View($controller);
|
|
|
|
$this->Rss = new RssHelper($this->View);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-10-23 17:11:50 +00:00
|
|
|
parent::tearDown();
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($this->Rss);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testDocument method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDocument() {
|
2008-08-05 03:24:18 +00:00
|
|
|
$result = $this->Rss->document();
|
|
|
|
$expected = array(
|
|
|
|
'rss' => array(
|
|
|
|
'version' => '2.0'
|
|
|
|
)
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-08-05 03:24:18 +00:00
|
|
|
$result = $this->Rss->document(null, 'content');
|
|
|
|
$expected = array(
|
|
|
|
'rss' => array(
|
|
|
|
'version' => '2.0'
|
|
|
|
),
|
|
|
|
'content'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-08-05 03:24:18 +00:00
|
|
|
$result = $this->Rss->document(array('contrived' => 'parameter'), 'content');
|
|
|
|
$expected = array(
|
|
|
|
'rss' => array(
|
|
|
|
'contrived' => 'parameter',
|
|
|
|
'version' => '2.0'
|
|
|
|
),
|
|
|
|
'content'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testChannel method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testChannel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$attrib = array('a' => '1', 'b' => '2');
|
2008-08-05 03:24:18 +00:00
|
|
|
$elements = array('title' => 'title');
|
2008-05-30 11:40:08 +00:00
|
|
|
$content = 'content';
|
2008-08-05 03:24:18 +00:00
|
|
|
|
|
|
|
$result = $this->Rss->channel($attrib, $elements, $content);
|
|
|
|
$expected = array(
|
|
|
|
'channel' => array(
|
|
|
|
'a' => '1',
|
|
|
|
'b' => '2'
|
|
|
|
),
|
|
|
|
'<title',
|
|
|
|
'title',
|
|
|
|
'/title',
|
|
|
|
'<link',
|
2010-12-13 01:21:14 +00:00
|
|
|
$this->Rss->url('/', true),
|
2008-08-05 03:24:18 +00:00
|
|
|
'/link',
|
|
|
|
'<description',
|
|
|
|
'content',
|
|
|
|
'/channel'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-09-10 10:49:49 +00:00
|
|
|
|
|
|
|
$this->View->pageTitle = 'title';
|
|
|
|
$attrib = array('a' => '1', 'b' => '2');
|
|
|
|
$elements = array();
|
|
|
|
$content = 'content';
|
|
|
|
|
|
|
|
$result = $this->Rss->channel($attrib, $elements, $content);
|
|
|
|
$expected = array(
|
|
|
|
'channel' => array(
|
|
|
|
'a' => '1',
|
|
|
|
'b' => '2'
|
|
|
|
),
|
|
|
|
'<title',
|
|
|
|
'title',
|
|
|
|
'/title',
|
|
|
|
'<link',
|
|
|
|
$this->Rss->url('/', true),
|
|
|
|
'/link',
|
|
|
|
'<description',
|
|
|
|
'content',
|
|
|
|
'/channel'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-11-24 23:10:29 +00:00
|
|
|
* test correct creation of channel sub elements.
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testChannelElements() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$attrib = array();
|
2008-08-05 03:24:18 +00:00
|
|
|
$elements = array(
|
2008-11-24 23:10:29 +00:00
|
|
|
'title' => 'Title of RSS Feed',
|
|
|
|
'link' => 'http://example.com',
|
|
|
|
'description' => 'Description of RSS Feed',
|
2008-08-05 03:24:18 +00:00
|
|
|
'image' => array(
|
2008-11-24 23:10:29 +00:00
|
|
|
'title' => 'Title of image',
|
|
|
|
'url' => 'http://example.com/example.png',
|
|
|
|
'link' => 'http://example.com'
|
|
|
|
),
|
|
|
|
'cloud' => array(
|
|
|
|
'domain' => "rpc.sys.com",
|
|
|
|
'port' => "80",
|
2011-12-01 07:21:31 +00:00
|
|
|
'path' => "/RPC2",
|
2008-11-24 23:10:29 +00:00
|
|
|
'registerProcedure' => "myCloud.rssPleaseNotify",
|
|
|
|
'protocol' => "xml-rpc"
|
2008-08-05 03:24:18 +00:00
|
|
|
)
|
|
|
|
);
|
2008-11-24 23:10:29 +00:00
|
|
|
$content = 'content-here';
|
2008-08-05 03:24:18 +00:00
|
|
|
$result = $this->Rss->channel($attrib, $elements, $content);
|
|
|
|
$expected = array(
|
|
|
|
'<channel',
|
2008-11-24 23:10:29 +00:00
|
|
|
'<title', 'Title of RSS Feed', '/title',
|
|
|
|
'<link', 'http://example.com', '/link',
|
|
|
|
'<description', 'Description of RSS Feed', '/description',
|
|
|
|
'<image',
|
|
|
|
'<title', 'Title of image', '/title',
|
|
|
|
'<url', 'http://example.com/example.png', '/url',
|
|
|
|
'<link', 'http://example.com', '/link',
|
|
|
|
'/image',
|
2008-11-25 05:54:31 +00:00
|
|
|
'cloud' => array(
|
2008-11-24 23:10:29 +00:00
|
|
|
'domain' => "rpc.sys.com",
|
|
|
|
'port' => "80",
|
2011-12-01 07:21:31 +00:00
|
|
|
'path' => "/RPC2",
|
2008-11-24 23:10:29 +00:00
|
|
|
'registerProcedure' => "myCloud.rssPleaseNotify",
|
|
|
|
'protocol' => "xml-rpc"
|
|
|
|
),
|
|
|
|
'content-here',
|
|
|
|
'/channel',
|
2008-08-05 03:24:18 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-10-23 17:11:50 +00:00
|
|
|
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testChannelElementAttributes() {
|
2008-11-25 05:54:31 +00:00
|
|
|
$attrib = array();
|
|
|
|
$elements = array(
|
|
|
|
'title' => 'Title of RSS Feed',
|
|
|
|
'link' => 'http://example.com',
|
|
|
|
'description' => 'Description of RSS Feed',
|
|
|
|
'image' => array(
|
|
|
|
'title' => 'Title of image',
|
|
|
|
'url' => 'http://example.com/example.png',
|
|
|
|
'link' => 'http://example.com'
|
|
|
|
),
|
|
|
|
'atom:link' => array(
|
|
|
|
'attrib' => array(
|
|
|
|
'href' => 'http://www.example.com/rss.xml',
|
|
|
|
'rel' => 'self',
|
|
|
|
'type' => 'application/rss+xml')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$content = 'content-here';
|
|
|
|
$result = $this->Rss->channel($attrib, $elements, $content);
|
|
|
|
$expected = array(
|
|
|
|
'<channel',
|
|
|
|
'<title', 'Title of RSS Feed', '/title',
|
|
|
|
'<link', 'http://example.com', '/link',
|
|
|
|
'<description', 'Description of RSS Feed', '/description',
|
|
|
|
'<image',
|
|
|
|
'<title', 'Title of image', '/title',
|
|
|
|
'<url', 'http://example.com/example.png', '/url',
|
|
|
|
'<link', 'http://example.com', '/link',
|
|
|
|
'/image',
|
|
|
|
'atom:link' => array(
|
2010-07-28 20:47:02 +00:00
|
|
|
'xmlns:atom' => 'http://www.w3.org/2005/Atom',
|
2008-11-25 05:54:31 +00:00
|
|
|
'href' => "http://www.example.com/rss.xml",
|
|
|
|
'rel' => "self",
|
2011-12-01 07:21:31 +00:00
|
|
|
'type' => "application/rss+xml"
|
2008-11-25 05:54:31 +00:00
|
|
|
),
|
|
|
|
'content-here',
|
|
|
|
'/channel',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-11-25 05:54:31 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testItems method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testItems() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$items = array(
|
|
|
|
array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'),
|
|
|
|
array('title' => 'title2', 'guid' => 'http://www.example.com/guid2', 'link' => 'http://www.example.com/link2', 'description' => 'description2'),
|
|
|
|
array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3')
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $this->Rss->items($items);
|
2008-08-05 03:24:18 +00:00
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title', 'title1', '/title',
|
|
|
|
'<guid', 'http://www.example.com/guid1', '/guid',
|
|
|
|
'<link', 'http://www.example.com/link1', '/link',
|
|
|
|
'<description', 'description1', '/description',
|
|
|
|
'/item',
|
|
|
|
'<item',
|
|
|
|
'<title', 'title2', '/title',
|
|
|
|
'<guid', 'http://www.example.com/guid2', '/guid',
|
|
|
|
'<link', 'http://www.example.com/link2', '/link',
|
|
|
|
'<description', 'description2', '/description',
|
|
|
|
'/item',
|
|
|
|
'<item',
|
|
|
|
'<title', 'title3', '/title',
|
|
|
|
'<guid', 'http://www.example.com/guid3', '/guid',
|
|
|
|
'<link', 'http://www.example.com/link3', '/link',
|
|
|
|
'<description', 'description3', '/description',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-09-10 10:49:49 +00:00
|
|
|
$items = array(
|
|
|
|
array('title' => 'title1', 'guid' => 'http://www.example.com/guid1', 'link' => 'http://www.example.com/link1', 'description' => 'description1'),
|
|
|
|
array('title' => 'title2', 'guid' => 'http://www.example.com/guid2', 'link' => 'http://www.example.com/link2', 'description' => 'description2'),
|
|
|
|
array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3')
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $this->Rss->items($items, create_function('$v', '$v[\'title\'] = $v[\'title\'] . \'-transformed\'; return $v;'));
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title', 'title1-transformed', '/title',
|
|
|
|
'<guid', 'http://www.example.com/guid1', '/guid',
|
|
|
|
'<link', 'http://www.example.com/link1', '/link',
|
|
|
|
'<description', 'description1', '/description',
|
|
|
|
'/item',
|
|
|
|
'<item',
|
|
|
|
'<title', 'title2-transformed', '/title',
|
|
|
|
'<guid', 'http://www.example.com/guid2', '/guid',
|
|
|
|
'<link', 'http://www.example.com/link2', '/link',
|
|
|
|
'<description', 'description2', '/description',
|
|
|
|
'/item',
|
|
|
|
'<item',
|
|
|
|
'<title', 'title3-transformed', '/title',
|
|
|
|
'<guid', 'http://www.example.com/guid3', '/guid',
|
|
|
|
'<link', 'http://www.example.com/link3', '/link',
|
|
|
|
'<description', 'description3', '/description',
|
|
|
|
'/item'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Rss->items(array());
|
2008-08-05 03:24:18 +00:00
|
|
|
$expected = '';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testItem method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testItem() {
|
2008-08-05 03:24:18 +00:00
|
|
|
$item = array(
|
|
|
|
'title' => 'My title',
|
|
|
|
'description' => 'My description',
|
|
|
|
'link' => 'http://www.google.com/'
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
|
|
|
'My title',
|
|
|
|
'/title',
|
|
|
|
'<description',
|
|
|
|
'My description',
|
|
|
|
'/description',
|
|
|
|
'<link',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/link',
|
|
|
|
'<guid',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/guid',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-21 15:23:58 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$item = array(
|
2010-10-23 17:11:50 +00:00
|
|
|
'title' => 'My Title',
|
2008-05-30 11:40:08 +00:00
|
|
|
'link' => 'http://www.example.com/1',
|
2010-10-23 17:11:50 +00:00
|
|
|
'description' => 'descriptive words',
|
2008-05-30 11:40:08 +00:00
|
|
|
'pubDate' => '2008-05-31 12:00:00',
|
2011-09-10 10:49:49 +00:00
|
|
|
'source' => array('http://www.google.com/', 'Google'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'guid' => 'http://www.example.com/1'
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
2008-11-16 05:06:36 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
2010-10-23 17:11:50 +00:00
|
|
|
'My Title',
|
2008-05-30 11:40:08 +00:00
|
|
|
'/title',
|
|
|
|
'<link',
|
|
|
|
'http://www.example.com/1',
|
|
|
|
'/link',
|
|
|
|
'<description',
|
2010-10-23 17:11:50 +00:00
|
|
|
'descriptive words',
|
2008-05-30 11:40:08 +00:00
|
|
|
'/description',
|
|
|
|
'<pubDate',
|
2008-11-16 05:06:36 +00:00
|
|
|
date('r', strtotime('2008-05-31 12:00:00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/pubDate',
|
2011-09-10 10:49:49 +00:00
|
|
|
'source' => array('url' => 'http://www.google.com/'),
|
|
|
|
'Google',
|
|
|
|
'/source',
|
2008-05-30 11:40:08 +00:00
|
|
|
'<guid',
|
|
|
|
'http://www.example.com/1',
|
|
|
|
'/guid',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-21 15:23:58 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$item = array(
|
2010-10-23 17:11:50 +00:00
|
|
|
'title' => 'My Title & more'
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title', 'My Title & more', '/title',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-23 17:11:50 +00:00
|
|
|
|
|
|
|
$item = array(
|
|
|
|
'title' => 'Foo bar',
|
|
|
|
'link' => array(
|
|
|
|
'url' => 'http://example.com/foo?a=1&b=2',
|
|
|
|
'convertEntities' => false
|
|
|
|
),
|
2012-03-16 02:50:05 +00:00
|
|
|
'description' => array(
|
2010-10-23 17:11:50 +00:00
|
|
|
'value' => 'descriptive words',
|
|
|
|
'cdata' => true,
|
|
|
|
),
|
2011-09-10 10:49:49 +00:00
|
|
|
'pubDate' => '2008-05-31 12:00:00',
|
|
|
|
'source' => 'http://www.google.com/'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
2010-10-23 17:11:50 +00:00
|
|
|
'Foo bar',
|
2008-05-30 11:40:08 +00:00
|
|
|
'/title',
|
2010-10-23 17:11:50 +00:00
|
|
|
'<link',
|
|
|
|
'http://example.com/foo?a=1&b=2',
|
|
|
|
'/link',
|
|
|
|
'<description',
|
|
|
|
'<![CDATA[descriptive words]]',
|
|
|
|
'/description',
|
|
|
|
'<pubDate',
|
|
|
|
date('r', strtotime('2008-05-31 12:00:00')),
|
|
|
|
'/pubDate',
|
2011-09-10 10:49:49 +00:00
|
|
|
'<source',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/source',
|
2010-10-23 17:11:50 +00:00
|
|
|
'<guid',
|
|
|
|
'http://example.com/foo?a=1&b=2',
|
|
|
|
'/guid',
|
2008-05-30 11:40:08 +00:00
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-09-10 10:49:49 +00:00
|
|
|
|
|
|
|
$item = array(
|
|
|
|
'title' => 'My title',
|
|
|
|
'description' => 'My description',
|
|
|
|
'link' => 'http://www.google.com/',
|
|
|
|
'source' => array('url' => 'http://www.example.com/', 'title' => 'Example website')
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
|
|
|
'My title',
|
|
|
|
'/title',
|
|
|
|
'<description',
|
|
|
|
'My description',
|
|
|
|
'/description',
|
|
|
|
'<link',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/link',
|
|
|
|
'source' => array('url' => 'http://www.example.com/'),
|
|
|
|
'Example website',
|
|
|
|
'/source',
|
|
|
|
'<guid',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/guid',
|
|
|
|
'/item'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-03-08 00:52:06 +00:00
|
|
|
|
|
|
|
$item = array(
|
|
|
|
'title' => 'My title',
|
|
|
|
'description' => 'My description',
|
|
|
|
'link' => 'http://www.google.com/',
|
|
|
|
'category' => array('Category One', 'Category Two')
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
|
|
|
'My title',
|
|
|
|
'/title',
|
|
|
|
'<description',
|
|
|
|
'My description',
|
|
|
|
'/description',
|
|
|
|
'<link',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/link',
|
|
|
|
'<category',
|
|
|
|
'Category One',
|
|
|
|
'/category',
|
|
|
|
'<category',
|
|
|
|
'Category Two',
|
|
|
|
'/category',
|
|
|
|
'<guid',
|
|
|
|
'http://www.google.com/',
|
|
|
|
'/guid',
|
|
|
|
'/item'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2010-10-23 17:11:50 +00:00
|
|
|
}
|
2008-06-21 15:23:58 +00:00
|
|
|
|
2010-10-23 17:11:50 +00:00
|
|
|
/**
|
|
|
|
* test item() with cdata blocks.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testItemCdata() {
|
2008-06-11 02:10:32 +00:00
|
|
|
$item = array(
|
|
|
|
'title' => array(
|
|
|
|
'value' => 'My Title & more',
|
|
|
|
'cdata' => true,
|
|
|
|
'convertEntities' => false,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
|
|
|
'<![CDATA[My Title & more]]',
|
|
|
|
'/title',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-08-05 03:24:18 +00:00
|
|
|
|
|
|
|
$item = array(
|
|
|
|
'category' => array(
|
|
|
|
'value' => 'CakePHP',
|
|
|
|
'cdata' => true,
|
2010-10-23 17:11:50 +00:00
|
|
|
'domain' => 'http://www.cakephp.org',
|
2008-08-05 03:24:18 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = $this->Rss->item(null, $item);
|
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'category' => array('domain' => 'http://www.cakephp.org'),
|
|
|
|
'<![CDATA[CakePHP]]',
|
|
|
|
'/category',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-08-05 03:24:18 +00:00
|
|
|
|
|
|
|
$item = array(
|
|
|
|
'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',
|
|
|
|
'category' => array('domain' => 'http://www.cakephp.org'),
|
|
|
|
'<![CDATA[CakePHP]]',
|
|
|
|
'/category',
|
|
|
|
'<category',
|
|
|
|
'<![CDATA[Bakery]]',
|
|
|
|
'/category',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-08-08 03:49:53 +00:00
|
|
|
$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',
|
2010-12-13 01:21:14 +00:00
|
|
|
'enclosure' => array('url' => $this->Rss->url('/test.flv', true)),
|
2008-08-08 03:49:53 +00:00
|
|
|
'<pubDate',
|
2008-11-16 05:06:36 +00:00
|
|
|
date('r', strtotime('2008-05-31 12:00:00')),
|
2008-08-08 03:49:53 +00:00
|
|
|
'/pubDate',
|
|
|
|
'<guid',
|
|
|
|
'http://www.example.com/1',
|
|
|
|
'/guid',
|
|
|
|
'category' => array('domain' => 'http://www.cakephp.org'),
|
|
|
|
'<![CDATA[CakePHP]]',
|
|
|
|
'/category',
|
|
|
|
'<category',
|
|
|
|
'<![CDATA[Bakery]]',
|
|
|
|
'/category',
|
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-09-10 10:49:49 +00:00
|
|
|
/**
|
|
|
|
* test item() with enclosure data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testItemEnclosureLength() {
|
2011-12-03 20:00:06 +00:00
|
|
|
if (!is_writable(WWW_ROOT)) {
|
|
|
|
$this->markTestSkipped(__d('cake_dev', 'Webroot is not writable.'));
|
2011-09-10 10:49:49 +00:00
|
|
|
}
|
2011-12-03 20:00:06 +00:00
|
|
|
$testExists = is_dir(WWW_ROOT . 'tests');
|
|
|
|
|
|
|
|
$tmpFile = WWW_ROOT . 'tests' . DS . 'cakephp.file.test.tmp';
|
|
|
|
$File = new File($tmpFile, true);
|
2011-09-10 10:49:49 +00:00
|
|
|
|
|
|
|
$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
|
2012-03-24 20:32:31 +00:00
|
|
|
|
|
|
|
if (50300 <= PHP_VERSION_ID) {
|
|
|
|
clearstatcache(true, $tmpFile);
|
|
|
|
} else {
|
|
|
|
clearstatcache();
|
|
|
|
}
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-09-10 10:49:49 +00:00
|
|
|
$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' => '/tests/cakephp.file.test.tmp'
|
|
|
|
),
|
|
|
|
'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);
|
2012-04-03 03:19:05 +00:00
|
|
|
if (!function_exists('finfo_open') &&
|
|
|
|
(function_exists('mime_content_type') && false === mime_content_type($tmpFile))
|
|
|
|
) {
|
2012-03-24 20:32:31 +00:00
|
|
|
$type = false;
|
|
|
|
} else {
|
|
|
|
$type = 'text/plain';
|
|
|
|
}
|
2011-09-10 10:49:49 +00:00
|
|
|
$expected = array(
|
|
|
|
'<item',
|
|
|
|
'<title',
|
|
|
|
'<![CDATA[My Title]]',
|
|
|
|
'/title',
|
|
|
|
'<link',
|
|
|
|
'http://www.example.com/1',
|
|
|
|
'/link',
|
|
|
|
'<description',
|
|
|
|
'<![CDATA[descriptive words]]',
|
|
|
|
'/description',
|
|
|
|
'enclosure' => array(
|
|
|
|
'url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true),
|
|
|
|
'length' => filesize($tmpFile),
|
2012-03-24 20:32:31 +00:00
|
|
|
'type' => $type
|
2011-09-10 10:49:49 +00:00
|
|
|
),
|
|
|
|
'<pubDate',
|
|
|
|
date('r', strtotime('2008-05-31 12:00:00')),
|
|
|
|
'/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);
|
|
|
|
|
2011-12-03 20:00:06 +00:00
|
|
|
$File->delete();
|
2011-09-10 10:49:49 +00:00
|
|
|
|
2011-12-03 20:00:06 +00:00
|
|
|
if (!$testExists) {
|
|
|
|
$Folder = new Folder(WWW_ROOT . 'tests');
|
|
|
|
$Folder->delete();
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testElementAttrNotInParent method
|
2008-06-21 15:23:58 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElementAttrNotInParent() {
|
2008-08-05 03:24:18 +00:00
|
|
|
$attributes = array(
|
|
|
|
'title' => 'Some Title',
|
|
|
|
'link' => 'http://link.com',
|
|
|
|
'description' => 'description'
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$elements = array('enclosure' => array('url' => 'http://test.com'));
|
|
|
|
|
|
|
|
$result = $this->Rss->item($attributes, $elements);
|
|
|
|
$expected = array(
|
2008-08-05 03:24:18 +00:00
|
|
|
'item' => array(
|
|
|
|
'title' => 'Some Title',
|
|
|
|
'link' => 'http://link.com',
|
|
|
|
'description' => 'description'
|
|
|
|
),
|
|
|
|
'enclosure' => array(
|
|
|
|
'url' => 'http://test.com'
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/item'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-09-10 10:49:49 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|