Skip to content

Commit

Permalink
Unskip more tests related to secured forms.
Browse files Browse the repository at this point in the history
These tests all pass with minimal changes. Favour text() over input() as
it is simpler and runs faster.
  • Loading branch information
markstory committed Feb 25, 2014
1 parent 94fe78b commit 85ccc83
Showing 1 changed file with 48 additions and 59 deletions.
107 changes: 48 additions & 59 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -1526,15 +1526,13 @@ public function testFormSecurityMultipleInputFields() {
* @return void
*/
public function testFormSecurityArrayFields() {
$this->markTestIncomplete('Need to revisit once models work again.');
$key = 'testKey';
$this->Form->request->params['_csrfToken'] = $key;
$this->Form->request->params['_Token'] = 'testKey';

$this->Form->create('Address');
$this->Form->input('Address.primary.1');
$this->Form->text('Address.primary.1');
$this->assertEquals('Address.primary', $this->Form->fields[0]);

$this->Form->input('Address.secondary.1.0');
$this->Form->text('Address.secondary.1.0');
$this->assertEquals('Address.secondary', $this->Form->fields[1]);
}

Expand All @@ -1546,41 +1544,40 @@ public function testFormSecurityArrayFields() {
* @return void
*/
public function testFormSecurityMultipleInputDisabledFields() {
$this->markTestIncomplete('Need to revisit once models work again.');
$key = 'testKey';
$this->Form->request->params['_csrfToken'] = $key;
$this->Form->request->params['_Token'] = array(
'unlockedFields' => array('first_name', 'address')
);
$this->Form->create();

$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
$this->Form->input('Addresses.0.title');
$this->Form->input('Addresses.0.first_name');
$this->Form->input('Addresses.0.last_name');
$this->Form->input('Addresses.0.address');
$this->Form->input('Addresses.0.city');
$this->Form->input('Addresses.0.phone');
$this->Form->text('Addresses.0.title');
$this->Form->text('Addresses.0.first_name');
$this->Form->text('Addresses.0.last_name');
$this->Form->text('Addresses.0.address');
$this->Form->text('Addresses.0.city');
$this->Form->text('Addresses.0.phone');
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
$this->Form->input('Addresses.1.title');
$this->Form->input('Addresses.1.first_name');
$this->Form->input('Addresses.1.last_name');
$this->Form->input('Addresses.1.address');
$this->Form->input('Addresses.1.city');
$this->Form->input('Addresses.1.phone');
$this->Form->text('Addresses.1.title');
$this->Form->text('Addresses.1.first_name');
$this->Form->text('Addresses.1.last_name');
$this->Form->text('Addresses.1.address');
$this->Form->text('Addresses.1.city');
$this->Form->text('Addresses.1.phone');

$result = $this->Form->secure($this->Form->fields);
$hash = '629b6536dcece48aa41a117045628ce602ccbbb2%3AAddresses.0.id%7CAddresses.1.id';

$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => '_Token[fields]',
'type' => 'hidden',
'name' => '_Token[fields]',
'value' => $hash
)),
array('input' => array(
'type' => 'hidden', 'name' => '_Token[unlocked]',
'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
'type' => 'hidden',
'name' => '_Token[unlocked]',
'value' => 'address%7Cfirst_name',
)),
'/div'
);
Expand All @@ -1595,22 +1592,19 @@ public function testFormSecurityMultipleInputDisabledFields() {
* @return void
*/
public function testFormSecurityInputUnlockedFields() {
$this->markTestIncomplete('Need to revisit once models work again.');
$key = 'testKey';
$this->Form->request->params['_csrfToken'] = $key;
$this->Form->request['_Token'] = array(
'unlockedFields' => array('first_name', 'address')
);
$this->Form->create();
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());

$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name');
$this->Form->input('Addresses.last_name');
$this->Form->input('Addresses.address');
$this->Form->input('Addresses.city');
$this->Form->input('Addresses.phone');
$this->Form->text('Addresses.title');
$this->Form->text('Addresses.first_name');
$this->Form->text('Addresses.last_name');
$this->Form->text('Addresses.address');
$this->Form->text('Addresses.city');
$this->Form->text('Addresses.phone');

$result = $this->Form->fields;
$expected = array(
Expand All @@ -1625,12 +1619,14 @@ public function testFormSecurityInputUnlockedFields() {
$expected = array(
'div' => array('style' => 'display:none;'),
array('input' => array(
'type' => 'hidden', 'name' => '_Token[fields]',
'type' => 'hidden',
'name' => '_Token[fields]',
'value' => $hash
)),
array('input' => array(
'type' => 'hidden', 'name' => '_Token[unlocked]',
'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
'type' => 'hidden',
'name' => '_Token[unlocked]',
'value' => 'address%7Cfirst_name',
)),
'/div'
);
Expand Down Expand Up @@ -1791,22 +1787,19 @@ public function testFormSecuredInput() {
* @return void
*/
public function testSecuredInputCustomName() {
$this->markTestIncomplete('Need to revisit once models work again.');
$this->Form->request->params['_csrfToken'] = 'testKey';
$this->Form->request->params['_Token'] = 'testKey';
$this->assertEquals(array(), $this->Form->fields);

$this->Form->input('text_input', array(
'name' => 'data[Option][General.default_role]',
$this->Form->text('text_input', array(
'name' => 'Option[General.default_role]',
));
$expected = array('Option.General.default_role');
$this->assertEquals($expected, $this->Form->fields);

$this->Form->input('select_box', array(
'name' => 'data[Option][General.select_role]',
'type' => 'select',
'options' => array(1, 2),
));
$expected = array('Option.General.default_role', 'Option.General.select_role');
$this->Form->select('select_box', [1, 2], [
'name' => 'Option[General.select_role]',
]);
$expected = ['Option.General.default_role', 'Option.General.select_role'];
$this->assertEquals($expected, $this->Form->fields);
}

Expand Down Expand Up @@ -1917,25 +1910,21 @@ public function testFormSecuredAndDisabled() {
* @return void
*/
public function testDisableSecurityUsingForm() {
$this->markTestIncomplete('Need to revisit once models work again.');
$this->Form->request->params['_csrfToken'] = 'testKey';
$this->Form->request['_Token'] = array(
'disabledFields' => array()
);
$this->Form->request['_Token'] = [
'disabledFields' => []
];
$this->Form->create();

$this->Form->hidden('Addresses.id', array('value' => '123456'));
$this->Form->input('Addresses.title');
$this->Form->input('Addresses.first_name', array('secure' => false));
$this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
$this->Form->input('Addresses.zip', array(
'type' => 'select', 'options' => array(1, 2), 'secure' => false
));
$this->Form->hidden('Addresses.id', ['value' => '123456']);
$this->Form->text('Addresses.title');
$this->Form->text('Addresses.first_name', ['secure' => false]);
$this->Form->textarea('Addresses.city', ['secure' => false]);
$this->Form->select('Addresses.zip', [1, 2], ['secure' => false]);

$result = $this->Form->fields;
$expected = array(
$expected = [
'Addresses.id' => '123456', 'Addresses.title',
);
];
$this->assertEquals($expected, $result);
}

Expand Down

0 comments on commit 85ccc83

Please sign in to comment.