Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* CacheHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
@ -151,7 +150,7 @@ class CacheHelperTest extends CakeTestCase {
$this->Controller->action = 'view';
$View = new View($this->Controller);
$result = $View->render('index');
$View->render('index');
$filename = CACHE . 'views' . DS . 'posts_view_風街ろまん.php';
$this->assertTrue(file_exists($filename));
@ -338,7 +337,7 @@ class CacheHelperTest extends CakeTestCase {
$this->Controller->cache_parsing();
$View = new View($this->Controller);
$result = $View->render('index');
$View->render('index');
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename));
@ -514,10 +513,10 @@ class CacheHelperTest extends CakeTestCase {
*
* This test verifies view cache is created correctly when the app name is contained in part of the controller name.
* (webapp Name) base name is 'cache' controller is 'cacheTest' action is 'cache_name'
* apps url would look something like http://localhost/cache/cacheTest/cache_name
* apps URL would look something like http://localhost/cache/cacheTest/cache_name
*
* @return void
**/
*/
public function testCacheBaseNameControllerName() {
$this->Controller->cache_parsing();
$this->Controller->cacheAction = array(

View file

@ -0,0 +1,172 @@
<?php
/**
* FlashHelperTest file
*
* Series of tests for flash helper.
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 2.7.0-dev
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('FlashHelper', 'View/Helper');
App::uses('View', 'View');
App::uses('CakePlugin', 'Core');
/**
* FlashHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class FlashHelperTest extends CakeTestCase {
/**
* setupBeforeClass method
*
* @return void
*/
public static function setupBeforeClass() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
));
}
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$controller = null;
$this->View = new View($controller);
$this->Flash = new FlashHelper($this->View);
if (!CakeSession::started()) {
CakeSession::start();
}
CakeSession::write(array(
'Message' => array(
'flash' => array(
'key' => 'flash',
'message' => 'This is a calling',
'element' => 'Flash/default',
'params' => array()
),
'notification' => array(
'key' => 'notification',
'message' => 'Broadcast message testing',
'element' => 'flash_helper',
'params' => array(
'title' => 'Notice!',
'name' => 'Alert!'
)
),
'classy' => array(
'key' => 'classy',
'message' => 'Recorded',
'element' => 'flash_classy',
'params' => array()
),
'default' => array(
'key' => 'default',
'message' => 'Default',
'element' => 'default',
'params' => array()
)
)
));
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->View, $this->Flash);
CakeSession::destroy();
}
/**
* testFlash method
*
* @return void
*/
public function testFlash() {
$result = $this->Flash->render();
$expected = '<div class="message">This is a calling</div>';
$this->assertContains($expected, $result);
$expected = '<div id="classy-message">Recorded</div>';
$result = $this->Flash->render('classy');
$this->assertContains($expected, $result);
$result = $this->Flash->render('notification');
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>Broadcast message testing</p>\n</div>";
$this->assertContains($expected, $result);
$this->assertNull($this->Flash->render('non-existent'));
}
/**
* testFlashThrowsException
*
* @expectedException UnexpectedValueException
*/
public function testFlashThrowsException() {
CakeSession::write('Message.foo', 'bar');
$this->Flash->render('foo');
}
/**
* test setting the element from the attrs.
*
* @return void
*/
public function testFlashElementInAttrs() {
$result = $this->Flash->render('notification', array(
'element' => 'flash_helper',
'params' => array('title' => 'Alert!', 'name' => 'Notice!')
));
$expected = "<div id=\"notificationLayout\">\n\t<h1>Notice!</h1>\n\t<h3>Alert!</h3>\n\t<p>Broadcast message testing</p>\n</div>";
$this->assertContains($expected, $result);
}
/**
* test using elements in plugins.
*
* @return void
*/
public function testFlashWithPluginElement() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$result = $this->Flash->render('flash', array('element' => 'TestPlugin.plugin_element'));
$expected = 'this is the plugin element';
$this->assertContains($expected, $result);
}
/**
* Test that the default element fallbacks to the Flash/default element.
*/
public function testFlashFallback() {
$result = $this->Flash->render('default');
$expected = '<div class="message">Default</div>';
$this->assertContains($expected, $result);
}
}

File diff suppressed because it is too large Load diff

View file

@ -2,19 +2,18 @@
/**
* HtmlHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc.
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
@ -24,6 +23,7 @@ App::uses('HtmlHelper', 'View/Helper');
App::uses('FormHelper', 'View/Helper');
App::uses('ClassRegistry', 'Utility');
App::uses('Folder', 'Utility');
App::uses('CakePlugin', 'Core');
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', 'http://cakephp.org');
@ -39,14 +39,14 @@ class TheHtmlTestController extends Controller {
/**
* name property
*
* @var string 'TheTest'
* @var string
*/
public $name = 'TheTest';
/**
* uses property
*
* @var mixed null
* @var mixed
*/
public $uses = null;
}
@ -209,12 +209,20 @@ class HtmlHelperTest extends CakeTestCase {
Router::reload();
$result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true));
$expected = array('a' => array('href' => FULL_BASE_URL . '/posts'), 'Posts', '/a');
$expected = array('a' => array('href' => Router::fullBaseUrl() . '/posts'), 'Posts', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'return confirm(&#039;Are you sure you want to do this?&#039;);'),
'a' => array('href' => '/home', 'onclick' => 'if (confirm(&quot;Are you sure you want to do this?&quot;)) { return true; } return false;'),
'Home',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Home', '/home', array('escape' => false, 'confirm' => 'Confirm\'s "nightmares"'));
$expected = array(
'a' => array('href' => '/home', 'onclick' => 'if (confirm(&quot;Confirm&#039;s \&quot;nightmares\&quot;&quot;)) { return true; } return false;'),
'Home',
'/a'
);
@ -290,6 +298,17 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Next >', '#', array(
'title' => 'Next >',
'escapeTitle' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'Next &gt;'),
'Next >',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->link('Original size', array(
'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200)
));
@ -310,6 +329,17 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->link($this->Html->image('test.gif'), '#', array(
'title' => 'hey "howdy"',
'escapeTitle' => false
));
$expected = array(
'a' => array('href' => '#', 'title' => 'hey &quot;howdy&quot;'),
'img' => array('src' => 'img/test.gif', 'alt' => ''),
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Html->image('test.gif', array('url' => '#'));
$expected = array(
'a' => array('href' => '#'),
@ -319,8 +349,8 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$result = $this->Html->link($this->Html->image('../favicon.ico'), '#', array('escape' => false));
$expected = array(
'a' => array('href' => '#'),
$expected = array(
'a' => array('href' => '#'),
'img' => array('src' => 'img/../favicon.ico', 'alt' => ''),
'/a'
);
@ -337,6 +367,30 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->link('http://www.example.org?param1=value1&param2=value2');
$expected = array('a' => array('href' => 'http://www.example.org?param1=value1&amp;param2=value2'), 'http://www.example.org?param1=value1&amp;param2=value2', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('alert', 'javascript:alert(\'cakephp\');');
$expected = array('a' => array('href' => 'javascript:alert(&#039;cakephp&#039;);'), 'alert', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('write me', 'mailto:example@cakephp.org');
$expected = array('a' => array('href' => 'mailto:example@cakephp.org'), 'write me', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('call me on 0123465-798', 'tel:0123465-798');
$expected = array('a' => array('href' => 'tel:0123465-798'), 'call me on 0123465-798', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('text me on 0123465-798', 'sms:0123465-798');
$expected = array('a' => array('href' => 'sms:0123465-798'), 'text me on 0123465-798', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('say hello to 0123465-798', 'sms:0123465-798?body=hello there');
$expected = array('a' => array('href' => 'sms:0123465-798?body=hello there'), 'say hello to 0123465-798', '/a');
$this->assertTags($result, $expected);
$result = $this->Html->link('say hello to 0123465-798', 'sms:0123465-798?body=hello "cakephp"');
$expected = array('a' => array('href' => 'sms:0123465-798?body=hello &quot;cakephp&quot;'), 'say hello to 0123465-798', '/a');
$this->assertTags($result, $expected);
}
/**
@ -353,14 +407,54 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->image('http://google.com/logo.gif');
$this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => '')));
$result = $this->Html->image('//google.com/logo.gif');
$this->assertTags($result, array('img' => array('src' => '//google.com/logo.gif', 'alt' => '')));
$result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif'));
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
$result = $this->Html->image('/test/view/1.gif');
$this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => '')));
}
/**
* Test image() with query strings.
*
* @return void
*/
public function testImageQueryString() {
$result = $this->Html->image('test.gif?one=two&three=four');
$this->assertTags($result, array('img' => array('src' => 'img/test.gif?one=two&amp;three=four', 'alt' => '')));
$result = $this->Html->image(array(
'controller' => 'images',
'action' => 'display',
'test',
'?' => array('one' => 'two', 'three' => 'four')
));
$this->assertTags($result, array('img' => array('src' => '/images/display/test?one=two&amp;three=four', 'alt' => '')));
}
/**
* Test that image works with pathPrefix.
*
* @return void
*/
public function testImagePathPrefix() {
$result = $this->Html->image('test.gif', array('pathPrefix' => '/my/custom/path/'));
$this->assertTags($result, array('img' => array('src' => '/my/custom/path/test.gif', 'alt' => '')));
$result = $this->Html->image('test.gif', array('pathPrefix' => 'http://cakephp.org/assets/img/'));
$this->assertTags($result, array('img' => array('src' => 'http://cakephp.org/assets/img/test.gif', 'alt' => '')));
$result = $this->Html->image('test.gif', array('pathPrefix' => '//cakephp.org/assets/img/'));
$this->assertTags($result, array('img' => array('src' => '//cakephp.org/assets/img/test.gif', 'alt' => '')));
$previousConfig = Configure::read('App.imageBaseUrl');
Configure::write('App.imageBaseUrl', '//cdn.cakephp.org/img/');
$result = $this->Html->image('test.gif');
$this->assertTags($result, array('img' => array('src' => '//cdn.cakephp.org/img/test.gif', 'alt' => '')));
Configure::write('App.imageBaseUrl', $previousConfig);
}
/**
@ -425,7 +519,7 @@ class HtmlHelperTest extends CakeTestCase {
App::uses('File', 'Utility');
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif';
$File = new File($testfile, true);
new File($testfile, true);
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
@ -525,7 +619,7 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
CakePlugin::load('TestPlugin');
$result = $this->Html->css('TestPlugin.style', null, array('plugin' => false));
$result = $this->Html->css('TestPlugin.style', array('plugin' => false));
$expected['link']['href'] = 'preg:/.*css\/TestPlugin\.style\.css/';
$this->assertTags($result, $expected);
CakePlugin::unload('TestPlugin');
@ -546,6 +640,21 @@ class HtmlHelperTest extends CakeTestCase {
$expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/';
$this->assertTags($result, $expected);
$result = $this->Html->css('cake.generic', array('pathPrefix' => '/my/custom/path/'));
$expected['link']['href'] = '/my/custom/path/cake.generic.css';
$this->assertTags($result, $expected);
$result = $this->Html->css('cake.generic', array('pathPrefix' => 'http://cakephp.org/assets/css/'));
$expected['link']['href'] = 'http://cakephp.org/assets/css/cake.generic.css';
$this->assertTags($result, $expected);
$previousConfig = Configure::read('App.cssBaseUrl');
Configure::write('App.cssBaseUrl', '//cdn.cakephp.org/css/');
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = '//cdn.cakephp.org/css/cake.generic.css';
$this->assertTags($result, $expected);
Configure::write('App.cssBaseUrl', $previousConfig);
Configure::write('Asset.filter.css', 'css.php');
$result = $this->Html->css('cake.generic');
$expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/';
@ -572,6 +681,74 @@ class HtmlHelperTest extends CakeTestCase {
->method('append')
->with('css', $this->matchesRegularExpression('/more_css_in_head.css/'));
$result = $this->Html->css('css_in_head', array('inline' => false));
$this->assertNull($result);
$result = $this->Html->css('more_css_in_head', array('inline' => false));
$this->assertNull($result);
$result = $this->Html->css('screen', array('rel' => 'import'));
$expected = array(
'style' => array('type' => 'text/css'),
'preg:/@import url\(.*css\/screen\.css\);/',
'/style'
);
$this->assertTags($result, $expected);
}
/**
* Test css() with once option.
*
* @return void
*/
public function testCssLinkOnce() {
Configure::write('Asset.filter.css', false);
$result = $this->Html->css('screen', array('once' => true));
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
);
$this->assertTags($result, $expected);
$result = $this->Html->css('screen', array('once' => true));
$this->assertEquals('', $result);
// Default is once=false
$result = $this->Html->css('screen');
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/')
);
$this->assertTags($result, $expected);
}
/**
* Test css link BC usage
*
* @return void
*/
public function testCssLinkBC() {
Configure::write('Asset.filter.css', false);
CakePlugin::load('TestPlugin');
$result = $this->Html->css('TestPlugin.style', null, array('plugin' => false));
$expected = array(
'link' => array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => 'preg:/.*css\/TestPlugin\.style\.css/'
)
);
$this->assertTags($result, $expected);
CakePlugin::unload('TestPlugin');
$result = $this->Html->css('screen', 'import');
$expected = array(
'style' => array('type' => 'text/css'),
'preg:/@import url\(.*css\/screen\.css\);/',
'/style'
);
$this->assertTags($result, $expected);
$result = $this->Html->css('css_in_head', null, array('inline' => false));
$this->assertNull($result);
@ -579,6 +756,22 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertNull($result);
}
/**
* testCssWithFullBase method
*
* @return void
*/
public function testCssWithFullBase() {
Configure::write('Asset.filter.css', false);
$here = $this->Html->url('/', true);
$result = $this->Html->css('screen', null, array('fullBase' => true));
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $here . 'css/screen.css')
);
$this->assertTags($result, $expected);
}
/**
* testPluginCssLink method
*
@ -706,13 +899,29 @@ class HtmlHelperTest extends CakeTestCase {
CakePlugin::unload('TestPlugin');
}
/**
* Resource names must be treated differently for css() and script()
*
* @return void
*/
public function testBufferedCssAndScriptWithIdenticalResourceName() {
$this->View->expects($this->at(0))
->method('append')
->with('css', $this->stringContains('test.min.css'));
$this->View->expects($this->at(1))
->method('append')
->with('script', $this->stringContains('test.min.js'));
$this->Html->css('test.min', array('inline' => false));
$this->Html->script('test.min', array('inline' => false));
}
/**
* test timestamp enforcement for script tags.
*
* @return void
*/
public function testScriptTimestamping() {
$this->skipIf(!is_writable(JS), 'webroot/js is not Writable, timestamp testing has been skipped.');
$this->skipIf(!is_writable(WWW_ROOT . 'js'), 'webroot/js is not Writable, timestamp testing has been skipped.');
Configure::write('debug', 2);
Configure::write('Asset.timestamp', true);
@ -739,7 +948,7 @@ class HtmlHelperTest extends CakeTestCase {
public function testPluginScriptTimestamping() {
CakePlugin::load('TestPlugin');
$pluginPath = App::pluginPath('TestPlugin');
$pluginPath = CakePlugin::path('TestPlugin');
$pluginJsPath = $pluginPath . 'webroot/js';
$this->skipIf(!is_writable($pluginJsPath), $pluginJsPath . ' is not Writable, timestamp testing has been skipped.');
@ -820,6 +1029,27 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->script('foo2', array('pathPrefix' => '/my/custom/path/'));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => '/my/custom/path/foo2.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script('foo3', array('pathPrefix' => 'http://cakephp.org/assets/js/'));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'http://cakephp.org/assets/js/foo3.js')
);
$this->assertTags($result, $expected);
$previousConfig = Configure::read('App.jsBaseUrl');
Configure::write('App.jsBaseUrl', '//cdn.cakephp.org/js/');
$result = $this->Html->script('foo4');
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => '//cdn.cakephp.org/js/foo4.js')
);
$this->assertTags($result, $expected);
Configure::write('App.jsBaseUrl', $previousConfig);
$result = $this->Html->script('foo');
$this->assertNull($result, 'Script returned upon duplicate inclusion %s');
@ -951,6 +1181,30 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* testScriptWithFullBase method
*
* @return void
*/
public function testScriptWithFullBase() {
$here = $this->Html->url('/', true);
$result = $this->Html->script('foo', array('fullBase' => true));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => $here . 'js/foo.js')
);
$this->assertTags($result, $expected);
$result = $this->Html->script(array('foobar', 'bar'), array('fullBase' => true));
$expected = array(
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/foobar.js')),
'/script',
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/bar.js')),
'/script',
);
$this->assertTags($result, $expected);
}
/**
* test a script file in the webroot/theme dir.
*
@ -963,7 +1217,7 @@ class HtmlHelperTest extends CakeTestCase {
App::uses('File', 'Utility');
$testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js';
$File = new File($testfile, true);
new File($testfile, true);
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
@ -1002,6 +1256,16 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptBlock('window.foo = 2;', array('type' => 'text/x-handlebars-template'));
$expected = array(
'script' => array('type' => 'text/x-handlebars-template'),
$this->cDataStart,
'window.foo = 2;',
$this->cDataEnd,
'/script',
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
$expected = array(
'script' => array('type' => 'text/javascript'),
@ -1075,6 +1339,20 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptStart(array('safe' => true, 'type' => 'text/x-handlebars-template'));
$this->assertNull($result);
echo 'this is some template';
$result = $this->Html->scriptEnd();
$expected = array(
'script' => array('type' => 'text/x-handlebars-template'),
$this->cDataStart,
'this is some template',
$this->cDataEnd,
'/script'
);
$this->assertTags($result, $expected);
$this->View->expects($this->once())
->method('append');
$result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
@ -1192,6 +1470,8 @@ class HtmlHelperTest extends CakeTestCase {
/**
* Test the array form of $startText
*
* @return void
*/
public function testGetCrumbFirstLink() {
$result = $this->Html->getCrumbList(null, 'Home');
@ -1473,22 +1753,8 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('icon', 'favicon.ico');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('icon');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
$this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
$this->assertRegExp('/\s+\/>$/', $result);
$result = $this->Html->meta('description', 'this is the meta description');
$this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));
@ -1497,8 +1763,57 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
}
/**
* Test generating favicon's with meta()
*
* @return void
*/
public function testMetaIcon() {
$result = $this->Html->meta('icon', 'favicon.ico');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('icon');
$expected = array(
'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
$result = $this->Html->meta('icon', '/favicon.png?one=two&three=four');
$url = '/favicon.png?one=two&amp;three=four';
$expected = array(
'link' => array(
'href' => $url,
'type' => 'image/x-icon',
'rel' => 'icon'
),
array(
'link' => array(
'href' => $url,
'type' => 'image/x-icon',
'rel' => 'shortcut icon'
)
)
);
$this->assertTags($result, $expected);
$this->Html->request->webroot = '/testing/';
$result = $this->Html->meta('icon');
$expected = array(
'link' => array('href' => '/testing/favicon.ico', 'type' => 'image/x-icon', 'rel' => 'icon'),
array('link' => array('href' => '/testing/favicon.ico', 'type' => 'image/x-icon', 'rel' => 'shortcut icon'))
);
$this->assertTags($result, $expected);
}
/**
* Test the inline and block options for meta()
*
* @return void
*/
public function testMetaWithBlocks() {
$this->View->expects($this->at(0))
@ -1610,6 +1925,21 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false);
$expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>";
$this->assertEquals($expected, $result);
$tr = array(
'td content 1',
'td content 2',
array('td content 3', array('class' => 'foo'))
);
$result = $this->Html->tableCells($tr, null, null, true);
$expected = array(
'<tr',
array('td' => array('class' => 'column-1')), 'td content 1', '/td',
array('td' => array('class' => 'column-2')), 'td content 2', '/td',
array('td' => array('class' => 'foo column-3')), 'td content 3', '/td',
'/tr'
);
$this->assertTags($result, $expected);
}
/**
@ -1624,11 +1954,17 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->tag('div', 'text');
$this->assertTags($result, '<div', 'text', '/div');
$result = $this->Html->tag('div', '<text>', 'class-name');
$this->assertTags($result, array('div' => array('class' => 'class-name'), 'preg:/<text>/', '/div'));
$result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true));
$this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div'));
$result = $this->Html->tag(false, '<em>stuff</em>');
$this->assertEquals('<em>stuff</em>', $result);
$result = $this->Html->tag(null, '<em>stuff</em>');
$this->assertEquals('<em>stuff</em>', $result);
$result = $this->Html->tag('', '<em>stuff</em>');
$this->assertEquals('<em>stuff</em>', $result);
}
/**
@ -1714,7 +2050,7 @@ class HtmlHelperTest extends CakeTestCase {
array('pathPrefix' => 'videos/', 'poster' => 'poster.jpg', 'text' => 'Your browser does not support the HTML5 Video element.')
);
$expected = array(
'video' => array('poster' => IMAGES_URL . 'poster.jpg'),
'video' => array('poster' => Configure::read('App.imageBaseUrl') . 'poster.jpg'),
array('source' => array('src' => 'videos/video.webm', 'type' => 'video/webm')),
array('source' => array('src' => 'videos/video.ogv', 'type' => 'video/ogg; codecs=&#039;theora, vorbis&#039;')),
'Your browser does not support the HTML5 Video element.',
@ -1752,7 +2088,6 @@ class HtmlHelperTest extends CakeTestCase {
/**
* testCrumbList method
*
*
* @return void
*/
public function testCrumbList() {
@ -1784,6 +2119,8 @@ class HtmlHelperTest extends CakeTestCase {
/**
* Test getCrumbList startText
*
* @return void
*/
public function testCrumbListFirstLink() {
$this->Html->addCrumb('First', '#first');
@ -1826,6 +2163,73 @@ class HtmlHelperTest extends CakeTestCase {
);
}
/**
* test getCrumbList() in Twitter Bootstrap style.
*
* @return void
*/
public function testCrumbListBootstrapStyle() {
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
$this->Html->addCrumb('Library', '/lib');
$this->Html->addCrumb('Data');
$result = $this->Html->getCrumbList(array(
'class' => 'breadcrumb',
'separator' => '<span class="divider">-</span>',
'firstClass' => false,
'lastClass' => 'active'
));
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumb')),
'<li',
array('a' => array('class' => 'home', 'href' => '/')), 'Home', '/a',
array('span' => array('class' => 'divider')), '-', '/span',
'/li',
'<li',
array('a' => array('href' => '/lib')), 'Library', '/a',
array('span' => array('class' => 'divider')), '-', '/span',
'/li',
array('li' => array('class' => 'active')), 'Data', '/li',
'/ul'
)
);
}
/**
* Test GetCrumbList using style of Zurb Foundation.
*
* @return void
*/
public function testCrumbListZurbStyle() {
$this->Html->addCrumb('Home', '#');
$this->Html->addCrumb('Features', '#');
$this->Html->addCrumb('Gene Splicing', '#');
$this->Html->addCrumb('Home', '#');
$result = $this->Html->getCrumbList(
array('class' => 'breadcrumbs', 'firstClass' => false, 'lastClass' => 'current')
);
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumbs')),
'<li',
array('a' => array('href' => '#')), 'Home', '/a',
'/li',
'<li',
array('a' => array('href' => '#')), 'Features', '/a',
'/li',
'<li',
array('a' => array('href' => '#')), 'Gene Splicing', '/a',
'/li',
array('li' => array('class' => 'current')),
array('a' => array('href' => '#')), 'Home', '/a',
'/li',
'/ul'
), true
);
}
/**
* testLoadConfig method
*
@ -1839,7 +2243,8 @@ class HtmlHelperTest extends CakeTestCase {
$expected = array(
'tags' => array(
'form' => 'start form',
'formend' => 'finish form'
'formend' => 'finish form',
'hiddenblock' => '<div class="hidden">%s</div>'
)
);
$this->assertEquals($expected, $result);
@ -1863,7 +2268,7 @@ class HtmlHelperTest extends CakeTestCase {
* @expectedException ConfigureException
*/
public function testLoadConfigWrongFile() {
$result = $this->Html->loadConfig('wrong_file');
$this->Html->loadConfig('wrong_file');
}
/**
@ -1874,7 +2279,7 @@ class HtmlHelperTest extends CakeTestCase {
*/
public function testLoadConfigWrongReader() {
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
$result = $this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path);
$this->Html->loadConfig(array('htmlhelper_tags', 'wrong_reader'), $path);
}
/**

View file

@ -2,18 +2,17 @@
/**
* JqueryEngineTestCase
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('HtmlHelper', 'View/Helper');
@ -21,6 +20,11 @@ App::uses('JsHelper', 'View/Helper');
App::uses('JqueryEngineHelper', 'View/Helper');
App::uses('View', 'View');
/**
* JqueryEngineHelperTest
*
* @package Cake.Test.Case.View.Helper
*/
class JqueryEngineHelperTest extends CakeTestCase {
/**
@ -213,6 +217,17 @@ class JqueryEngineHelperTest extends CakeTestCase {
));
$expected = '$.ajax({beforeSend:function (XMLHttpRequest) {doBefore}, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEquals($expected, $result);
$result = $this->Jquery->request('/people/edit/1', array(
'success' => 'doFoo',
'xhr' => 'return jQuery.ajaxSettings.xhr();',
'async' => true,
'method' => 'post',
'dataExpression' => true,
'data' => '$("#someId").serialize()',
));
$expected = '$.ajax({async:true, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\/people\/edit\/1", xhr:function () {return jQuery.ajaxSettings.xhr();}});';
$this->assertEquals($expected, $result);
}
/**

View file

@ -4,20 +4,20 @@
*
* TestCase for the JsHelper
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('JsBaseEngineHelper', 'View/Helper');
@ -25,6 +25,11 @@ App::uses('FormHelper', 'View/Helper');
App::uses('View', 'View');
App::uses('ClassRegistry', 'Utility');
/**
* JsEncodingObject
*
* @package Cake.Test.Case.View.Helper
*/
class JsEncodingObject {
protected $_title = 'Old thing';
@ -35,6 +40,11 @@ class JsEncodingObject {
}
/**
* OptionEngineHelper
*
* @package Cake.Test.Case.View.Helper
*/
class OptionEngineHelper extends JsBaseEngineHelper {
protected $_optionMap = array(
@ -48,6 +58,7 @@ class OptionEngineHelper extends JsBaseEngineHelper {
/**
* test method for testing option mapping
*
* @param array $options
* @return array
*/
public function testMap($options = array()) {
@ -57,6 +68,8 @@ class OptionEngineHelper extends JsBaseEngineHelper {
/**
* test method for option parsing
*
* @param $options
* @param array $safe
* @return void
*/
public function testParseOptions($options, $safe = array()) {
@ -161,13 +174,8 @@ class JsHelperTest extends CakeTestCase {
protected function _useMock() {
$request = new CakeRequest(null, false);
if (!class_exists('TestJsEngineHelper', false)) {
$this->getMock('JsBaseEngineHelper', array(), array($this->View), 'TestJsEngineHelper');
}
$this->Js = new JsHelper($this->View, array('TestJs'));
$this->Js->TestJsEngine = new TestJsEngineHelper($this->View);
$this->mockObjects[] = $this->Js->TestJsEngine;
$this->Js->TestJsEngine = $this->getMock('JsBaseEngineHelper', array(), array($this->View));
$this->Js->request = $request;
$this->Js->Html = new HtmlHelper($this->View);
$this->Js->Html->request = $request;
@ -319,7 +327,7 @@ class JsHelperTest extends CakeTestCase {
->method('append')
->with('script', $this->matchesRegularExpression('#<script type="text\/javascript">window.app \= \{"foo"\:1\}\;<\/script>#'));
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'inline' => false, 'safe' => false));
$this->Js->writeBuffer(array('onDomReady' => false, 'inline' => false, 'safe' => false));
}
/**
@ -338,7 +346,7 @@ class JsHelperTest extends CakeTestCase {
$this->Js->buffer('alert("test");');
$this->Js->TestJsEngine->expects($this->never())->method('domReady');
$result = $this->Js->writeBuffer();
$this->Js->writeBuffer();
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
if ($requestWith !== null) {
@ -352,11 +360,11 @@ class JsHelperTest extends CakeTestCase {
* @return void
*/
public function testWriteScriptsInFile() {
$this->skipIf(!is_writable(JS), 'webroot/js is not Writable, script caching test has been skipped.');
$this->skipIf(!is_writable(WWW_ROOT . 'js'), 'webroot/js is not Writable, script caching test has been skipped.');
Configure::write('Cache.disable', false);
$this->Js->request->webroot = '/';
$this->Js->JsBaseEngine = new TestJsEngineHelper($this->View);
$this->Js->JsBaseEngine = $this->getMock('JsBaseEngineHelper', array(), array($this->View));
$this->Js->buffer('one = 1;');
$this->Js->buffer('two = 2;');
$result = $this->Js->writeBuffer(array('onDomReady' => false, 'cache' => true));
@ -684,7 +692,7 @@ class JsHelperTest extends CakeTestCase {
}
/**
* test set()'ing variables to the Javascript buffer and controlling the output var name.
* test set()'ing variables to the JavaScript buffer and controlling the output var name.
*
* @return void
*/
@ -858,7 +866,7 @@ class JsBaseEngineTest extends CakeTestCase {
$object = new JsEncodingObject();
$object->title = 'New thing';
$object->indexes = array(5,6,7,8);
$object->indexes = array(5, 6, 7, 8);
$result = $this->JsEngine->object($object);
$this->assertEquals($expected, $result);

View file

@ -2,18 +2,17 @@
/**
* MooEngineTestCase
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
@ -21,6 +20,11 @@ App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('MootoolsEngineHelper', 'View/Helper');
/**
* MootoolsEngineHelperTest
*
* @package Cake.Test.Case.View.Helper
*/
class MootoolsEngineHelperTest extends CakeTestCase {
/**
@ -260,7 +264,7 @@ class MootoolsEngineHelperTest extends CakeTestCase {
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10,10),
'snapGrid' => array(10, 10),
'wrapCallbacks' => false
));
$expected = '$("drag-me").makeDraggable({onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});';

View file

@ -2,19 +2,18 @@
/**
* NumberHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
@ -70,6 +69,8 @@ class NumberHelperTest extends CakeTestCase {
/**
* test CakeNumber class methods are called correctly
*
* @return void
*/
public function testNumberHelperProxyMethodCalls() {
$methods = array(
@ -87,6 +88,8 @@ class NumberHelperTest extends CakeTestCase {
/**
* test engine override
*
* @return void
*/
public function testEngineOverride() {
App::build(array(

File diff suppressed because it is too large Load diff

View file

@ -2,18 +2,17 @@
/**
* PrototypeEngine TestCase
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
* @link http://cakephp.org CakePHP Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package Cake.Test.Case.View.Helper
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
@ -21,6 +20,11 @@ App::uses('HtmlHelper', 'View/Helper');
App::uses('JsHelper', 'View/Helper');
App::uses('PrototypeEngineHelper', 'View/Helper');
/**
* PrototypeEngineHelperTest
*
* @package Cake.Test.Case.View.Helper
*/
class PrototypeEngineHelperTest extends CakeTestCase {
/**
@ -283,8 +287,8 @@ class PrototypeEngineHelperTest extends CakeTestCase {
}
/**
* test drag() method. Scriptaculous lacks the ability to take an Array of Elements
* in new Drag() when selection is a multiple type. Iterate over the array.
* test drag() method. Scriptaculous lacks the ability to take an Array of Elements
* in new Drag() when selection is a multiple type. Iterate over the array.
*
* @return void
*/

View file

@ -2,20 +2,20 @@
/**
* RssHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
App::uses('RssHelper', 'View/Helper');
App::uses('TimeHelper', 'View/Helper');
@ -91,7 +91,7 @@ class RssHelperTest extends CakeTestCase {
*/
public function testChannel() {
$attrib = array('a' => '1', 'b' => '2');
$elements = array('title' => 'title');
$elements = array('title' => 'Title');
$content = 'content';
$result = $this->Rss->channel($attrib, $elements, $content);
@ -101,30 +101,7 @@ class RssHelperTest extends CakeTestCase {
'b' => '2'
),
'<title',
'title',
'/title',
'<link',
$this->Rss->url('/', true),
'/link',
'<description',
'content',
'/channel'
);
$this->assertTags($result, $expected);
$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',
'/title',
'<link',
$this->Rss->url('/', true),
@ -608,7 +585,7 @@ class RssHelperTest extends CakeTestCase {
$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
if (50300 <= PHP_VERSION_ID) {
if (PHP_VERSION_ID >= 50300) {
clearstatcache(true, $tmpFile);
} else {
clearstatcache();
@ -642,13 +619,12 @@ class RssHelperTest extends CakeTestCase {
)
);
$result = $this->Rss->item(null, $item);
if (!function_exists('finfo_open') &&
(function_exists('mime_content_type') && false === mime_content_type($tmpFile))
) {
$type = false;
if (!function_exists('mime_content_type')) {
$type = null;
} else {
$type = 'text/plain';
$type = mime_content_type($tmpFile);
}
$expected = array(
'<item',
'<title',
@ -679,6 +655,9 @@ class RssHelperTest extends CakeTestCase {
'/category',
'/item'
);
if ($type === null) {
unset($expected['enclosure']['type']);
}
$this->assertTags($result, $expected);
$File->delete();
@ -741,36 +720,36 @@ class RssHelperTest extends CakeTestCase {
public function testElementNamespaceWithPrefix() {
$item = array(
'title' => 'Title',
'dc:creator' => 'Alex',
'xy:description' => 'descriptive words'
);
'title' => 'Title',
'dc:creator' => 'Alex',
'dc:description' => 'descriptive words'
);
$attributes = array(
'namespace' => array(
'prefix' => 'dc',
'url' => 'http://link.com'
)
'namespace' => array(
'prefix' => 'dc',
'url' => 'http://link.com'
)
);
$result = $this->Rss->item($attributes, $item);
$expected = array(
'item' => array(
'xmlns:dc' => 'http://link.com'
'xmlns:dc' => 'http://link.com'
),
'title' => array(
'xmlns:dc' => 'http://link.com'
'xmlns:dc' => 'http://link.com'
),
'Title',
'/title',
'dc:creator' => array(
'xmlns:dc' => 'http://link.com'
'xmlns:dc' => 'http://link.com'
),
'Alex',
'/dc:creator',
'description' => array(
'xmlns:dc' => 'http://link.com'
'dc:description' => array(
'xmlns:dc' => 'http://link.com'
),
'descriptive words',
'/description',
'/dc:description',
'/item'
);
$this->assertTags($result, $expected, true);

View file

@ -2,19 +2,18 @@
/**
* SessionHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');

View file

@ -2,27 +2,31 @@
/**
* TextHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
App::uses('TextHelper', 'View/Helper');
/**
* TextHelperTestObject
*
* @package Cake.Test.Case.View.Helper
*/
class TextHelperTestObject extends TextHelper {
public function attach(StringMock $string) {
public function attach(CakeTextMock $string) {
$this->_engine = $string;
}
@ -33,9 +37,11 @@ class TextHelperTestObject extends TextHelper {
}
/**
* StringMock class
* CakeTextMock class
*
* @package Cake.Test.Case.View.Helper
*/
class StringMock {
class CakeTextMock {
}
/**
@ -68,22 +74,26 @@ class TextHelperTest extends CakeTestCase {
/**
* test String class methods are called correctly
*
* @return void
*/
public function testTextHelperProxyMethodCalls() {
$methods = array(
'highlight', 'stripLinks', 'truncate', 'excerpt', 'toList',
'highlight', 'stripLinks', 'truncate', 'tail', 'excerpt', 'toList',
);
$String = $this->getMock('StringMock', $methods);
$Text = new TextHelperTestObject($this->View, array('engine' => 'StringMock'));
$Text->attach($String);
$CakeText = $this->getMock('CakeTextMock', $methods);
$Text = new TextHelperTestObject($this->View, array('engine' => 'CakeTextMock'));
$Text->attach($CakeText);
foreach ($methods as $method) {
$String->expects($this->at(0))->method($method);
$CakeText->expects($this->at(0))->method($method);
$Text->{$method}('who', 'what', 'when', 'where', 'how');
}
}
/**
* test engine override
*
* @return void
*/
public function testEngineOverride() {
App::build(array(
@ -107,6 +117,10 @@ class TextHelperTest extends CakeTestCase {
* @return void
*/
public function testAutoLink() {
$text = 'The AWWWARD show happened today';
$result = $this->Text->autoLink($text);
$this->assertEquals($text, $result);
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLink($text);
@ -117,6 +131,10 @@ class TextHelperTest extends CakeTestCase {
$expected = 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL and <a href="mailto:test@cakephp\.org">test@cakephp\.org</a> email address';
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = 'Text with a partial <a href="//www.cakephp.org">link</a> link';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($text, $result);
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text);
@ -137,6 +155,51 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets';
$expected = 'This is a test text with URL (<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>) in brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL [http://www.cakephp.org/page/4] in square brackets';
$expected = 'This is a test text with URL [<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>] in square brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets';
$expected = 'This is a test text with URL [<a href="http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3">http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3</a>] in square brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon';
$expected = 'This is a test text with URL ;<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>; semi-colon';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
$text = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets';
$expected = 'This is a test text with URL (<a href="http://www.cakephp.org/page/4/other(thing)">http://www.cakephp.org/page/4/other(thing)</a>) brackets';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
}
/**
* Test mixing URLs and Email addresses in one confusing string.
*
* @return void
*/
public function testAutoLinkMixed() {
$text = 'Text with a url/email http://example.com/store?email=mark@example.com and email.';
$expected = 'Text with a url/email <a href="http://example.com/store?email=mark@example.com">' .
'http://example.com/store?email=mark@example.com</a> and email.';
$result = $this->Text->autoLink($text);
$this->assertEquals($expected, $result);
}
/**
* test autoLink() and options.
*
* @return void
*/
public function testAutoLinkOptions() {
$text = 'This is a test text with URL http://www.cakephp.org';
$expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('class' => 'link'));
@ -163,10 +226,23 @@ class TextHelperTest extends CakeTestCase {
$expected = 'This is a <b>test</b> text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'test <ul>
<li>lorem: http://example.org?some</li>
<li>ipsum: http://othersite.com/abc</li>
</ul> test';
$expected = 'test <ul>
<li>lorem: <a href="http://example.org?some">http://example.org?some</a></li>
<li>ipsum: <a href="http://othersite.com/abc">http://othersite.com/abc</a></li>
</ul> test';
$result = $this->Text->autoLink($text, array('escape' => false));
$this->assertEquals($expected, $result);
}
/**
* Data provider for autoLinking
*
* @return array
*/
public static function autoLinkProvider() {
return array(
@ -222,6 +298,18 @@ class TextHelperTest extends CakeTestCase {
'Text with a url http://www.not--work.com and more',
'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
),
array(
'Text with a url http://www.sub_domain.domain.pl and more',
'Text with a url <a href="http://www.sub_domain.domain.pl">http://www.sub_domain.domain.pl</a> and more',
),
array(
'Text with a partial www.küchenschöhn-not-working.de URL',
'Text with a partial <a href="http://www.küchenschöhn-not-working.de">www.küchenschöhn-not-working.de</a> URL'
),
array(
'Text with a partial http://www.küchenschöhn-not-working.de URL',
'Text with a partial <a href="http://www.küchenschöhn-not-working.de">http://www.küchenschöhn-not-working.de</a> URL'
),
);
}
@ -259,6 +347,16 @@ class TextHelperTest extends CakeTestCase {
* @return void
*/
public function testAutoLinkUrlsEscape() {
$text = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
$expected = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
$expected = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$expected = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
@ -276,50 +374,115 @@ class TextHelperTest extends CakeTestCase {
$text = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$expected = 'Text with a url &lt;a href=&quot;http://www.not-working-www.com&quot;&gt;www.not-working-www.com&lt;/a&gt; and more';
$result = $this->Text->autoLinkUrls($text);
$result = $this->Text->autoLinkUrls($text, array('escape' => true));
$this->assertEquals($expected, $result);
$text = 'Text with a url www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a url http://www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.not-working-www.com">http://www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text);
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
$text = 'Text with a url http://www.www.not-working-www.com and more';
$expected = 'Text with a url <a href="http://www.www.not-working-www.com">http://www.www.not-working-www.com</a> and more';
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
$this->assertEquals($expected, $result);
}
/**
* Test autoLinkUrls with query strings.
*
* @return void
*/
public function testAutoLinkUrlsQueryString() {
$text = 'Text with a partial http://www.cakephp.org?product_id=123&foo=bar link';
$expected = 'Text with a partial <a href="http://www.cakephp.org?product_id=123&amp;foo=bar">http://www.cakephp.org?product_id=123&amp;foo=bar</a> link';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
}
/**
* testAutoLinkEmails method
* Data provider for autoLinkEmail.
*
* @return void
*/
public function testAutoLinkEmails() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLinkUrls($text);
public function autoLinkEmailProvider() {
return array(
array(
'This is a test text',
'This is a test text',
),
array(
'email@example.com address',
'<a href="mailto:email@example.com">email@example.com</a> address',
),
array(
'email@example.com address',
'<a href="mailto:email@example.com">email@example.com</a> address',
),
array(
'(email@example.com) address',
'(<a href="mailto:email@example.com">email@example.com</a>) address',
),
array(
'Text with email@example.com address',
'Text with <a href="mailto:email@example.com">email@example.com</a> address',
),
array(
"Text with o'hare._-bob@example.com address",
'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address',
),
array(
'Text with düsentrieb@küchenschöhn-not-working.de address',
'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
),
array(
'Text with me@subdomain.küchenschöhn.de address',
'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
),
array(
'Text with email@example.com address',
'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address',
array('class' => 'link'),
),
array(
'<p>mark@example.com</p>',
'<p><a href="mailto:mark@example.com">mark@example.com</a></p>',
array('escape' => false)
),
array(
'Some&nbsp;mark@example.com&nbsp;Text',
'Some&nbsp;<a href="mailto:mark@example.com">mark@example.com</a>&nbsp;Text',
array('escape' => false)
),
);
}
/**
* testAutoLinkEmails method
*
* @param string $text The text to link
* @param string $expected The expected results.
* @dataProvider autoLinkEmailProvider
* @return void
*/
public function testAutoLinkEmails($text, $expected, $attrs = array()) {
$result = $this->Text->autoLinkEmails($text, $attrs);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
$this->assertRegExp('#^' . $expected . '$#', $result);
}
/**
@ -333,5 +496,58 @@ class TextHelperTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
}
/**
* testAutoParagraph method
*
* @return void
*/
public function testAutoParagraph() {
$text = 'This is a test text';
$expected = <<<TEXT
<p>This is a test text</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$text = 'This is a <br/> <BR> test text';
$expected = <<<TEXT
<p>This is a </p>
<p> test text</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
$result = $this->Text->autoParagraph($text);
$text = 'This is a <BR id="test"/><br class="test"> test text';
$expected = <<<TEXT
<p>This is a </p>
<p> test text</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
$text = <<<TEXT
This is a test text.
This is a line return.
TEXT;
$expected = <<<TEXT
<p>This is a test text.<br />
This is a line return.</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
$text = <<<TEXT
This is a test text.
This is a new line.
TEXT;
$expected = <<<TEXT
<p>This is a test text.</p>
<p>This is a new line.</p>
TEXT;
$result = $this->Text->autoParagraph($text);
$this->assertTextEquals($expected, $result);
}
}

View file

@ -2,26 +2,28 @@
/**
* TimeHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('TimeHelper', 'View/Helper');
App::uses('View', 'View');
App::uses('CakeTime', 'Utility');
/**
* TimeHelperTestObject class
*
* @package Cake.Test.Case.View.Helper
*/
class TimeHelperTestObject extends TimeHelper {
@ -37,6 +39,8 @@ class TimeHelperTestObject extends TimeHelper {
/**
* CakeTimeMock class
*
* @package Cake.Test.Case.View.Helper
*/
class CakeTimeMock {
}
@ -74,6 +78,8 @@ class TimeHelperTest extends CakeTestCase {
/**
* test CakeTime class methods are called correctly
*
* @return void
*/
public function testTimeHelperProxyMethodCalls() {
$methods = array(
@ -81,7 +87,7 @@ class TimeHelperTest extends CakeTestCase {
'nice', 'niceShort', 'daysAsSql', 'dayAsSql',
'isToday', 'isThisMonth', 'isThisYear', 'wasYesterday',
'isTomorrow', 'toQuarter', 'toUnix', 'toAtom', 'toRSS',
'timeAgoInWords', 'wasWithinLast', 'gmt', 'format', 'i18nFormat',
'wasWithinLast', 'gmt', 'format', 'i18nFormat',
);
$CakeTime = $this->getMock('CakeTimeMock', $methods);
$Time = new TimeHelperTestObject($this->View, array('engine' => 'CakeTimeMock'));
@ -90,10 +96,18 @@ class TimeHelperTest extends CakeTestCase {
$CakeTime->expects($this->at(0))->method($method);
$Time->{$method}('who', 'what', 'when', 'where', 'how');
}
$CakeTime = $this->getMock('CakeTimeMock', array('timeAgoInWords'));
$Time = new TimeHelperTestObject($this->View, array('engine' => 'CakeTimeMock'));
$Time->attach($CakeTime);
$CakeTime->expects($this->at(0))->method('timeAgoInWords');
$Time->timeAgoInWords('who', array('what'), array('when'), array('where'), array('how'));
}
/**
* test engine override
*
* @return void
*/
public function testEngineOverride() {
App::build(array(
@ -161,7 +175,7 @@ class TimeHelperTest extends CakeTestCase {
'title' => $timestamp,
'class' => 'time-ago-in-words'
),
'2 weeks',
'in 2 weeks',
'/div'
);
$this->assertTags($result, $expected);

View file

@ -2,19 +2,18 @@
/**
* HelperCollectionTest file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('HelperCollection', 'View');
@ -27,6 +26,11 @@ App::uses('View', 'View');
class HtmlAliasHelper extends HtmlHelper {
}
/**
* HelperCollectionTest
*
* @package Cake.Test.Case.View
*/
class HelperCollectionTest extends CakeTestCase {
/**
@ -61,8 +65,8 @@ class HelperCollectionTest extends CakeTestCase {
$this->assertInstanceOf('HtmlHelper', $result);
$this->assertInstanceOf('HtmlHelper', $this->Helpers->Html);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
$result = $this->Helpers->loaded();
$this->assertEquals(array('Html'), $result, 'loaded() results are wrong.');
$this->assertTrue($this->Helpers->enabled('Html'));
}
@ -93,7 +97,7 @@ class HelperCollectionTest extends CakeTestCase {
* @return void
*/
public function testLazyLoadException() {
$result = $this->Helpers->NotAHelper;
$this->Helpers->NotAHelper;
}
/**
@ -106,8 +110,8 @@ class HelperCollectionTest extends CakeTestCase {
$this->assertInstanceOf('HtmlAliasHelper', $result);
$this->assertInstanceOf('HtmlAliasHelper', $this->Helpers->Html);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html'), $result, 'attached() results are wrong.');
$result = $this->Helpers->loaded();
$this->assertEquals(array('Html'), $result, 'loaded() results are wrong.');
$this->assertTrue($this->Helpers->enabled('Html'));
@ -120,8 +124,8 @@ class HelperCollectionTest extends CakeTestCase {
$this->assertInstanceOf('OtherHelperHelper', $result);
$this->assertInstanceOf('OtherHelperHelper', $this->Helpers->SomeOther);
$result = $this->Helpers->attached();
$this->assertEquals(array('Html', 'SomeOther'), $result, 'attached() results are wrong.');
$result = $this->Helpers->loaded();
$this->assertEquals(array('Html', 'SomeOther'), $result, 'loaded() results are wrong.');
App::build();
}
@ -145,7 +149,7 @@ class HelperCollectionTest extends CakeTestCase {
* @return void
*/
public function testLoadMissingHelper() {
$result = $this->Helpers->load('ThisHelperShouldAlwaysBeMissing');
$this->Helpers->load('ThisHelperShouldAlwaysBeMissing');
}
/**
@ -174,14 +178,14 @@ class HelperCollectionTest extends CakeTestCase {
$this->Helpers->load('Form');
$this->Helpers->load('Html');
$result = $this->Helpers->attached();
$result = $this->Helpers->loaded();
$this->assertEquals(array('Form', 'Html'), $result, 'loaded helpers is wrong');
$this->Helpers->unload('Html');
$this->assertNotContains('Html', $this->Helpers->attached());
$this->assertContains('Form', $this->Helpers->attached());
$this->assertNotContains('Html', $this->Helpers->loaded());
$this->assertContains('Form', $this->Helpers->loaded());
$result = $this->Helpers->attached();
$result = $this->Helpers->loaded();
$this->assertEquals(array('Form'), $result, 'loaded helpers is wrong');
}

View file

@ -2,19 +2,18 @@
/**
* HelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
@ -32,7 +31,7 @@ class HelperTestPost extends Model {
/**
* useTable property
*
* @var bool false
* @var bool
*/
public $useTable = false;
@ -72,7 +71,7 @@ class HelperTestComment extends Model {
/**
* useTable property
*
* @var bool false
* @var bool
*/
public $useTable = false;
@ -106,7 +105,7 @@ class HelperTestTag extends Model {
/**
* useTable property
*
* @var bool false
* @var bool
*/
public $useTable = false;
@ -137,7 +136,7 @@ class HelperTestPostsTag extends Model {
/**
* useTable property
*
* @var bool false
* @var bool
*/
public $useTable = false;
@ -158,10 +157,20 @@ class HelperTestPostsTag extends Model {
class TestHelper extends Helper {
/**
* Settings for this helper.
*
* @var array
*/
public $settings = array(
'key1' => 'val1',
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'val2.2')
);
/**
* Helpers for this helper.
*
* @var string
* @var array
*/
public $helpers = array('Html', 'TestPlugin.OtherHelper');
@ -264,6 +273,24 @@ class HelperTest extends CakeTestCase {
);
}
/**
* Test settings merging
*
* @return void
*/
public function testSettingsMerging() {
$Helper = new TestHelper($this->View, array(
'key3' => 'val3',
'key2' => array('key2.2' => 'newval')
));
$expected = array(
'key1' => 'val1',
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'newval'),
'key3' => 'val3'
);
$this->assertEquals($expected, $Helper->settings);
}
/**
* Test setting an entity and retrieving the entity, model and field.
*
@ -280,7 +307,7 @@ class HelperTest extends CakeTestCase {
/**
* test setEntity with setting a scope.
*
* @return
* @return void
*/
public function testSetEntityScoped() {
$this->Helper->setEntity('HelperTestPost', true);
@ -528,7 +555,7 @@ class HelperTest extends CakeTestCase {
}
/**
* Ensure HTML escaping of url params. So link addresses are valid and not exploited
* Ensure HTML escaping of URL params. So link addresses are valid and not exploited
*
* @return void
*/
@ -571,30 +598,34 @@ class HelperTest extends CakeTestCase {
public function testAssetTimestamp() {
Configure::write('Foo.bar', 'test');
Configure::write('Asset.timestamp', false);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertEquals(CSS_URL . 'cake.generic.css', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css');
$this->assertEquals(Configure::read('App.cssBaseUrl') . 'cake.generic.css', $result);
Configure::write('Asset.timestamp', true);
Configure::write('debug', 0);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertEquals(CSS_URL . 'cake.generic.css', $result);
$result = $this->Helper->assetTimestamp('/%3Cb%3E/cake.generic.css');
$this->assertEquals('/%3Cb%3E/cake.generic.css', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css');
$this->assertEquals(Configure::read('App.cssBaseUrl') . 'cake.generic.css', $result);
Configure::write('Asset.timestamp', true);
Configure::write('debug', 2);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . 'cake.generic.css?', '/') . '[0-9]+/', $result);
Configure::write('Asset.timestamp', 'force');
Configure::write('debug', 0);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
$this->assertEquals(CSS_URL . 'cake.generic.css?someparam', $result);
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css?someparam');
$this->assertEquals(Configure::read('App.cssBaseUrl') . 'cake.generic.css?someparam', $result);
$this->Helper->request->webroot = '/some/dir/';
$result = $this->Helper->assetTimestamp('/some/dir/' . CSS_URL . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetTimestamp('/some/dir/' . Configure::read('App.cssBaseUrl') . 'cake.generic.css');
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . 'cake.generic.css?', '/') . '[0-9]+/', $result);
}
/**
@ -611,13 +642,13 @@ class HelperTest extends CakeTestCase {
),
array('fullBase' => true)
);
$this->assertEquals(FULL_BASE_URL . '/js/post.js', $result);
$this->assertEquals(Router::fullBaseUrl() . '/js/post.js', $result);
$result = $this->Helper->assetUrl('foo.jpg', array('pathPrefix' => 'img/'));
$this->assertEquals('img/foo.jpg', $result);
$result = $this->Helper->assetUrl('foo.jpg', array('fullBase' => true));
$this->assertEquals(FULL_BASE_URL . '/foo.jpg', $result);
$this->assertEquals(Router::fullBaseUrl() . '/foo.jpg', $result);
$result = $this->Helper->assetUrl('style', array('ext' => '.css'));
$this->assertEquals('style.css', $result);
@ -627,6 +658,25 @@ class HelperTest extends CakeTestCase {
$result = $this->Helper->assetUrl('foo.jpg?one=two&three=four');
$this->assertEquals('foo.jpg?one=two&amp;three=four', $result);
$result = $this->Helper->assetUrl('dir/big+tall/image', array('ext' => '.jpg'));
$this->assertEquals('dir/big%2Btall/image.jpg', $result);
}
/**
* Test assetUrl with no rewriting.
*
* @return void
*/
public function testAssetUrlNoRewrite() {
$this->Helper->request->addPaths(array(
'base' => '/cake_dev/index.php',
'webroot' => '/cake_dev/app/webroot/',
'here' => '/cake_dev/index.php/tasks',
));
$result = $this->Helper->assetUrl('img/cake.icon.png', array('fullBase' => true));
$expected = FULL_BASE_URL . '/cake_dev/app/webroot/img/cake.icon.png';
$this->assertEquals($expected, $result);
}
/**
@ -656,8 +706,8 @@ class HelperTest extends CakeTestCase {
$this->Helper->webroot = '';
Configure::write('Asset.timestamp', 'force');
$result = $this->Helper->assetUrl('cake.generic.css', array('pathPrefix' => CSS_URL));
$this->assertRegExp('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
$result = $this->Helper->assetUrl('cake.generic.css', array('pathPrefix' => Configure::read('App.cssBaseUrl')));
$this->assertRegExp('/' . preg_quote(Configure::read('App.cssBaseUrl') . 'cake.generic.css?', '/') . '[0-9]+/', $result);
}
/**
@ -801,6 +851,16 @@ class HelperTest extends CakeTestCase {
$this->assertEquals('&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;', $result);
}
/**
* testDomId method
*
* @return void
*/
public function testDomId() {
$result = $this->Helper->domId('Foo.bar');
$this->assertEquals('FooBar', $result);
}
/**
* testMultiDimensionalField method
*
@ -923,8 +983,7 @@ class HelperTest extends CakeTestCase {
$Helper->OtherHelper;
$result = $this->View->Helpers->enabled();
$expected = array();
$this->assertEquals($expected, $result, 'Helper helpers were attached to the collection.');
$this->assertEquals(array(), $result, 'Helper helpers were attached to the collection.');
}
/**

View file

@ -2,19 +2,18 @@
/**
* JsonViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 2.1.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
@ -30,44 +29,254 @@ App::uses('JsonView', 'View');
class JsonViewTest extends CakeTestCase {
/**
* testRenderWithoutView method
* setUp method
*
* @return void
**/
public function setUp() {
parent::setUp();
Configure::write('debug', 0);
}
/**
* Generates testRenderWithoutView data.
*
* Note: array($data, $serialize, expected)
*
* @return void
*/
public function testRenderWithoutView() {
public static function renderWithoutViewProvider() {
return array(
// Test render with a valid string in _serialize.
array(
array('data' => array('user' => 'fake', 'list' => array('item1', 'item2'))),
'data',
json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')))
),
// Test render with a string with an invalid key in _serialize.
array(
array('data' => array('user' => 'fake', 'list' => array('item1', 'item2'))),
'no_key',
json_encode(null)
),
// Test render with a valid array in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('no', 'user'),
json_encode(array('no' => 'nope', 'user' => 'fake'))
),
// Test render with an empty array in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array(),
json_encode(null)
),
// Test render with a valid array with an invalid key in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('no', 'user', 'no_key'),
json_encode(array('no' => 'nope', 'user' => 'fake'))
),
// Test render with a valid array with only an invalid key in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('no_key'),
json_encode(null)
),
// Test render with Null in _serialize (unset).
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
null,
null
),
// Test render with False in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
false,
json_encode(null)
),
// Test render with True in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
true,
json_encode(null)
),
// Test render with empty string in _serialize.
array(
array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2')),
'',
json_encode(null)
),
// Test render with a valid array in _serialize and alias.
array(
array('original_name' => 'my epic name', 'user' => 'fake', 'list' => array('item1', 'item2')),
array('new_name' => 'original_name', 'user'),
json_encode(array('new_name' => 'my epic name', 'user' => 'fake'))
),
// Test render with an a valid array in _serialize and alias of a null value.
array(
array('null' => null),
array('null'),
json_encode(array('null' => null))
),
// Test render with a False value to be serialized.
array(
array('false' => false),
'false',
json_encode(false)
),
// Test render with a True value to be serialized.
array(
array('true' => true),
'true',
json_encode(true)
),
// Test render with an empty string value to be serialized.
array(
array('empty' => ''),
'empty',
json_encode('')
),
// Test render with a zero value to be serialized.
array(
array('zero' => 0),
'zero',
json_encode(0)
),
);
}
/**
* Custom error handler for use while testing methods that use json_encode
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return void
* @throws CakeException
**/
public function jsonEncodeErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
throw new CakeException($errstr, 0, $errno, $errfile, $errline);
}
/**
* Test render with a valid string in _serialize.
*
* @dataProvider renderWithoutViewProvider
* @return void
*/
public function testRenderWithoutView($data, $serialize, $expected) {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->set($data);
$Controller->set('_serialize', $serialize);
$View = new JsonView($Controller);
$output = $View->render(false);
$this->assertSame($expected, $output);
}
/**
* Test render with _jsonOptions setting.
*
* @return void
*/
public function testRenderWithoutViewJsonOptions() {
$this->skipIf(!version_compare(PHP_VERSION, '5.3.0', '>='), 'Needs PHP5.3+ for these constants to be tested');
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
// Test render with encode <, >, ', &, and " for RFC4627-compliant to be serialized.
$data = array('rfc4627_escape' => '<tag> \'quote\' "double-quote" &');
$serialize = 'rfc4627_escape';
$expected = json_encode('<tag> \'quote\' "double-quote" &', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
$Controller->set($data);
$Controller->set('_serialize', $serialize);
$Controller->set('_jsonOptions', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
$View = new JsonView($Controller);
$output = $View->render(false);
$this->assertSame($expected, $output);
}
/**
* Test that rendering with _serialize does not load helpers.
*
* @return void
*/
public function testRenderSerializeNoHelpers() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->helpers = array('Html');
$Controller->set(array(
'tags' => array('cakephp', 'framework'),
'_serialize' => 'tags'
));
$View = new JsonView($Controller);
$View->render();
$this->assertFalse(isset($View->Html), 'No helper loaded.');
}
/**
* testJsonpResponse method
*
* @return void
*/
public function testJsonpResponse() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array('user' => 'fake', 'list' => array('item1', 'item2'));
$Controller->set(array('data' => $data, '_serialize' => 'data'));
$Controller->set(array(
'data' => $data,
'_serialize' => 'data',
'_jsonp' => true
));
$View = new JsonView($Controller);
$output = $View->render(false);
$this->assertSame(json_encode($data), $output);
$this->assertSame('application/json', $Response->type());
}
/**
* Test render with an array in _serialize
*
* @return void
*/
public function testRenderWithoutViewMultiple() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2'));
$Controller->set($data);
$Controller->set('_serialize', array('no', 'user'));
$View = new JsonView($Controller);
$View->request->query = array('callback' => 'jfunc');
$output = $View->render(false);
$expected = 'jfunc(' . json_encode($data) . ')';
$this->assertSame($expected, $output);
$this->assertSame('application/javascript', $Response->type());
$this->assertSame(json_encode(array('no' => $data['no'], 'user' => $data['user'])), $output);
$this->assertSame('application/json', $Response->type());
$View->request->query = array('jsonCallback' => 'jfunc');
$View->viewVars['_jsonp'] = 'jsonCallback';
$output = $View->render(false);
$expected = 'jfunc(' . json_encode($data) . ')';
$this->assertSame($expected, $output);
}
/**
* testRenderWithView method
* Test render with a View file specified.
*
* @return void
*/
@ -93,9 +302,106 @@ class JsonViewTest extends CakeTestCase {
$View = new JsonView($Controller);
$output = $View->render('index');
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => null));
$this->assertSame($expected, $output);
$this->assertSame('application/json', $Response->type());
}
/**
* Test render with a View file specified and named parameters.
*
* @return void
*/
public function testRenderWithViewAndNamed() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
));
$Request = new CakeRequest(null, false);
$Request->params['named'] = array('page' => 2);
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->name = $Controller->viewPath = 'Posts';
$data = array(
'User' => array(
'username' => 'fake'
),
'Item' => array(
array('name' => 'item1'),
array('name' => 'item2')
)
);
$Controller->set('user', $data);
$Controller->helpers = array('Paginator');
$View = new JsonView($Controller);
$output = $View->render('index');
$expected = array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => array('page' => 2));
$this->assertSame(json_encode($expected), $output);
$this->assertSame('application/json', $Response->type());
$View->request->query = array('jsonCallback' => 'jfunc');
$Controller->set('_jsonp', 'jsonCallback');
$View = new JsonView($Controller);
$View->helpers = array('Paginator');
$output = $View->render('index');
$expected['paging']['?']['jsonCallback'] = 'jfunc';
$expected = 'jfunc(' . json_encode($expected) . ')';
$this->assertSame($expected, $output);
$this->assertSame('application/javascript', $Response->type());
}
/**
* JsonViewTest::testRenderInvalidJSON()
*
* @return void
*/
public function testRenderInvalidJSON() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
// non utf-8 stuff
$bar = 'bar';
$bar .= chr(0x97);
$data = array('data' => array('foo' => $bar));
$Controller->set($data);
$Controller->set('_serialize', 'data');
$View = new JsonView($Controller);
// Use a custom error handler
set_error_handler(array($this, 'jsonEncodeErrorHandler'));
try {
$View->render();
restore_error_handler();
$this->fail('Failed asserting that exception of type "CakeException" is thrown.');
} catch (CakeException $e) {
restore_error_handler();
$this->assertRegExp('/UTF-8/', $e->getMessage());
return;
}
}
/**
* JsonViewTest::testRenderJSONBoolFalse()
*
* @return void
*/
public function testRenderJSONBoolFalse() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
// encoding a false, ensure this doesn't trigger exception
$data = false;
$Controller->set($data);
$Controller->set('_serialize', 'data');
$View = new JsonView($Controller);
$output = $View->render();
$this->assertSame('null', $output);
}
}

View file

@ -2,19 +2,18 @@
/**
* MediaViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
@ -35,11 +34,15 @@ class MediaViewTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->MediaView = $this->getMock('MediaView', array('_isActive', '_clearBuffer', '_flushBuffer'));
$this->MediaView->response = $this->getMock(
'CakeResponse',
array('send', 'cache', 'type', 'download', 'statusCode')
);
$this->MediaView = new MediaView();
$this->MediaView->response = $this->getMock('CakeResponse', array(
'cache',
'type',
'disableCache',
'file',
'send',
'compress',
));
}
/**
@ -52,279 +55,64 @@ class MediaViewTest extends CakeTestCase {
unset($this->MediaView);
}
/**
* tests that rendering a file that does not exists throws an exception
*
* @expectedException NotFoundException
* @return void
*/
public function testRenderNotFound() {
$this->MediaView->viewVars = array(
'path' => '/some/missing/folder',
'id' => 'file.jpg'
);
$this->MediaView->render();
}
/**
* testRender method
*
* @return void
*/
public function testRender() {
$this->MediaView->viewVars = array(
$vars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css'
);
$this->MediaView->viewVars = $vars;
$this->MediaView->response->expects($this->once())
->method('disableCache');
$this->MediaView->response->expects($this->once())
->method('file')
->with(
$vars['path'] . $vars['id'],
array('name' => null, 'download' => null)
);
$this->MediaView->render();
}
/**
* Test render() when caching is on.
*
* @return void
*/
public function testRenderCachingAndName() {
$vars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
'cache' => '+1 day',
'name' => 'something_special',
'download' => true,
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('css')
->will($this->returnArgument(0));
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEquals('this is the test asset css file', $output);
$this->assertTrue($result !== false);
$headers = $this->MediaView->response->header();
$this->assertEquals(31, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
* testRenderWithUnknownFileTypeGeneric method
*
* @return void
*/
public function testRenderWithUnknownFileTypeGeneric() {
$currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$_SERVER['HTTP_USER_AGENT'] = 'Some generic browser';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
* testRenderWithUnknownFileTypeOpera method
*
* @return void
*/
public function testRenderWithUnknownFileTypeOpera() {
$currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (Windows NT 6.0; U; en) Presto/2.8.99 Version/11.10';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->at(0))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('type')
->with('application/octetstream')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
* testRenderWithUnknownFileTypeIE method
*
* @return void
*/
public function testRenderWithUnknownFileTypeIE() {
$currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)';
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
'name' => 'config'
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->at(0))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('type')
->with('application/force-download')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
->method('download')
->with('config.ini');
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEquals("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
if ($currentUserAgent !== null) {
$_SERVER['HTTP_USER_AGENT'] = $currentUserAgent;
}
$headers = $this->MediaView->response->header();
$this->assertEquals(35, $headers['Content-Length']);
$this->assertEquals(0, $headers['Expires']);
$this->assertEquals('bytes', $headers['Accept-Ranges']);
$this->assertEquals(
'private, must-revalidate, post-check=0, pre-check=0',
$headers['Cache-Control']
);
$this->assertEquals('no-cache', $headers['Pragma']);
$this->assertContains(gmdate('D, d M Y H:i', time()), $headers['Date']);
}
/**
* testConnectionAborted method
*
* @return void
*/
public function testConnectionAborted() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
);
$this->MediaView->expects($this->once())
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->viewVars = $vars;
$this->MediaView->response->expects($this->never())
->method('type');
->method('disableCache');
$result = $this->MediaView->render();
$this->assertFalse($result);
}
$this->MediaView->response->expects($this->once())
->method('cache')
->with($this->anything(), $vars['cache']);
/**
* testConnectionAbortedOnBuffering method
*
* @return void
*/
public function testConnectionAbortedOnBuffering() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
'id' => 'test_asset.css',
'extension' => 'css',
);
$this->MediaView->response->expects($this->once())
->method('file')
->with(
$vars['path'] . $vars['id'],
array(
'name' => 'something_special.css',
'download' => true
)
);
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->any())
->method('type')
->with('css')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(1))
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->never())->method('_flushBuffer');
$result = $this->MediaView->render();
$this->assertFalse($result);
$this->MediaView->render();
}
/**
@ -335,8 +123,7 @@ class MediaViewTest extends CakeTestCase {
public function testRenderUpperExtension() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
'id' => 'test_2.JPG',
'extension' => 'JPG',
'id' => 'test_2.JPG'
);
$this->MediaView->response->expects($this->any())
@ -344,33 +131,6 @@ class MediaViewTest extends CakeTestCase {
->with('jpg')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->render();
}
/**
* Test downloading files with extension not explicitly set.
*
* @return void
*/
public function testRenderExtensionNotSet() {
$this->MediaView->viewVars = array(
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
'id' => 'test_2.JPG',
);
$this->MediaView->response->expects($this->any())
->method('type')
->with('jpg')
->will($this->returnArgument(0));
$this->MediaView->expects($this->at(0))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->render();
}

View file

@ -2,20 +2,20 @@
/**
* ScaffoldViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Controller
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
App::uses('Scaffold', 'Controller');
App::uses('ScaffoldView', 'View');
@ -52,7 +52,7 @@ class ScaffoldViewMockController extends Controller {
/**
* name property
*
* @var string 'ScaffoldMock'
* @var string
*/
public $name = 'ScaffoldMock';
@ -364,7 +364,7 @@ class ScaffoldViewTest extends CakeTestCase {
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
@ -407,7 +407,7 @@ class ScaffoldViewTest extends CakeTestCase {
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();
@ -448,7 +448,7 @@ class ScaffoldViewTest extends CakeTestCase {
$this->Controller->constructClasses();
ob_start();
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
new Scaffold($this->Controller, $this->Controller->request);
$this->Controller->response->send();
$result = ob_get_clean();

View file

@ -2,25 +2,24 @@
/**
* ThemeViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
App::uses('ThemeView', 'View');
App::uses('Controller', 'Controller');
/**
* ThemePosts2Controller class
*
@ -31,7 +30,7 @@ class ThemePosts2Controller extends Controller {
/**
* name property
*
* @var string 'ThemePosts'
* @var string
*/
public $name = 'ThemePosts';
@ -213,7 +212,7 @@ class ThemeViewTest extends CakeTestCase {
$View = new TestTheme2View($this->Controller);
ob_start();
$result = $View->getViewFileName('does_not_exist');
$View->getViewFileName('does_not_exist');
$expected = ob_get_clean();
$this->assertRegExp("/PagesController::/", $expected);
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected);
@ -234,7 +233,7 @@ class ThemeViewTest extends CakeTestCase {
$View = new TestTheme2View($this->Controller);
ob_start();
$result = $View->getLayoutFileName();
$View->getLayoutFileName();
$expected = ob_get_clean();
$this->assertRegExp("/Missing Layout/", $expected);
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected);

File diff suppressed because it is too large Load diff

View file

@ -2,19 +2,18 @@
/**
* XmlViewTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View
* @since CakePHP(tm) v 2.1.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
@ -29,6 +28,11 @@ App::uses('XmlView', 'View');
*/
class XmlViewTest extends CakeTestCase {
public function setUp() {
parent::setUp();
Configure::write('debug', 0);
}
/**
* testRenderWithoutView method
*
@ -64,6 +68,102 @@ class XmlViewTest extends CakeTestCase {
$expected = Xml::build(array('response' => array('users' => $data)))->asXML();
$this->assertSame($expected, $output);
$Controller->set('_rootNode', 'custom_name');
$View = new XmlView($Controller);
$output = $View->render(false);
$expected = Xml::build(array('custom_name' => array('users' => $data)))->asXML();
$this->assertSame($expected, $output);
}
/**
* Test that rendering with _serialize does not load helpers
*
* @return void
*/
public function testRenderSerializeNoHelpers() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->helpers = array('Html');
$Controller->set(array(
'_serialize' => 'tags',
'tags' => array('cakephp', 'framework')
));
$View = new XmlView($Controller);
$View->render();
$this->assertFalse(isset($View->Html), 'No helper loaded.');
}
/**
* Test that rendering with _serialize respects XML options.
*
* @return void
*/
public function testRenderSerializeWithOptions() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array(
'_serialize' => array('tags'),
'_xmlOptions' => array('format' => 'attributes', 'return' => 'domdocument'),
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
);
$Controller->set($data);
$Controller->viewClass = 'Xml';
$View = new XmlView($Controller);
$result = $View->render();
$expected = Xml::build(array('response' => array('tags' => $data['tags'])), $data['_xmlOptions'])->saveXML();
$this->assertSame($expected, $result);
}
/**
* Test that rendering with _serialize can work with string setting.
*
* @return void
*/
public function testRenderSerializeWithString() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array(
'_serialize' => 'tags',
'_xmlOptions' => array('format' => 'attributes'),
'tags' => array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'id' => '2',
'name' => 'enhancement'
)
)
)
)
);
$Controller->set($data);
$Controller->viewClass = 'Xml';
$View = new XmlView($Controller);
$result = $View->render();
$expected = Xml::build($data['tags'], $data['_xmlOptions'])->asXML();
$this->assertSame($expected, $result);
}
/**
@ -79,13 +179,49 @@ class XmlViewTest extends CakeTestCase {
$Controller->set($data);
$Controller->set('_serialize', array('no', 'user'));
$View = new XmlView($Controller);
$this->assertSame('application/xml', $Response->type());
$output = $View->render(false);
$expected = array(
'response' => array('no' => $data['no'], 'user' => $data['user'])
);
$this->assertSame(Xml::build($expected)->asXML(), $output);
$Controller->set('_rootNode', 'custom_name');
$View = new XmlView($Controller);
$output = $View->render(false);
$expected = array(
'custom_name' => array('no' => $data['no'], 'user' => $data['user'])
);
$this->assertSame(Xml::build($expected)->asXML(), $output);
}
/**
* Test render with an array in _serialize and alias
*
* @return void
*/
public function testRenderWithoutViewMultipleAndAlias() {
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$data = array('original_name' => 'my epic name', 'user' => 'fake', 'list' => array('item1', 'item2'));
$Controller->set($data);
$Controller->set('_serialize', array('new_name' => 'original_name', 'user'));
$View = new XmlView($Controller);
$this->assertSame('application/xml', $Response->type());
$output = $View->render(false);
$expected = array(
'response' => array('new_name' => $data['original_name'], 'user' => $data['user'])
);
$this->assertSame(Xml::build($expected)->asXML(), $output);
$Controller->set('_rootNode', 'custom_name');
$View = new XmlView($Controller);
$output = $View->render(false);
$expected = array(
'custom_name' => array('new_name' => $data['original_name'], 'user' => $data['user'])
);
$this->assertSame(Xml::build($expected)->asXML(), $output);
}
/**