Updating FormHelper tests to use CakeRequest.

This commit is contained in:
Mark Story 2010-05-03 23:39:43 -04:00
parent 69275c8996
commit c5fdeec7a1

View file

@ -17,7 +17,7 @@
* @since CakePHP(tm) v 1.2.0.4206 * @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
App::import('Core', array('ClassRegistry', 'Controller', 'View', 'Model', 'Security')); App::import('Core', array('ClassRegistry', 'Controller', 'View', 'Model', 'Security', 'CakeRequest'));
App::import('Helper', 'Html'); App::import('Helper', 'Html');
App::import('Helper', 'Form'); App::import('Helper', 'Form');
@ -671,10 +671,11 @@ class FormHelperTest extends CakeTestCase {
parent::setUp(); parent::setUp();
Router::reload(); Router::reload();
$this->Form =& new FormHelper(); $this->Form = new FormHelper();
$this->Form->Html =& new HtmlHelper(); $this->Form->Html = new HtmlHelper();
$this->Controller =& new ContactTestController(); $this->Controller = new ContactTestController();
$this->View =& new View($this->Controller); $this->View = new View($this->Controller);
$this->Form->params = new CakeRequest(null, false);
$this->Form->params['action'] = 'add'; $this->Form->params['action'] = 'add';
ClassRegistry::addObject('view', $view); ClassRegistry::addObject('view', $view);
@ -816,7 +817,8 @@ class FormHelperTest extends CakeTestCase {
function testFormSecurityFields() { function testFormSecurityFields() {
$key = 'testKey'; $key = 'testKey';
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0'); $fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
$this->Form->params['_Token']['key'] = $key;
$this->Form->params['_Token'] = array('key' => $key);
$result = $this->Form->secure($fields); $result = $this->Form->secure($fields);
$expected = Security::hash(serialize($fields) . Configure::read('Security.salt')); $expected = Security::hash(serialize($fields) . Configure::read('Security.salt'));
@ -879,7 +881,7 @@ class FormHelperTest extends CakeTestCase {
'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username', 'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
'Model.1.hidden' => 'value', 'Model.1.valid' => '0' 'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
); );
$this->Form->params['_Token']['key'] = $key; $this->Form->params['_Token'] = array('key' => $key);
$result = $this->Form->secure($fields); $result = $this->Form->secure($fields);
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3An%3A4%3A%7Bv%3A0%3Bf%3A14%3A%22Zbqry.'; $hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3An%3A4%3A%7Bv%3A0%3Bf%3A14%3A%22Zbqry.';
@ -906,7 +908,7 @@ class FormHelperTest extends CakeTestCase {
*/ */
function testFormSecurityMultipleSubmitButtons() { function testFormSecurityMultipleSubmitButtons() {
$key = 'testKey'; $key = 'testKey';
$this->Form->params['_Token']['key'] = $key; $this->Form->params['_Token'] = array('key' => $key);
$this->Form->create('Addresses'); $this->Form->create('Addresses');
$this->Form->input('Address.title'); $this->Form->input('Address.title');
@ -950,7 +952,7 @@ class FormHelperTest extends CakeTestCase {
function testFormSecurityMultipleInputFields() { function testFormSecurityMultipleInputFields() {
$key = 'testKey'; $key = 'testKey';
$this->Form->params['_Token']['key'] = $key; $this->Form->params['_Token'] = array('key' => $key);
$this->Form->create('Addresses'); $this->Form->create('Addresses');
$this->Form->hidden('Addresses.0.id', array('value' => '123456')); $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
@ -997,8 +999,10 @@ class FormHelperTest extends CakeTestCase {
*/ */
function testFormSecurityMultipleInputDisabledFields() { function testFormSecurityMultipleInputDisabledFields() {
$key = 'testKey'; $key = 'testKey';
$this->Form->params['_Token']['key'] = $key; $this->Form->params['_Token'] = array(
$this->Form->params['_Token']['disabledFields'] = array('first_name', 'address'); 'key' => $key,
'disabledFields' => array('first_name', 'address')
);
$this->Form->create(); $this->Form->create();
$this->Form->hidden('Addresses.0.id', array('value' => '123456')); $this->Form->hidden('Addresses.0.id', array('value' => '123456'));
@ -1041,8 +1045,10 @@ class FormHelperTest extends CakeTestCase {
*/ */
function testFormSecurityInputDisabledFields() { function testFormSecurityInputDisabledFields() {
$key = 'testKey'; $key = 'testKey';
$this->Form->params['_Token']['key'] = $key; $this->Form->params['_Token'] = array(
$this->Form->params['_Token']['disabledFields'] = array('first_name', 'address'); 'key' => $key,
'disabledFields' => array('first_name', 'address')
);
$this->Form->create(); $this->Form->create();
$this->Form->hidden('Addresses.id', array('value' => '123456')); $this->Form->hidden('Addresses.id', array('value' => '123456'));
@ -1084,7 +1090,7 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testFormSecuredInput() { function testFormSecuredInput() {
$this->Form->params['_Token']['key'] = 'testKey'; $this->Form->params['_Token'] = array('key' => 'testKey');
$result = $this->Form->create('Contact', array('url' => '/contacts/add')); $result = $this->Form->create('Contact', array('url' => '/contacts/add'));
$encoding = strtolower(Configure::read('App.encoding')); $encoding = strtolower(Configure::read('App.encoding'));
@ -1189,7 +1195,7 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testFormSecuredFileInput() { function testFormSecuredFileInput() {
$this->Form->params['_Token']['key'] = 'testKey'; $this->Form->params['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array()); $this->assertEqual($this->Form->fields, array());
$result = $this->Form->file('Attachment.file'); $result = $this->Form->file('Attachment.file');
@ -1207,7 +1213,7 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testFormSecuredMultipleSelect() { function testFormSecuredMultipleSelect() {
$this->Form->params['_Token']['key'] = 'testKey'; $this->Form->params['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array()); $this->assertEqual($this->Form->fields, array());
$options = array('1' => 'one', '2' => 'two'); $options = array('1' => 'one', '2' => 'two');
@ -1227,7 +1233,7 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testFormSecuredRadio() { function testFormSecuredRadio() {
$this->Form->params['_Token']['key'] = 'testKey'; $this->Form->params['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array()); $this->assertEqual($this->Form->fields, array());
$options = array('1' => 'option1', '2' => 'option2'); $options = array('1' => 'option1', '2' => 'option2');
@ -1243,8 +1249,10 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testDisableSecurityUsingForm() { function testDisableSecurityUsingForm() {
$this->Form->params['_Token']['key'] = 'testKey'; $this->Form->params['_Token'] = array(
$this->Form->params['_Token']['disabledFields'] = array(); 'key' => 'testKey',
'disabledFields' => array()
);
$this->Form->create(); $this->Form->create();
$this->Form->hidden('Addresses.id', array('value' => '123456')); $this->Form->hidden('Addresses.id', array('value' => '123456'));
@ -3340,7 +3348,7 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testSelectMultipleCheckboxSecurity() { function testSelectMultipleCheckboxSecurity() {
$this->Form->params['_Token']['key'] = 'testKey'; $this->Form->params['_Token'] = array('key' => 'testKey');
$this->assertEqual($this->Form->fields, array()); $this->assertEqual($this->Form->fields, array());
$result = $this->Form->select( $result = $this->Form->select(