mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding test to showcase notice when create has no ID and security component is used
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5718 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
84f8c78e05
commit
556ae6c161
1 changed files with 52 additions and 28 deletions
|
@ -38,14 +38,12 @@ uses(
|
|||
'view'.DS.'helpers'.DS.'form'
|
||||
);
|
||||
|
||||
|
||||
class ContactTestController extends Controller {
|
||||
var $name = 'ContactTest';
|
||||
var $uses = null;
|
||||
}
|
||||
|
||||
class Contact extends Model {
|
||||
|
||||
var $primaryKey = 'id';
|
||||
var $useTable = false;
|
||||
var $name = 'Contact';
|
||||
|
@ -196,7 +194,33 @@ class FormHelperTest extends CakeTestCase {
|
|||
unset($this->View);
|
||||
}
|
||||
|
||||
function testFormValidationAssociated() {
|
||||
function testFormCreateWithSecurity() {
|
||||
$this->Form->params['_Token'] = array('key' => 'testKey');
|
||||
|
||||
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
|
||||
$this->assertPattern('/^<form[^<>]+id="MyForm"[^<>]*>.+$/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+method="post"[^<>]*>.+$/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+action="[^"]+"[^<>]*>.+$/', $result);
|
||||
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+type="hidden"[^<>]*\/>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+name="data\[__Token\]\[key\]"[^<>]*\/>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+value="testKey"[^<>]*\/>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+id="\w+"[^<>]*\/>/', $result);
|
||||
$this->assertNoPattern('/<input[^<>]+[^type|name|value|id]=[^<>]*>/', $result);
|
||||
|
||||
$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
|
||||
$this->assertPattern('/^<form[^<>]+id="MyForm"[^<>]*>.+$/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+method="post"[^<>]*>.+$/', $result);
|
||||
$this->assertPattern('/^<form[^<>]+action="[^"]+"[^<>]*>.+$/', $result);
|
||||
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+type="hidden"[^<>]*\/>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+name="data\[__Token\]\[key\]"[^<>]*\/>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+value="testKey"[^<>]*\/>/', $result);
|
||||
$this->assertPattern('/<input[^<>]+id="\w+"[^<>]*\/>/', $result);
|
||||
$this->assertNoPattern('/<input[^<>]+[^type|name|value|id]=[^<>]*>/', $result);
|
||||
}
|
||||
|
||||
function _testFormValidationAssociated() {
|
||||
$this->UserForm =& ClassRegistry::getObject('UserForm');
|
||||
$this->UserForm->OpenidUrl =& ClassRegistry::getObject('OpenidUrl');
|
||||
|
||||
|
@ -221,7 +245,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
unset($this->UserForm);
|
||||
}
|
||||
|
||||
function testFormValidationAssociatedFirstLevel() {
|
||||
function _testFormValidationAssociatedFirstLevel() {
|
||||
$this->ValidateUser =& ClassRegistry::getObject('ValidateUser');
|
||||
$this->ValidateUser->ValidateProfile =& ClassRegistry::getObject('ValidateProfile');
|
||||
|
||||
|
@ -245,7 +269,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
unset($this->ValidateUser);
|
||||
}
|
||||
|
||||
function testFormValidationAssociatedSecondLevel() {
|
||||
function _testFormValidationAssociatedSecondLevel() {
|
||||
$this->ValidateUser =& ClassRegistry::getObject('ValidateUser');
|
||||
$this->ValidateUser->ValidateProfile =& ClassRegistry::getObject('ValidateProfile');
|
||||
$this->ValidateUser->ValidateProfile->ValidateItem =& ClassRegistry::getObject('ValidateItem');
|
||||
|
@ -276,7 +300,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
unset($this->ValidateUser);
|
||||
}
|
||||
|
||||
function testFormInput() {
|
||||
function _testFormInput() {
|
||||
$result = $this->Form->input('Model.field', array('type' => 'text'));
|
||||
$expected = '<div class="input"><label for="ModelField">Field</label><input name="data[Model][field]" type="text" value="" id="ModelField" /></div>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -338,7 +362,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/error-message/', $result);
|
||||
}
|
||||
|
||||
function testLabel() {
|
||||
function _testLabel() {
|
||||
$this->Form->text('Person/name');
|
||||
$result = $this->Form->label();
|
||||
$this->assertEqual($result, '<label for="PersonName">Name</label>');
|
||||
|
@ -367,7 +391,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, '<label for="PersonFirstName"></label>');
|
||||
}
|
||||
|
||||
function testTextbox() {
|
||||
function _testTextbox() {
|
||||
$result = $this->Form->text('Model.field');
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input[^<>]+type="text"[^<>]+\/>$/', $result);
|
||||
|
@ -397,7 +421,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
|
||||
}
|
||||
|
||||
function testDefaultValue() {
|
||||
function _testDefaultValue() {
|
||||
$this->Form->data['Model']['field'] = 'test';
|
||||
$result = $this->Form->text('Model.field', array('default' => 'default value'));
|
||||
$this->assertPattern('/^<input[^<>]+value="test"[^<>]+\/>$/', $result);
|
||||
|
@ -407,7 +431,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/^<input[^<>]+value="default value"[^<>]+\/>$/', $result);
|
||||
}
|
||||
|
||||
function testFieldError() {
|
||||
function _testFieldError() {
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$result = $this->Form->error('Model.field');
|
||||
$this->assertEqual($result, '<div class="error-message">Error in field Field</div>');
|
||||
|
@ -429,7 +453,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, '<strong>Badness!</strong>');
|
||||
}
|
||||
|
||||
function testPassword() {
|
||||
function _testPassword() {
|
||||
$result = $this->Form->password('Model.field');
|
||||
$expected = '<input name="data[Model][field]" type="password" value="" id="ModelField" />';
|
||||
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/', $result);
|
||||
|
@ -448,7 +472,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
|
||||
}
|
||||
|
||||
function testRadio() {
|
||||
function _testRadio() {
|
||||
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
|
||||
$this->assertPattern('/id="Field0"/', $result);
|
||||
$this->assertPattern('/id="Field1"/', $result);
|
||||
|
@ -464,7 +488,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/id="Field0".*checked="checked"/', $result);
|
||||
}
|
||||
|
||||
function testSelect() {
|
||||
function _testSelect() {
|
||||
$result = $this->Form->select('Model.field', array());
|
||||
$this->assertPattern('/^<select [^<>]+>\n<option [^<>]+>/', $result);
|
||||
$this->assertPattern('/<option value=""><\/option>/', $result);
|
||||
|
@ -512,7 +536,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$result);
|
||||
}
|
||||
|
||||
function testSelectMultiple() {
|
||||
function _testSelectMultiple() {
|
||||
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => true));
|
||||
$this->assertPattern('/^<select[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>\/]*>/', $result);
|
||||
$this->assertPattern('/^<select[^<>]+id="ModelMultiField"[^<>\/]*>/', $result);
|
||||
|
@ -538,7 +562,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/<option[^<>]+value="[^012]"[^<>\/]*>/', $result);
|
||||
}
|
||||
|
||||
function testCheckbox() {
|
||||
function _testCheckbox() {
|
||||
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
|
||||
|
||||
$this->assertPattern('/^<input[^<>]+type="hidden"[^<>]+\/><input[^<>]+type="checkbox"[^<>]+\/>$/', $result);
|
||||
|
@ -605,7 +629,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, '<input type="hidden" name="data[Contact][published]" value="0" id="theID_" /><input type="checkbox" name="data[Contact][published]" id="theID" value="1" />');
|
||||
}
|
||||
|
||||
function testMonth() {
|
||||
function _testMonth() {
|
||||
$result = $this->Form->month('Model.field');
|
||||
$this->assertPattern('/' .
|
||||
'<option\s+value="01"[^>]*>January<\/option>\s+'.
|
||||
|
@ -613,7 +637,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/i', $result);
|
||||
}
|
||||
|
||||
function testDay() {
|
||||
function _testDay() {
|
||||
$result = $this->Form->day('Model.field', false);
|
||||
$this->assertPattern('/option value="12"/', $result);
|
||||
$this->assertPattern('/option value="13"/', $result);
|
||||
|
@ -636,7 +660,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
}
|
||||
|
||||
function testHour() {
|
||||
function _testHour() {
|
||||
$result = $this->Form->hour('Model.field', false);
|
||||
$this->assertPattern('/option value="12"/', $result);
|
||||
$this->assertNoPattern('/option value="13"/', $result);
|
||||
|
@ -658,7 +682,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/option value="24"/', $result);
|
||||
}
|
||||
|
||||
function testYear() {
|
||||
function _testYear() {
|
||||
|
||||
$result = $this->Form->year('Model.field', 2006, 2007);
|
||||
$this->assertPattern('/option value="2006"/', $result);
|
||||
|
@ -708,7 +732,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
}
|
||||
|
||||
function testTextArea() {
|
||||
function _testTextArea() {
|
||||
$this->Form->data = array('Model' => array('field' => 'some test data'));
|
||||
$result = $this->Form->textarea('Model.field');
|
||||
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]+id="ModelField"/', $result);
|
||||
|
@ -721,7 +745,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[tmp\]"[^<>]+><\/textarea>/', $result);
|
||||
}
|
||||
|
||||
function testHiddenField() {
|
||||
function _testHiddenField() {
|
||||
$this->Form->validationErrors['Model']['field'] = 1;
|
||||
$this->Form->data['Model']['field'] = 'test';
|
||||
$result = $this->Form->hidden('Model.field', array('id' => 'theID'));
|
||||
|
@ -731,7 +755,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
|
||||
}
|
||||
|
||||
function testFileUploadField() {
|
||||
function _testFileUploadField() {
|
||||
$result = $this->Form->file('Model.upload');
|
||||
$this->assertPattern('/^<input type="file"[^<>]+name="data\[Model\]\[upload\]"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input type="file"[^<>]+value=""[^<>]+\/>$/', $result);
|
||||
|
@ -740,7 +764,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/<input[^<>]+[^type|name|value|id]=[^<>]*>$/', $result);
|
||||
}
|
||||
|
||||
function testSubmitButton() {
|
||||
function _testSubmitButton() {
|
||||
$result = $this->Form->submit('Test Submit');
|
||||
$this->assertPattern('/^<div\s+class="submit"><input type="submit"[^<>]+value="Test Submit"[^<>]+\/><\/div>$/', $result);
|
||||
|
||||
|
@ -760,7 +784,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/^<div\s+class="submit"><input type="submit"[^<>]+value="Next >"[^<>]+\/><\/div>$/', $result);
|
||||
}
|
||||
|
||||
function testFormCreate() {
|
||||
function _testFormCreate() {
|
||||
$result = $this->Form->create('Contact');
|
||||
$this->assertPattern('/^<form [^<>]+>/', $result);
|
||||
$this->assertPattern('/\s+id="ContactAddForm"/', $result);
|
||||
|
@ -794,7 +818,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertPattern('/action="\/users\/login[\/]"/', $result);
|
||||
}
|
||||
|
||||
function testFormMagicInput() {
|
||||
function _testFormMagicInput() {
|
||||
$result = $this->Form->create('Contact');
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*>$/', $result);
|
||||
$this->assertNoPattern('/^<form[^<>]+[^id|method|action]=[^<>]*>/', $result);
|
||||
|
@ -848,7 +872,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'<select name="data\[Contact\]\[updated_month\]"\s+id="ContactUpdatedMonth">/', $result);
|
||||
}
|
||||
|
||||
function testFormMagicInputLabel() {
|
||||
function _testFormMagicInputLabel() {
|
||||
$result = $this->Form->create('Contact');
|
||||
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*>$/', $result);
|
||||
|
||||
|
@ -882,14 +906,14 @@ class FormHelperTest extends CakeTestCase {
|
|||
'<input name="data\[Contact\]\[name\]" type="text" id="my_id" maxlength="255" value="" \/>$/', $result);
|
||||
}
|
||||
|
||||
function testSetFormTag() {
|
||||
function _testSetFormTag() {
|
||||
$controller = null;
|
||||
new View($controller);
|
||||
|
||||
$this->Form->setFormTag('Model.field');
|
||||
}
|
||||
|
||||
function testFormEnd() {
|
||||
function _testFormEnd() {
|
||||
$this->assertEqual($this->Form->end(), '</form>');
|
||||
|
||||
$result = $this->Form->end('save');
|
||||
|
|
Loading…
Reference in a new issue