2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* HelperTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
|
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('Helper', 'View');
|
2010-12-11 05:47:55 +00:00
|
|
|
App::uses('Model', 'Model');
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('Router', 'Routing');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* HelperTestPost class
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class HelperTestPost extends Model {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2013-09-17 12:44:34 +00:00
|
|
|
* @var boolean
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function schema($field = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_schema = array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
|
|
|
|
'body' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
|
'number' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'date' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
|
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
|
|
|
|
);
|
|
|
|
return $this->_schema;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2011-12-01 07:21:31 +00:00
|
|
|
public $hasAndBelongsToMany = array('HelperTestTag' => array('with' => 'HelperTestPostsTag'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* HelperTestComment class
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class HelperTestComment extends Model {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2013-09-17 12:44:34 +00:00
|
|
|
* @var boolean
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function schema($field = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_schema = array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'author_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
|
|
|
|
'body' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
|
2011-09-08 02:13:37 +00:00
|
|
|
'BigField' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
|
2008-05-30 11:40:08 +00:00
|
|
|
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
|
|
|
|
);
|
|
|
|
return $this->_schema;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* HelperTestTag class
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class HelperTestTag extends Model {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2013-09-17 12:44:34 +00:00
|
|
|
* @var boolean
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function schema($field = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_schema = array(
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
|
|
|
|
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
|
|
|
|
);
|
|
|
|
return $this->_schema;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* HelperTestPostsTag class
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class HelperTestPostsTag extends Model {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2013-09-17 12:44:34 +00:00
|
|
|
* @var boolean
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function schema($field = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_schema = array(
|
|
|
|
'helper_test_post_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'helper_test_tag_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
);
|
|
|
|
return $this->_schema;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-10 23:11:26 +00:00
|
|
|
class TestHelper extends Helper {
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2012-11-30 06:41:23 +00:00
|
|
|
/**
|
|
|
|
* Settings for this helper.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $settings = array(
|
|
|
|
'key1' => 'val1',
|
|
|
|
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'val2.2')
|
|
|
|
);
|
|
|
|
|
2010-07-03 15:36:53 +00:00
|
|
|
/**
|
2011-10-10 21:18:48 +00:00
|
|
|
* Helpers for this helper.
|
2010-07-03 15:36:53 +00:00
|
|
|
*
|
2012-11-30 06:41:23 +00:00
|
|
|
* @var array
|
2010-07-03 15:36:53 +00:00
|
|
|
*/
|
2011-10-10 21:18:48 +00:00
|
|
|
public $helpers = array('Html', 'TestPlugin.OtherHelper');
|
2010-07-03 15:36:53 +00:00
|
|
|
|
2010-06-10 23:11:26 +00:00
|
|
|
/**
|
|
|
|
* expose a method as public
|
|
|
|
*
|
2011-04-17 10:35:21 +00:00
|
|
|
* @param string $options
|
|
|
|
* @param string $exclude
|
|
|
|
* @param string $insertBefore
|
|
|
|
* @param string $insertAfter
|
2010-06-10 23:11:26 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
2010-06-10 23:11:26 +00:00
|
|
|
return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter);
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2010-06-10 23:11:26 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* HelperTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class HelperTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2012-04-10 01:46:38 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ClassRegistry::flush();
|
|
|
|
Router::reload();
|
|
|
|
$null = null;
|
|
|
|
$this->View = new View($null);
|
2010-07-03 05:10:36 +00:00
|
|
|
$this->Helper = new Helper($this->View);
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request = new CakeRequest(null, false);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ClassRegistry::addObject('HelperTestPost', new HelperTestPost());
|
|
|
|
ClassRegistry::addObject('HelperTestComment', new HelperTestComment());
|
|
|
|
ClassRegistry::addObject('HelperTestTag', new HelperTestTag());
|
2012-02-08 04:14:56 +00:00
|
|
|
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2012-02-08 04:14:56 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2012-04-10 01:46:38 +00:00
|
|
|
parent::tearDown();
|
|
|
|
Configure::delete('Asset');
|
|
|
|
|
2011-05-06 05:53:01 +00:00
|
|
|
CakePlugin::unload();
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Helper, $this->View);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
/**
|
|
|
|
* Provider for setEntity test.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function entityProvider() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'HelperTestPost.id',
|
2011-11-11 03:22:11 +00:00
|
|
|
array('HelperTestPost', 'id'),
|
|
|
|
'HelperTestPost',
|
|
|
|
'id'
|
2011-06-25 02:52:12 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTestComment.body',
|
2011-11-11 03:22:11 +00:00
|
|
|
array('HelperTestComment', 'body'),
|
|
|
|
'HelperTestComment',
|
|
|
|
'body'
|
2011-06-25 02:52:12 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTest.1.Comment.body',
|
2011-11-11 03:22:11 +00:00
|
|
|
array('HelperTest', '1', 'Comment', 'body'),
|
|
|
|
'Comment',
|
|
|
|
'body'
|
2011-09-08 02:13:37 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTestComment.BigField',
|
2011-11-11 03:22:11 +00:00
|
|
|
array('HelperTestComment', 'BigField'),
|
|
|
|
'HelperTestComment',
|
|
|
|
'BigField'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTestComment.min',
|
|
|
|
array('HelperTestComment', 'min'),
|
|
|
|
'HelperTestComment',
|
|
|
|
'min'
|
2011-06-25 02:52:12 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-11-30 06:41:23 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* Test setting an entity and retrieving the entity, model and field.
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2011-06-25 02:52:12 +00:00
|
|
|
* @dataProvider entityProvider
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-11-11 03:22:11 +00:00
|
|
|
public function testSetEntity($entity, $expected, $modelKey, $fieldKey) {
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->setEntity($entity);
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2011-11-11 03:22:11 +00:00
|
|
|
$this->assertEquals($modelKey, $this->Helper->model());
|
|
|
|
$this->assertEquals($fieldKey, $this->Helper->field());
|
2011-06-25 02:52:12 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
/**
|
|
|
|
* test setEntity with setting a scope.
|
|
|
|
*
|
2013-07-05 15:19:22 +00:00
|
|
|
* @return void
|
2011-06-25 02:52:12 +00:00
|
|
|
*/
|
|
|
|
public function testSetEntityScoped() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
2011-11-11 03:22:11 +00:00
|
|
|
$this->assertEquals(array('HelperTestPost'), $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('id');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('HelperTestPost', 'id');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.body');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('HelperTestComment', 'body');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('body');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('HelperTestPost', 'body');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-06-25 17:10:09 +00:00
|
|
|
$this->Helper->setEntity('2.body');
|
|
|
|
$expected = array('HelperTestPost', '2', 'body');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2011-06-25 17:10:09 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity('Something.else');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('Something', 'else');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.5.id');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('HelperTestComment', 5, 'id');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.id.time');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('HelperTestComment', 'id', 'time');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-09-17 16:29:21 +00:00
|
|
|
$this->Helper->setEntity('HelperTestComment.created.year');
|
|
|
|
$expected = array('HelperTestComment', 'created', 'year');
|
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity(null);
|
|
|
|
$this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist');
|
2011-06-25 02:52:12 +00:00
|
|
|
$expected = array('ModelThatDoesntExist', 'field_that_doesnt_exist');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-06-25 23:19:53 +00:00
|
|
|
/**
|
|
|
|
* Test that setEntity() and model()/field() work with associated models.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetEntityAssociated() {
|
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.title');
|
|
|
|
$expected = array('HelperTestPost', '1', 'HelperTestComment', '1', 'title');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2011-06-25 23:19:53 +00:00
|
|
|
|
|
|
|
$this->assertEquals('HelperTestComment', $this->Helper->model());
|
2011-09-08 02:13:37 +00:00
|
|
|
}
|
|
|
|
|
2011-10-27 03:46:15 +00:00
|
|
|
/**
|
|
|
|
* Test creating saveMany() compatible entities
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetEntitySaveMany() {
|
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('0.HelperTestPost.id');
|
|
|
|
$expected = array('0', 'HelperTestPost', 'id');
|
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
|
|
|
}
|
|
|
|
|
2011-09-08 02:13:37 +00:00
|
|
|
/**
|
|
|
|
* Test that setEntity doesn't make CamelCase fields that are not associations an
|
|
|
|
* associated model.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetEntityAssociatedCamelCaseField() {
|
2011-09-09 01:45:36 +00:00
|
|
|
$this->Helper->fieldset = array(
|
|
|
|
'HelperTestComment' => array(
|
|
|
|
'fields' => array('BigField' => array('type' => 'integer'))
|
|
|
|
)
|
|
|
|
);
|
2011-09-08 02:13:37 +00:00
|
|
|
$this->Helper->setEntity('HelperTestComment', true);
|
|
|
|
$this->Helper->setEntity('HelperTestComment.BigField');
|
|
|
|
|
|
|
|
$this->assertEquals('HelperTestComment', $this->Helper->model());
|
|
|
|
$this->assertEquals('BigField', $this->Helper->field());
|
2011-06-25 23:19:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 01:45:36 +00:00
|
|
|
/**
|
|
|
|
* Test that multiple fields work when they are camelcase and in fieldset
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetEntityAssociatedCamelCaseFieldHabtmMultiple() {
|
|
|
|
$this->Helper->fieldset = array(
|
|
|
|
'HelperTestComment' => array(
|
|
|
|
'fields' => array('Tag' => array('type' => 'multiple'))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Helper->setEntity('HelperTestComment', true);
|
|
|
|
$this->Helper->setEntity('Tag');
|
|
|
|
|
|
|
|
$this->assertEquals('Tag', $this->Helper->model());
|
|
|
|
$this->assertEquals('Tag', $this->Helper->field());
|
|
|
|
$this->assertEquals(array('Tag', 'Tag'), $this->Helper->entity());
|
|
|
|
}
|
|
|
|
|
2011-10-26 02:21:27 +00:00
|
|
|
/**
|
|
|
|
* Test that habtm associations can have property fields created.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetEntityHabtmPropertyFieldNames() {
|
|
|
|
$this->Helper->fieldset = array(
|
|
|
|
'HelperTestComment' => array(
|
|
|
|
'fields' => array('Tag' => array('type' => 'multiple'))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Helper->setEntity('HelperTestComment', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('Tag.name');
|
|
|
|
$this->assertEquals('Tag', $this->Helper->model());
|
|
|
|
$this->assertEquals('name', $this->Helper->field());
|
|
|
|
$this->assertEquals(array('Tag', 'name'), $this->Helper->entity());
|
|
|
|
}
|
|
|
|
|
2010-08-24 01:39:23 +00:00
|
|
|
/**
|
|
|
|
* test that 'view' doesn't break things.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetEntityWithView() {
|
2010-08-24 01:39:23 +00:00
|
|
|
$this->assertNull($this->Helper->setEntity('Allow.view.group_id'));
|
|
|
|
$this->assertNull($this->Helper->setEntity('Allow.view'));
|
|
|
|
$this->assertNull($this->Helper->setEntity('View.view'));
|
|
|
|
}
|
|
|
|
|
2009-01-26 19:45:55 +00:00
|
|
|
/**
|
|
|
|
* test getting values from Helper
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testValue() {
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data = array('fullname' => 'This is me');
|
2009-01-26 19:45:55 +00:00
|
|
|
$this->Helper->setEntity('fullname');
|
|
|
|
$result = $this->Helper->value('fullname');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('This is me', $result);
|
2009-01-26 19:45:55 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'Post' => array('name' => 'First Post')
|
|
|
|
);
|
2009-01-26 19:45:55 +00:00
|
|
|
$this->Helper->setEntity('Post.name');
|
|
|
|
$result = $this->Helper->value('Post.name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('First Post', $result);
|
2009-01-26 19:45:55 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'Post' => array(2 => array('name' => 'First Post'))
|
|
|
|
);
|
2009-01-26 19:45:55 +00:00
|
|
|
$this->Helper->setEntity('Post.2.name');
|
|
|
|
$result = $this->Helper->value('Post.2.name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('First Post', $result);
|
2009-01-26 19:45:55 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'Post' => array(
|
|
|
|
2 => array('created' => array('year' => '2008'))
|
|
|
|
)
|
|
|
|
);
|
2009-01-26 19:45:55 +00:00
|
|
|
$this->Helper->setEntity('Post.2.created');
|
|
|
|
$result = $this->Helper->value('Post.2.created');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('year' => '2008'), $result);
|
2009-01-26 19:45:55 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'Post' => array(
|
|
|
|
2 => array('created' => array('year' => '2008'))
|
|
|
|
)
|
|
|
|
);
|
2009-01-26 19:45:55 +00:00
|
|
|
$this->Helper->setEntity('Post.2.created.year');
|
|
|
|
$result = $this->Helper->value('Post.2.created.year');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('2008', $result);
|
2011-07-07 01:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test default values with value()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testValueWithDefault() {
|
2011-07-07 01:26:07 +00:00
|
|
|
$this->Helper->request->data = array('zero' => 0);
|
|
|
|
$this->Helper->setEntity('zero');
|
|
|
|
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('value' => 0), $result);
|
2009-11-10 02:00:19 +00:00
|
|
|
|
2011-07-07 01:26:07 +00:00
|
|
|
$this->Helper->request->data = array('zero' => '0');
|
|
|
|
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('value' => '0'), $result);
|
2011-07-07 01:26:07 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('inexistent');
|
|
|
|
$result = $this->Helper->value(array('default' => 'something'), 'inexistent');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('value' => 'something'), $result);
|
2011-07-07 01:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test habtm data fetching and ensure no pollution happens.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testValueHabtmKeys() {
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'HelperTestTag' => array('HelperTestTag' => '')
|
|
|
|
);
|
2009-11-10 02:00:19 +00:00
|
|
|
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
|
|
|
|
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('', $result);
|
2009-11-10 02:00:19 +00:00
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'HelperTestTag' => array(
|
|
|
|
'HelperTestTag' => array(2, 3, 4)
|
|
|
|
)
|
|
|
|
);
|
2009-11-10 02:00:19 +00:00
|
|
|
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
|
|
|
|
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(2, 3, 4), $result);
|
2009-11-10 02:00:19 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data = array(
|
2009-11-10 02:00:19 +00:00
|
|
|
'HelperTestTag' => array(
|
|
|
|
array('id' => 3),
|
|
|
|
array('id' => 5)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
|
|
|
|
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(3 => 3, 5 => 5), $result);
|
2010-03-10 19:46:02 +00:00
|
|
|
|
2011-07-07 01:26:07 +00:00
|
|
|
$this->Helper->request->data = array(
|
|
|
|
'HelperTestTag' => array(
|
|
|
|
'body' => '',
|
|
|
|
'title' => 'winning'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$this->Helper->setEntity('HelperTestTag.body');
|
|
|
|
$result = $this->Helper->value('HelperTestTag.body');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('', $result);
|
2009-01-26 19:45:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-02-25 19:51:41 +00:00
|
|
|
/**
|
2013-10-08 03:17:58 +00:00
|
|
|
* Ensure HTML escaping of URL params. So link addresses are valid and not exploited
|
2009-02-25 19:51:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUrlConversion() {
|
2009-02-25 19:51:41 +00:00
|
|
|
$result = $this->Helper->url('/controller/action/1');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/controller/action/1', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-25 19:51:41 +00:00
|
|
|
$result = $this->Helper->url('/controller/action/1?one=1&two=2');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/controller/action/1?one=1&two=2', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-25 19:51:41 +00:00
|
|
|
$result = $this->Helper->url(array('controller' => 'posts', 'action' => 'index', 'page' => '1" onclick="alert(\'XSS\');"'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals("/posts/index/page:1%22%20onclick%3D%22alert%28%27XSS%27%29%3B%22", $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-25 20:01:55 +00:00
|
|
|
$result = $this->Helper->url('/controller/action/1/param:this+one+more');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/controller/action/1/param:this+one+more', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-25 20:01:55 +00:00
|
|
|
$result = $this->Helper->url('/controller/action/1/param:this%20one%20more');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/controller/action/1/param:this%20one%20more', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-25 20:01:55 +00:00
|
|
|
$result = $this->Helper->url('/controller/action/1/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('/controller/action/1/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2009-02-25 20:01:55 +00:00
|
|
|
$result = $this->Helper->url(array(
|
|
|
|
'controller' => 'posts', 'action' => 'index', 'param' => '%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24'
|
|
|
|
));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals("/posts/index/param:%257Baround%2520here%257D%255Bthings%255D%255Bare%255D%2524%2524", $result);
|
2009-04-15 02:29:50 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->url(array(
|
2009-07-24 19:18:37 +00:00
|
|
|
'controller' => 'posts', 'action' => 'index', 'page' => '1',
|
2009-04-15 02:29:50 +00:00
|
|
|
'?' => array('one' => 'value', 'two' => 'value', 'three' => 'purple')
|
|
|
|
));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals("/posts/index/page:1?one=value&two=value&three=purple", $result);
|
2009-02-25 19:51:41 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-09-24 03:45:11 +00:00
|
|
|
/**
|
|
|
|
* test assetTimestamp application
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAssetTimestamp() {
|
2012-04-10 01:46:38 +00:00
|
|
|
Configure::write('Foo.bar', 'test');
|
2009-09-24 03:45:11 +00:00
|
|
|
Configure::write('Asset.timestamp', false);
|
2013-07-31 14:36:57 +00:00
|
|
|
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css');
|
|
|
|
$this->assertEquals(Configure::read('App.cssBaseUrl') . 'cake.generic.css', $result);
|
2009-09-24 03:45:11 +00:00
|
|
|
|
|
|
|
Configure::write('Asset.timestamp', true);
|
|
|
|
Configure::write('debug', 0);
|
2013-05-10 15:04:46 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/%3Cb%3E/cake.generic.css');
|
|
|
|
$this->assertEquals('/%3Cb%3E/cake.generic.css', $result);
|
|
|
|
|
2013-07-31 14:36:57 +00:00
|
|
|
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css');
|
|
|
|
$this->assertEquals(Configure::read('App.cssBaseUrl') . 'cake.generic.css', $result);
|
2009-09-24 03:45:11 +00:00
|
|
|
|
|
|
|
Configure::write('Asset.timestamp', true);
|
|
|
|
Configure::write('debug', 2);
|
2013-07-31 14:36:57 +00:00
|
|
|
$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);
|
2009-09-24 03:45:11 +00:00
|
|
|
|
|
|
|
Configure::write('Asset.timestamp', 'force');
|
|
|
|
Configure::write('debug', 0);
|
2013-07-31 14:36:57 +00:00
|
|
|
$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);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2013-07-31 14:36:57 +00:00
|
|
|
$result = $this->Helper->assetTimestamp(Configure::read('App.cssBaseUrl') . 'cake.generic.css?someparam');
|
|
|
|
$this->assertEquals(Configure::read('App.cssBaseUrl') . 'cake.generic.css?someparam', $result);
|
2009-09-24 03:45:11 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->webroot = '/some/dir/';
|
2013-07-31 14:36:57 +00:00
|
|
|
$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);
|
2009-09-24 03:45:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:55:59 +00:00
|
|
|
/**
|
|
|
|
* test assetUrl application
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssetUrl() {
|
|
|
|
$this->Helper->webroot = '';
|
|
|
|
$result = $this->Helper->assetUrl(array(
|
|
|
|
'controller' => 'js',
|
|
|
|
'action' => 'post',
|
|
|
|
'ext' => 'js'
|
|
|
|
),
|
|
|
|
array('fullBase' => true)
|
|
|
|
);
|
2013-07-31 14:36:57 +00:00
|
|
|
$this->assertEquals(Router::fullBaseUrl() . '/js/post.js', $result);
|
2012-02-06 21:55:59 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetUrl('foo.jpg', array('pathPrefix' => 'img/'));
|
|
|
|
$this->assertEquals('img/foo.jpg', $result);
|
|
|
|
|
|
|
|
$result = $this->Helper->assetUrl('foo.jpg', array('fullBase' => true));
|
2013-07-31 14:36:57 +00:00
|
|
|
$this->assertEquals(Router::fullBaseUrl() . '/foo.jpg', $result);
|
2012-02-06 21:55:59 +00:00
|
|
|
|
2012-02-08 04:14:56 +00:00
|
|
|
$result = $this->Helper->assetUrl('style', array('ext' => '.css'));
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->assertEquals('style.css', $result);
|
2012-02-08 04:14:56 +00:00
|
|
|
|
2012-11-26 04:31:22 +00:00
|
|
|
$result = $this->Helper->assetUrl('dir/sub dir/my image', array('ext' => '.jpg'));
|
|
|
|
$this->assertEquals('dir/sub%20dir/my%20image.jpg', $result);
|
|
|
|
|
2012-04-10 01:20:03 +00:00
|
|
|
$result = $this->Helper->assetUrl('foo.jpg?one=two&three=four');
|
|
|
|
$this->assertEquals('foo.jpg?one=two&three=four', $result);
|
2013-06-21 18:24:39 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetUrl('dir/big+tall/image', array('ext' => '.jpg'));
|
|
|
|
$this->assertEquals('dir/big%2Btall/image.jpg', $result);
|
2012-04-10 01:20:03 +00:00
|
|
|
}
|
|
|
|
|
2013-04-28 03:00:50 +00:00
|
|
|
/**
|
|
|
|
* 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));
|
2013-07-14 05:38:55 +00:00
|
|
|
$expected = FULL_BASE_URL . '/cake_dev/app/webroot/img/cake.icon.png';
|
|
|
|
$this->assertEquals($expected, $result);
|
2013-04-28 03:00:50 +00:00
|
|
|
}
|
|
|
|
|
2012-04-10 01:20:03 +00:00
|
|
|
/**
|
|
|
|
* Test assetUrl with plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssetUrlPlugin() {
|
|
|
|
$this->Helper->webroot = '';
|
2012-02-08 04:14:56 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
|
|
|
|
$result = $this->Helper->assetUrl('TestPlugin.style', array('ext' => '.css'));
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->assertEquals('test_plugin/style.css', $result);
|
2012-02-08 04:14:56 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetUrl('TestPlugin.style', array('ext' => '.css', 'plugin' => false));
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->assertEquals('TestPlugin.style.css', $result);
|
2012-02-08 04:14:56 +00:00
|
|
|
|
|
|
|
CakePlugin::unload('TestPlugin');
|
2012-04-10 01:20:03 +00:00
|
|
|
}
|
2012-02-08 04:14:56 +00:00
|
|
|
|
2012-04-10 01:20:03 +00:00
|
|
|
/**
|
|
|
|
* test assetUrl and Asset.timestamp = force
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAssetUrlTimestampForce() {
|
|
|
|
$this->Helper->webroot = '';
|
2012-02-06 21:55:59 +00:00
|
|
|
Configure::write('Asset.timestamp', 'force');
|
|
|
|
|
2013-07-31 14:36:57 +00:00
|
|
|
$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);
|
2012-02-06 21:55:59 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 00:47:54 +00:00
|
|
|
/**
|
|
|
|
* test assetTimestamp with plugins and themes
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAssetTimestampPluginsAndThemes() {
|
2010-07-01 00:47:54 +00:00
|
|
|
Configure::write('Asset.timestamp', 'force');
|
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
2010-07-01 00:47:54 +00:00
|
|
|
));
|
2012-03-16 02:50:05 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2010-07-01 00:47:54 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/test_plugin/css/test_plugin_asset.css');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('#/test_plugin/css/test_plugin_asset.css\?[0-9]+$#', $result, 'Missing timestamp plugin');
|
2010-07-01 00:47:54 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/test_plugin/css/i_dont_exist.css');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('#/test_plugin/css/i_dont_exist.css\?$#', $result, 'No error on missing file');
|
2010-07-01 00:47:54 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/theme.js');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('#/theme/test_theme/js/theme.js\?[0-9]+$#', $result, 'Missing timestamp theme');
|
2010-07-01 00:47:54 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/non_existant.js');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('#/theme/test_theme/js/non_existant.js\?$#', $result, 'No error on missing file');
|
2010-07-01 00:47:54 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFieldsWithSameName method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFieldsWithSameName() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity('HelperTestTag', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestTag.id');
|
2011-06-25 05:02:22 +00:00
|
|
|
$expected = array('HelperTestTag', 'id');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('My.id');
|
2011-06-25 05:02:22 +00:00
|
|
|
$expected = array('My', 'id');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('MyOther.id');
|
2011-06-25 05:02:22 +00:00
|
|
|
$expected = array('MyOther', 'id');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFieldSameAsModel method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFieldSameAsModel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity('HelperTestTag', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('helper_test_post');
|
2011-06-25 05:02:22 +00:00
|
|
|
$expected = array('HelperTestTag', 'helper_test_post');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-09-26 04:46:51 +00:00
|
|
|
$this->Helper->setEntity('HelperTestTag');
|
2011-06-25 05:02:22 +00:00
|
|
|
$expected = array('HelperTestTag', 'HelperTestTag');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testFieldSuffixForDate method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFieldSuffixForDate() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
2011-06-25 05:02:22 +00:00
|
|
|
$expected = array('HelperTestPost');
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-06-25 23:19:53 +00:00
|
|
|
foreach (array('year', 'month', 'day', 'hour', 'min', 'meridian') as $d) {
|
2011-06-25 17:10:09 +00:00
|
|
|
$this->Helper->setEntity('date.' . $d);
|
|
|
|
$expected = array('HelperTestPost', 'date', $d);
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2011-06-25 17:10:09 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMulitDimensionValue method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-06-25 05:02:22 +00:00
|
|
|
public function testMultiDimensionValue() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->data = array();
|
2009-11-04 19:05:12 +00:00
|
|
|
for ($i = 0; $i < 2; $i++) {
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['Model'][$i] = 'what';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result[] = $this->Helper->value("Model.{$i}");
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['Model'][$i] = array();
|
2009-11-04 19:05:12 +00:00
|
|
|
for ($j = 0; $j < 2; $j++) {
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['Model'][$i][$j] = 'how';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result[] = $this->Helper->value("Model.{$i}.{$j}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$expected = array('what', 'how', 'how', 'what', 'how', 'how');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['HelperTestComment']['5']['id'] = 'ok';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Helper->value('HelperTestComment.5.id');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('ok', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['HelperTestPost']['5']['created']['month'] = '10';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Helper->value('5.created.month');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(10, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['HelperTestPost']['0']['id'] = 100;
|
2011-06-25 05:02:22 +00:00
|
|
|
$result = $this->Helper->value('HelperTestPost.0.id');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(100, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testClean method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testClean() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Helper->clean(array());
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(null, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->clean(array('<script>with something</script>', '<applet>something else</applet>'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('with something', 'something else'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->clean('<script>with something</script>');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('with something', $result);
|
2008-08-27 03:42:17 +00:00
|
|
|
|
2008-08-24 19:01:54 +00:00
|
|
|
$result = $this->Helper->clean('<script type="text/javascript">alert("ruined");</script>');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('#</*script#', $result);
|
2008-08-27 03:42:17 +00:00
|
|
|
|
2008-08-24 19:01:54 +00:00
|
|
|
$result = $this->Helper->clean("<script \ntype=\"text/javascript\">\n\talert('ruined');\n\n\t\t</script>");
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('#</*script#', $result);
|
2008-08-27 03:42:17 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->clean('<body/onload=do(/something/)>');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('<body/>', $result);
|
2008-08-27 03:42:17 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->clean('<script>alert(document.cookie)</script>');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('&lt;script&gt;alert(document.cookie)&lt;/script&gt;', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-22 04:24:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testMultiDimensionalField method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultiDimensionalField() {
|
2009-10-22 04:24:54 +00:00
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
|
|
|
|
2011-06-25 02:52:12 +00:00
|
|
|
$entity = 'HelperTestPost.2.HelperTestComment.1.title';
|
|
|
|
$this->Helper->setEntity($entity);
|
|
|
|
$expected = array(
|
|
|
|
'HelperTestPost', '2', 'HelperTestComment', '1', 'title'
|
|
|
|
);
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2011-06-25 02:52:12 +00:00
|
|
|
|
|
|
|
$entity = 'HelperTestPost.1.HelperTestComment.1.HelperTestTag.1.created';
|
|
|
|
$this->Helper->setEntity($entity);
|
|
|
|
$expected = array(
|
|
|
|
'HelperTestPost', '1', 'HelperTestComment', '1',
|
|
|
|
'HelperTestTag', '1', 'created'
|
|
|
|
);
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
2011-06-25 02:52:12 +00:00
|
|
|
|
|
|
|
$entity = 'HelperTestPost.0.HelperTestComment.1.HelperTestTag.1.fake';
|
|
|
|
$expected = array(
|
|
|
|
'HelperTestPost', '0', 'HelperTestComment', '1',
|
|
|
|
'HelperTestTag', '1', 'fake'
|
|
|
|
);
|
|
|
|
$this->Helper->setEntity($entity);
|
|
|
|
|
|
|
|
$entity = '1.HelperTestComment.1.HelperTestTag.created.year';
|
|
|
|
$this->Helper->setEntity($entity);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['HelperTestPost'][2]['HelperTestComment'][1]['title'] = 'My Title';
|
2009-10-22 04:24:54 +00:00
|
|
|
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.title');
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->assertEquals('My Title', $result);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['HelperTestPost'][2]['HelperTestComment'][1]['created']['year'] = 2008;
|
2009-10-22 04:24:54 +00:00
|
|
|
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->assertEquals(2008, $result);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data[2]['HelperTestComment'][1]['created']['year'] = 2008;
|
2009-10-22 04:24:54 +00:00
|
|
|
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->assertEquals(2008, $result);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['HelperTestPost']['title'] = 'My Title';
|
2009-10-22 04:24:54 +00:00
|
|
|
$result = $this->Helper->value('title');
|
2011-06-25 02:52:12 +00:00
|
|
|
$this->assertEquals('My Title', $result);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data['My']['title'] = 'My Title';
|
2009-10-22 04:24:54 +00:00
|
|
|
$result = $this->Helper->value('My.title');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('My Title', $result);
|
2009-10-22 04:24:54 +00:00
|
|
|
}
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWebrootPaths() {
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->webroot = '/';
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $this->Helper->webroot('/img/cake.power.gif');
|
|
|
|
$expected = '/img/cake.power.gif';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
$this->Helper->theme = 'test_theme';
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
App::build(array(
|
2012-03-16 02:50:05 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2009-11-26 20:52:38 +00:00
|
|
|
));
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $this->Helper->webroot('/img/cake.power.gif');
|
|
|
|
$expected = '/theme/test_theme/img/cake.power.gif';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $this->Helper->webroot('/img/test.jpg');
|
|
|
|
$expected = '/theme/test_theme/img/test.jpg';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-11-26 20:52:38 +00:00
|
|
|
|
|
|
|
$webRoot = Configure::read('App.www_root');
|
2011-04-17 10:35:21 +00:00
|
|
|
Configure::write('App.www_root', CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $this->Helper->webroot('/img/cake.power.gif');
|
|
|
|
$expected = '/theme/test_theme/img/cake.power.gif';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $this->Helper->webroot('/img/test.jpg');
|
|
|
|
$expected = '/theme/test_theme/img/test.jpg';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $this->Helper->webroot('/img/cake.icon.gif');
|
|
|
|
$expected = '/img/cake.icon.gif';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->webroot('/img/cake.icon.gif?some=param');
|
|
|
|
$expected = '/img/cake.icon.gif?some=param';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-14 01:43:02 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
Configure::write('App.www_root', $webRoot);
|
|
|
|
}
|
2010-06-10 23:11:26 +00:00
|
|
|
|
2010-07-03 05:15:00 +00:00
|
|
|
/**
|
|
|
|
* test lazy loading helpers is seamless
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLazyLoadingHelpers() {
|
2010-07-03 15:36:53 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2010-07-03 15:36:53 +00:00
|
|
|
));
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2010-07-03 15:36:53 +00:00
|
|
|
$Helper = new TestHelper($this->View);
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('OtherHelperHelper', $Helper->OtherHelper);
|
|
|
|
$this->assertInstanceOf('HtmlHelper', $Helper->Html);
|
2010-07-03 15:36:53 +00:00
|
|
|
App::build();
|
2010-07-03 05:15:00 +00:00
|
|
|
}
|
2010-07-03 15:41:49 +00:00
|
|
|
|
2010-07-03 17:29:15 +00:00
|
|
|
/**
|
|
|
|
* test that a helpers Helper is not 'attached' to the collection
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testThatHelperHelpersAreNotAttached() {
|
2010-07-03 17:29:15 +00:00
|
|
|
$Helper = new TestHelper($this->View);
|
2010-07-03 17:33:09 +00:00
|
|
|
$Helper->OtherHelper;
|
|
|
|
|
|
|
|
$result = $this->View->Helpers->enabled();
|
2013-09-02 01:39:50 +00:00
|
|
|
$this->assertEquals(array(), $result, 'Helper helpers were attached to the collection.');
|
2010-07-03 17:29:15 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 15:41:49 +00:00
|
|
|
/**
|
|
|
|
* test that the lazy loader doesn't duplicate objects on each access.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLazyLoadingUsesReferences() {
|
2010-07-03 15:41:49 +00:00
|
|
|
$Helper = new TestHelper($this->View);
|
2012-03-16 02:50:05 +00:00
|
|
|
$resultA = $Helper->Html;
|
|
|
|
$resultB = $Helper->Html;
|
2010-07-03 15:41:49 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$resultA->testprop = 1;
|
|
|
|
$this->assertEquals($resultA->testprop, $resultB->testprop);
|
2010-07-03 15:41:49 +00:00
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|