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
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
* @access public
|
|
|
|
* @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' => ''),
|
|
|
|
'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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* helpers for this helper.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $helpers = array('Html', 'TestPlugin.OtherHelper');
|
|
|
|
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormFieldNameParsing method
|
2008-08-27 03:42:17 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetEntity() {
|
2008-05-30 11:40:08 +00:00
|
|
|
// PHP4 reference hack
|
|
|
|
ClassRegistry::removeObject('view');
|
|
|
|
ClassRegistry::addObject('view', $this->View);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost.id');
|
|
|
|
$this->assertFalse($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.body');
|
|
|
|
$this->assertFalse($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestComment');
|
|
|
|
$this->assertEqual($this->View->field, 'body');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, null);
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('_Token.fields');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'fields');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, '_Token');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
|
|
|
|
$this->Helper->setEntity('id');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.body');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'body');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, 'HelperTestComment');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('body');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'body');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('Something.else');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'else');
|
|
|
|
$this->assertEqual($this->View->modelId, false);
|
|
|
|
$this->assertEqual($this->View->association, 'Something');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, '');
|
|
|
|
|
|
|
|
$this->Helper->setEntity('5.id');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, '5');
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->assertEqual($this->View->entity(), array('HelperTestPost', 5, 'id'));
|
|
|
|
|
|
|
|
$this->Helper->setEntity('0.id');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, '0');
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->assertEqual($this->View->entity(), array('HelperTestPost', 0, 'id'));
|
|
|
|
|
|
|
|
$this->Helper->setEntity('5.created.month');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'created');
|
|
|
|
$this->assertEqual($this->View->modelId, '5');
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, 'month');
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.5.id');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, '5');
|
|
|
|
$this->assertEqual($this->View->association, 'HelperTestComment');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestComment.id.time');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, 'HelperTestComment');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, 'time');
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestTag');
|
|
|
|
$this->assertTrue($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->modelId, '');
|
|
|
|
$this->assertEqual($this->View->association, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, '');
|
|
|
|
|
|
|
|
$this->Helper->setEntity(null);
|
|
|
|
$this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist');
|
|
|
|
$this->assertFalse($this->View->modelScope);
|
|
|
|
$this->assertEqual($this->View->model, 'ModelThatDoesntExist');
|
|
|
|
$this->assertEqual($this->View->field, 'field_that_doesnt_exist');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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');
|
|
|
|
|
2010-05-14 04:05:45 +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');
|
|
|
|
|
2010-05-14 04:05:45 +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');
|
|
|
|
|
2010-05-14 04:05:45 +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'));
|
|
|
|
|
2010-05-14 04:05:45 +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');
|
2009-11-10 02:00:19 +00:00
|
|
|
|
2010-05-14 04:05:45 +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, '');
|
|
|
|
|
2010-05-14 04:05:45 +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
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data = array('zero' => 0);
|
2010-03-10 19:46:02 +00:00
|
|
|
$this->Helper->setEntity('zero');
|
|
|
|
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
|
|
|
$this->assertEqual($result, array('value' => 0));
|
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
$this->Helper->request->data = array('zero' => '0');
|
2010-03-10 19:46:02 +00:00
|
|
|
$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'));
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFieldsWithSameName() {
|
2008-05-30 11:40:08 +00:00
|
|
|
// PHP4 reference hack
|
|
|
|
ClassRegistry::removeObject('view');
|
|
|
|
ClassRegistry::addObject('view', $this->View);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestTag', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestTag.id');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('My.id');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, 'My');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('MyOther.id');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field, 'id');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, 'MyOther');
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFieldSameAsModel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
// PHP4 reference hack
|
|
|
|
ClassRegistry::removeObject('view');
|
|
|
|
ClassRegistry::addObject('view', $this->View);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestTag', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('helper_test_post');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field, 'helper_test_post');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
2010-09-26 04:46:51 +00:00
|
|
|
$this->Helper->setEntity('HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field, 'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
$this->assertEqual($this->View->entityPath, 'HelperTestTag');
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFieldSuffixForDate() {
|
2008-05-30 11:40:08 +00:00
|
|
|
// PHP4 reference hack
|
|
|
|
ClassRegistry::removeObject('view');
|
|
|
|
ClassRegistry::addObject('view', $this->View);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, null);
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('date.month');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->field, 'date');
|
|
|
|
$this->assertEqual($this->View->modelId, null);
|
|
|
|
$this->assertEqual($this->View->association, null);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix, 'month');
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMulitDimensionValue() {
|
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;
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Helper->value('0.id');
|
|
|
|
$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
|
|
|
* @access public
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultiDimensionalField() {
|
2009-10-22 04:24:54 +00:00
|
|
|
// PHP4 reference hack
|
|
|
|
ClassRegistry::removeObject('view');
|
|
|
|
ClassRegistry::addObject('view', $this->View);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost', true);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost.2.HelperTestComment.1.title');
|
|
|
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->association, 'HelperTestComment');
|
|
|
|
$this->assertEqual($this->View->modelId,2);
|
|
|
|
$this->assertEqual($this->View->field, 'title');
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.HelperTestTag.1.created');
|
|
|
|
$this->assertEqual($this->View->field,'created');
|
|
|
|
$this->assertEqual($this->View->association,'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->modelId,1);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('HelperTestPost.0.HelperTestComment.1.HelperTestTag.1.fake');
|
|
|
|
$this->assertEqual($this->View->model,'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->association,'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field,null);
|
|
|
|
|
|
|
|
$this->Helper->setEntity('1.HelperTestComment.1.HelperTestTag.created.year');
|
|
|
|
$this->assertEqual($this->View->model,'HelperTestPost');
|
|
|
|
$this->assertEqual($this->View->association,'HelperTestTag');
|
|
|
|
$this->assertEqual($this->View->field,'created');
|
|
|
|
$this->assertEqual($this->View->modelId,1);
|
|
|
|
$this->assertEqual($this->View->fieldSuffix,'year');
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result,'My Title');
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result,2008);
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result,2008);
|
|
|
|
|
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');
|
|
|
|
$this->assertEqual($result,'My Title');
|
|
|
|
|
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
|
|
|
}
|