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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
|
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
*/
|
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
|
|
|
|
*/
|
2010-04-04 07:14:00 +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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
*/
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-10 23:11:26 +00:00
|
|
|
class TestHelper extends Helper {
|
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
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() {
|
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());
|
|
|
|
}
|
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() {
|
2011-05-06 05:53:01 +00:00
|
|
|
CakePlugin::unload();
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Helper, $this->View);
|
|
|
|
ClassRegistry::flush();
|
|
|
|
}
|
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',
|
|
|
|
array('HelperTestPost', 'id')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTestComment.body',
|
|
|
|
array('HelperTestComment', 'body')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTest.1.Comment.body',
|
|
|
|
array('HelperTest', '1', 'Comment', 'body')
|
2011-09-08 02:13:37 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'HelperTestComment.BigField',
|
|
|
|
array('HelperTestComment', 'BigField')
|
2011-06-25 02:52:12 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormFieldNameParsing method
|
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-06-25 02:52:12 +00:00
|
|
|
public function testSetEntity($entity, $expected) {
|
|
|
|
$this->Helper->setEntity($entity);
|
2011-06-26 00:02:34 +00:00
|
|
|
$this->assertEquals($expected, $this->Helper->entity());
|
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.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public function testSetEntityScoped() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
2011-06-26 00:02:34 +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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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());
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, 'This is me');
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, 'First Post');
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, 'First Post');
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, array('year' => '2008'));
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, '2008');
|
2011-07-07 01:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test default values with value()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testValueWithDefault() {
|
|
|
|
$this->Helper->request->data = array('zero' => 0);
|
|
|
|
$this->Helper->setEntity('zero');
|
|
|
|
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
|
|
|
$this->assertEqual($result, array('value' => 0));
|
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');
|
|
|
|
$this->assertEqual($result, array('value' => '0'));
|
|
|
|
|
|
|
|
$this->Helper->setEntity('inexistent');
|
|
|
|
$result = $this->Helper->value(array('default' => 'something'), 'inexistent');
|
|
|
|
$this->assertEqual($result, array('value' => 'something'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test habtm data fetching and ensure no pollution happens.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, '');
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, array(2, 3, 4));
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result, array(3 => 3, 5 => 5));
|
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');
|
|
|
|
$this->assertEqual($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
|
|
|
/**
|
|
|
|
* Ensure HTML escaping of url params. So link addresses are valid and not exploited
|
|
|
|
*
|
|
|
|
* @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');
|
|
|
|
$this->assertEqual($result, '/controller/action/1');
|
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');
|
|
|
|
$this->assertEqual($result, '/controller/action/1?one=1&two=2');
|
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\');"'));
|
|
|
|
$this->assertEqual($result, "/posts/index/page:1" onclick="alert('XSS');"");
|
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');
|
|
|
|
$this->assertEqual($result, '/controller/action/1/param:this+one+more');
|
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');
|
|
|
|
$this->assertEqual($result, '/controller/action/1/param:this%20one%20more');
|
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');
|
|
|
|
$this->assertEqual($result, '/controller/action/1/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24');
|
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'
|
|
|
|
));
|
|
|
|
$this->assertEqual($result, "/posts/index/param:%7Baround%20here%7D%5Bthings%5D%5Bare%5D%24%24");
|
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')
|
|
|
|
));
|
|
|
|
$this->assertEqual($result, "/posts/index/page:1?one=value&two=value&three=purple");
|
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() {
|
2009-09-24 03:45:11 +00:00
|
|
|
$_timestamp = Configure::read('Asset.timestamp');
|
|
|
|
$_debug = Configure::read('debug');
|
|
|
|
|
|
|
|
Configure::write('Asset.timestamp', false);
|
|
|
|
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
|
|
|
|
$this->assertEqual($result, CSS_URL . 'cake.generic.css');
|
|
|
|
|
|
|
|
Configure::write('Asset.timestamp', true);
|
|
|
|
Configure::write('debug', 0);
|
|
|
|
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
|
|
|
|
$this->assertEqual($result, CSS_URL . 'cake.generic.css');
|
|
|
|
|
|
|
|
Configure::write('Asset.timestamp', true);
|
|
|
|
Configure::write('debug', 2);
|
|
|
|
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
|
|
|
|
$this->assertPattern('/' . preg_quote(CSS_URL . '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->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2009-09-24 03:45:11 +00:00
|
|
|
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css?someparam');
|
|
|
|
$this->assertEqual($result, CSS_URL . 'cake.generic.css?someparam');
|
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->webroot = '/some/dir/';
|
2010-04-09 03:36:04 +00:00
|
|
|
$result = $this->Helper->assetTimestamp('/some/dir/' . CSS_URL . 'cake.generic.css');
|
|
|
|
$this->assertPattern('/' . preg_quote(CSS_URL . 'cake.generic.css?', '/') . '[0-9]+/', $result);
|
|
|
|
|
2009-09-24 03:45:11 +00:00
|
|
|
Configure::write('debug', $_debug);
|
|
|
|
Configure::write('Asset.timestamp', $_timestamp);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
$_timestamp = Configure::read('Asset.timestamp');
|
|
|
|
Configure::write('Asset.timestamp', 'force');
|
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
2010-07-01 00:47:54 +00:00
|
|
|
));
|
2011-05-06 05:53:01 +00:00
|
|
|
CakePlugin::loadAll();
|
2010-07-01 00:47:54 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/test_plugin/css/test_plugin_asset.css');
|
|
|
|
$this->assertPattern('#/test_plugin/css/test_plugin_asset.css\?[0-9]+$#', $result, 'Missing timestamp plugin');
|
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/test_plugin/css/i_dont_exist.css');
|
|
|
|
$this->assertPattern('#/test_plugin/css/i_dont_exist.css\?$#', $result, 'No error on missing file');
|
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/theme.js');
|
|
|
|
$this->assertPattern('#/theme/test_theme/js/theme.js\?[0-9]+$#', $result, 'Missing timestamp theme');
|
|
|
|
|
|
|
|
$result = $this->Helper->assetTimestamp('/theme/test_theme/js/non_existant.js');
|
|
|
|
$this->assertPattern('#/theme/test_theme/js/non_existant.js\?$#', $result, 'No error on missing file');
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
Configure::write('Asset.timestamp', $_timestamp);
|
|
|
|
}
|
|
|
|
|
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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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');
|
|
|
|
$this->assertEqual($result, 'ok');
|
|
|
|
|
|
|
|
$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');
|
|
|
|
$this->assertEqual($result, 10);
|
|
|
|
|
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');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, 100);
|
|
|
|
}
|
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());
|
|
|
|
$this->assertEqual($result, null);
|
|
|
|
|
|
|
|
$result = $this->Helper->clean(array('<script>with something</script>', '<applet>something else</applet>'));
|
|
|
|
$this->assertEqual($result, array('with something', 'something else'));
|
|
|
|
|
|
|
|
$result = $this->Helper->clean('<script>with something</script>');
|
|
|
|
$this->assertEqual($result, 'with something');
|
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>');
|
2008-08-26 23:15:48 +00:00
|
|
|
$this->assertNoPattern('#</*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>");
|
2008-08-26 23:15:48 +00:00
|
|
|
$this->assertNoPattern('#</*script#', $result);
|
2008-08-27 03:42:17 +00:00
|
|
|
|
|
|
|
$result = $this->Helper->clean('<body/onload=do(/something/)>');
|
|
|
|
$this->assertEqual($result, '<body/>');
|
|
|
|
|
|
|
|
$result = $this->Helper->clean('<script>alert(document.cookie)</script>');
|
|
|
|
$this->assertEqual($result, '&lt;script&gt;alert(document.cookie)&lt;/script&gt;');
|
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');
|
|
|
|
$this->assertEqual($result,'My Title');
|
|
|
|
}
|
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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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(
|
2011-04-17 10:35:21 +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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2010-07-03 15:36:53 +00:00
|
|
|
));
|
2011-05-10 04:03:58 +00:00
|
|
|
CakePlugin::loadAll();
|
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();
|
|
|
|
$expected = array();
|
2010-07-03 17:29:15 +00:00
|
|
|
$this->assertEquals($expected, $result, 'Helper helpers were attached to the collection.');
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
$result1 = $Helper->Html;
|
|
|
|
$result2 = $Helper->Html;
|
|
|
|
|
|
|
|
$result1->testprop = 1;
|
|
|
|
$this->assertEquals($result1->testprop, $result2->testprop);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|