code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function testError() { $this->Form->validationErrors['Model']['field'] = 1; $result = $this->Form->error('Model.field'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div')); $result = $this->Form->error('Model.field', null, array('wrap' => false)); $this->assertEqual($result, 'Error in field Field'); $this->Form->validationErrors['Model']['field'] = "This field contains invalid input"; $result = $this->Form->error('Model.field', null, array('wrap' => false)); $this->assertEqual($result, 'This field contains invalid input'); $this->Form->validationErrors['Model']['field'] = "This field contains invalid input"; $result = $this->Form->error('Model.field', null, array('wrap' => 'span')); $this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span')); $result = $this->Form->error('Model.field', 'There is an error fool!', array('wrap' => 'span')); $this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span')); $result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false)); $this->assertEqual($result, '&lt;strong&gt;Badness!&lt;/strong&gt;'); $result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true)); $this->assertEqual($result, '&lt;strong&gt;Badness!&lt;/strong&gt;'); $result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false)); $this->assertEqual($result, '<strong>Badness!</strong>'); $this->Form->validationErrors['Model']['field'] = "email"; $result = $this->Form->error('Model.field', array('class' => 'field-error', 'email' => 'No good!')); $expected = array( 'div' => array('class' => 'field-error'), 'No good!', '/div' ); $this->assertTags($result, $expected); }
testError method Test field error generation @access public @return void
testError
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testInputErrorEscape() { $this->Form->create('ValidateProfile'); $this->Form->validationErrors['ValidateProfile']['city'] = 'required<br>'; $result = $this->Form->input('city',array('error' => array('escape' => true))); $this->assertPattern('/required&lt;br&gt;/', $result); $result = $this->Form->input('city',array('error' => array('escape' => false))); $this->assertPattern('/required<br>/', $result); }
test error options when using form->input(); @return void
testInputErrorEscape
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testPassword() { $result = $this->Form->password('Model.field'); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField'))); $this->Form->validationErrors['Model']['passwd'] = 1; $this->Form->data['Model']['passwd'] = 'test'; $result = $this->Form->password('Model.passwd', array('id' => 'theID')); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error'))); }
testPassword method Test password element generation @access public @return void
testPassword
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testRadio() { $result = $this->Form->radio('Model.field', array('option A')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), 'label' => array('for' => 'ModelField0'), 'option A', '/label' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1/2' => 'half')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')), 'label' => array('for' => 'ModelField12'), 'half', '/label' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('option A', 'option B')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'option A', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'option B', '/label', '/fieldset' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'option A', '/label', 'br' => array(), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'option B', '/label', '/fieldset' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'checked' => 'checked')), array('label' => array('for' => 'ModelField1')), 'Yes', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'No', '/label', '/fieldset' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'Yes', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')), array('label' => array('for' => 'ModelField0')), 'No', '/label', '/fieldset' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null)); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'Yes', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'No', '/label', '/fieldset' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'Yes', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'No', '/label', '/fieldset' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('field' => '')); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'Yes', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'No', '/label', '/fieldset' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'fieldset' => array(), 'legend' => array(), 'Legend title', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), array('label' => array('for' => 'NewsletterSubscribe0')), 'Unsubscribe', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), array('label' => array('for' => 'NewsletterSubscribe1')), 'Subscribe', '/label', '/fieldset', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), array('label' => array('for' => 'NewsletterSubscribe0')), 'Unsubscribe', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), array('label' => array('for' => 'NewsletterSubscribe1')), 'Subscribe', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'fieldset' => array(), 'legend' => array(), 'Legend title', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), 'Unsubscribe', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), 'Subscribe', '/fieldset', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), 'Unsubscribe', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), 'Subscribe', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'value' => '1', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), 'Unsubscribe', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1', 'checked' => 'checked')), 'Subscribe', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Gender', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'), array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')), array('label' => array('for' => 'EmployeeGenderMale')), 'Male', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')), array('label' => array('for' => 'EmployeeGenderFemale')), 'Female', '/label', '/fieldset', ); $this->assertTags($result, $expected); $result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Gender', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Officer][gender]', 'value' => '', 'id' => 'OfficerGender_'), array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'male', 'id' => 'OfficerGenderMale')), array('label' => array('for' => 'OfficerGenderMale')), 'Male', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'female', 'id' => 'OfficerGenderFemale')), array('label' => array('for' => 'OfficerGenderFemale')), 'Female', '/label', '/fieldset', ); $this->assertTags($result, $expected); $result = $this->Form->radio('Contact.1.imrequired', array('option A')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][1][imrequired]', 'value' => '', 'id' => 'Contact1Imrequired_'), array('input' => array('type' => 'radio', 'name' => 'data[Contact][1][imrequired]', 'value' => '0', 'id' => 'Contact1Imrequired0')), 'label' => array('for' => 'Contact1Imrequired0'), 'option A', '/label' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.1.field', array('option A')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')), 'label' => array('for' => 'Model1Field0'), 'option A', '/label' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Model][custom]', 'value' => '', 'id' => 'ModelField_'), array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '0', 'id' => 'ModelField0')), array('label' => array('for' => 'ModelField0')), 'option A', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '1', 'id' => 'ModelField1')), array('label' => array('for' => 'ModelField1')), 'option B', '/label', '/fieldset' ); $this->assertTags($result, $expected); }
testRadio method Test radio element set generation @access public @return void
testRadio
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testRadioHiddenInputDisabling() { $result = $this->Form->input('Model.1.field', array( 'type' => 'radio', 'options' => array('option A'), 'hiddenField' => false ) ); $expected = array( 'div' => array('class' => 'input radio'), 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), 'label' => array('for' => 'Model1Field0'), 'option A', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false)); $expected = array( 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), 'label' => array('for' => 'Model1Field0'), 'option A', '/label' ); $this->assertTags($result, $expected); }
test disabling the hidden input for radio buttons @return void
testRadioHiddenInputDisabling
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelect() { $result = $this->Form->select('Model.field', array()); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => '')), '/option', '/select' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('field' => 'value')); $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad')); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => '')), '/option', array('option' => array('value' => 'value', 'selected' => 'selected')), 'good', '/option', array('option' => array('value' => 'other')), 'bad', '/option', '/select' ); $this->assertTags($result, $expected); $this->Form->data = array(); $result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad')); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => '')), '/option', array('option' => array('value' => 'value')), 'good', '/option', array('option' => array('value' => 'other')), 'bad', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array('empty' => false) ); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => 'first')), 'first &quot;html&quot; &lt;chars&gt;', '/option', array('option' => array('value' => 'second')), 'value', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array('escape' => false, 'empty' => false) ); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => 'first')), 'first "html" <chars>', '/option', array('option' => array('value' => 'second')), 'value', '/option', '/select' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('contact_id' => 228)); $result = $this->Form->select( 'Model.contact_id', array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'), null, array('escape' => false, 'empty' => 'pick something') ); $expected = array( 'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'), array('option' => array('value' => '')), 'pick something', '/option', array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option', array('option' => array('value' => '228-1')), '228-1 value', '/option', array('option' => array('value' => '228-2')), '228-2 value', '/option', '/select' ); $this->assertTags($result, $expected); }
testSelect method Test select element generation. @access public @return void
testSelect
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectOptionGroupEscaping() { $options = array( '>< Key' => array( 1 => 'One', 2 => 'Two' ) ); $result = $this->Form->select('Model.field', $options, null, array('empty' => false)); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), 'optgroup' => array('label' => '&gt;&lt; Key'), array('option' => array('value' => '1')), 'One', '/option', array('option' => array('value' => '2')), 'Two', '/option', '/optgroup', '/select' ); $this->assertTags($result, $expected); $options = array( '>< Key' => array( 1 => 'One', 2 => 'Two' ) ); $result = $this->Form->select('Model.field', $options, null, array('empty' => false, 'escape' => false)); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), 'optgroup' => array('label' => '>< Key'), array('option' => array('value' => '1')), 'One', '/option', array('option' => array('value' => '2')), 'Two', '/option', '/optgroup', '/select' ); $this->assertTags($result, $expected); }
test that select() with optiongroups listens to the escape param. @return void
testSelectOptionGroupEscaping
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectWithNullAttributes() { $result = $this->Form->select('Model.field', array('first', 'second'), null, array('empty' => false)); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => '0')), 'first', '/option', array('option' => array('value' => '1')), 'second', '/option', '/select' ); $this->assertTags($result, $expected); }
Tests that FormHelper::select() allows null to be passed in the $attributes parameter @access public @return void
testSelectWithNullAttributes
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testNestedSelect() { $result = $this->Form->select( 'Model.field', array(1 => 'One', 2 => 'Two', 'Three' => array( 3 => 'Three', 4 => 'Four', 5 => 'Five' )), null, array('empty' => false) ); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => 1)), 'One', '/option', array('option' => array('value' => 2)), 'Two', '/option', array('optgroup' => array('label' => 'Three')), array('option' => array('value' => 4)), 'Four', '/option', array('option' => array('value' => 5)), 'Five', '/option', '/optgroup', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.field', array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')), null, array('showParents' => true, 'empty' => false) ); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => 1)), 'One', '/option', array('option' => array('value' => 2)), 'Two', '/option', array('optgroup' => array('label' => 'Three')), array('option' => array('value' => 3)), 'Three', '/option', array('option' => array('value' => 4)), 'Four', '/option', '/optgroup', '/select' ); $this->assertTags($result, $expected); }
testNestedSelect method test select element generation with optgroups @access public @return void
testNestedSelect
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectMultiple() { $options = array('first', 'second', 'third'); $result = $this->Form->select( 'Model.multi_field', $options, null, array('multiple' => true) ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_' ), 'select' => array( 'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField', 'multiple' => 'multiple' ), array('option' => array('value' => '0')), 'first', '/option', array('option' => array('value' => '1')), 'second', '/option', array('option' => array('value' => '2')), 'third', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.multi_field', $options, null, array('multiple' => 'multiple') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_' ), 'select' => array( 'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField', 'multiple' => 'multiple' ), array('option' => array('value' => '0')), 'first', '/option', array('option' => array('value' => '1')), 'second', '/option', array('option' => array('value' => '2')), 'third', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.multi_field', $options, array(0, 1), array('multiple' => true) ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_' ), 'select' => array( 'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField', 'multiple' => 'multiple' ), array('option' => array('value' => '0', 'selected' => 'selected')), 'first', '/option', array('option' => array('value' => '1', 'selected' => 'selected')), 'second', '/option', array('option' => array('value' => '2')), 'third', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.multi_field', $options, array(0, 1), array('multiple' => false) ); $expected = array( 'select' => array( 'name' => 'data[Model][multi_field]', 'id' => 'ModelMultiField' ), array('option' => array('value' => '0', 'selected' => 'selected')), 'first', '/option', array('option' => array('value' => '1', 'selected' => 'selected')), 'second', '/option', array('option' => array('value' => '2')), 'third', '/option', '/select' ); $this->assertTags($result, $expected); }
testSelectMultiple method test generation of multiple select elements @access public @return void
testSelectMultiple
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testHabtmSelectBox() { $view =& ClassRegistry::getObject('view'); $view->viewVars['contactTags'] = array( 1 => 'blue', 2 => 'red', 3 => 'green' ); $this->Form->data = array( 'Contact' => array(), 'ContactTag' => array( array( 'id' => 1, 'name' => 'blue' ), array( 'id' => 3, 'name' => 'green' ) ) ); $this->Form->create('Contact'); $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false)); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_' ), 'select' => array( 'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag', 'multiple' => 'multiple' ), array('option' => array('value' => '1', 'selected' => 'selected')), 'blue', '/option', array('option' => array('value' => '2')), 'red', '/option', array('option' => array('value' => '3', 'selected' => 'selected')), 'green', '/option', '/select' ); $this->assertTags($result, $expected); }
test generation of habtm select boxes. @return void
testHabtmSelectBox
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectMultipleCheckboxes() { $result = $this->Form->select( 'Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => 'checkbox') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField' ), array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0' )), array('label' => array('for' => 'ModelMultiField0')), 'first', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1' )), array('label' => array('for' => 'ModelMultiField1')), 'second', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2' )), array('label' => array('for' => 'ModelMultiField2')), 'third', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.multi_field', array('a' => 'first', 'b' => 'second', 'c' => 'third'), null, array('multiple' => 'checkbox') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField' ), array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA' )), array('label' => array('for' => 'ModelMultiFieldA')), 'first', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB' )), array('label' => array('for' => 'ModelMultiFieldB')), 'second', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC' )), array('label' => array('for' => 'ModelMultiFieldC')), 'third', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.multi_field', array('1' => 'first'), null, array('multiple' => 'checkbox') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField' ), array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1' )), array('label' => array('for' => 'ModelMultiField1')), 'first', '/label', '/div' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('tags' => array(1))); $result = $this->Form->select( 'Model.tags', array('1' => 'first', 'Array' => 'Array'), null, array('multiple' => 'checkbox') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags' ), array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked' )), array('label' => array('for' => 'ModelTags1', 'class' => 'selected')), 'first', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => 'Array', 'id' => 'ModelTagsArray' )), array('label' => array('for' => 'ModelTagsArray')), 'Array', '/label', '/div' ); $this->assertTags($result, $expected); }
test generation of multi select elements in checkbox format @access public @return void
testSelectMultipleCheckboxes
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectMultipleCheckboxDiv() { $result = $this->Form->select( 'Model.tags', array('first', 'second'), null, array('multiple' => 'checkbox', 'class' => 'my-class') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags' ), array('div' => array('class' => 'my-class')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0' )), array('label' => array('for' => 'ModelTags0')), 'first', '/label', '/div', array('div' => array('class' => 'my-class')), array('input' => array( 'type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '1', 'id' => 'ModelTags1' )), array('label' => array('for' => 'ModelTags1')), 'second', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.tags', array( 'options' => array('first', 'second'), 'multiple' => 'checkbox', 'class' => 'my-class', 'div' => false, 'label' => false )); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['tags'] = 'Select atleast one option'; $result = $this->Form->input('Model.tags', array( 'options' => array('one'), 'multiple' => 'checkbox', 'label' => false, 'div' => false )); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'), array('div' => array('class' => 'checkbox form-error')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')), array('label' => array('for' => 'ModelTags0')), 'one', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.tags', array( 'options' => array('one'), 'multiple' => 'checkbox', 'class' => 'mycheckbox', 'label' => false, 'div' => false )); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'), array('div' => array('class' => 'mycheckbox form-error')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')), array('label' => array('for' => 'ModelTags0')), 'one', '/label', '/div' ); $this->assertTags($result, $expected); }
test multiple checkboxes with div styles. @return void
testSelectMultipleCheckboxDiv
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectMultipleCheckboxSecurity() { $this->Form->params['_Token']['key'] = 'testKey'; $this->assertEqual($this->Form->fields, array()); $result = $this->Form->select( 'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'), null, array('multiple' => 'checkbox') ); $this->assertEqual($this->Form->fields, array('Model.multi_field')); $result = $this->Form->secure($this->Form->fields); $key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A'; $this->assertPattern('/"' . $key . '"/', $result); }
Checks the security hash array generated for multiple-input checkbox elements @access public @return void
testSelectMultipleCheckboxSecurity
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testInputMultipleCheckboxes() { $result = $this->Form->input('Model.multi_field', array( 'options' => array('first', 'second', 'third'), 'multiple' => 'checkbox' )); $expected = array( array('div' => array('class' => 'input select')), array('label' => array('for' => 'ModelMultiField')), 'Multi Field', '/label', 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'), array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')), array('label' => array('for' => 'ModelMultiField0')), 'first', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')), array('label' => array('for' => 'ModelMultiField1')), 'second', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')), array('label' => array('for' => 'ModelMultiField2')), 'third', '/label', '/div', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.multi_field', array( 'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'), 'multiple' => 'checkbox' )); $expected = array( array('div' => array('class' => 'input select')), array('label' => array('for' => 'ModelMultiField')), 'Multi Field', '/label', 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'), array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')), array('label' => array('for' => 'ModelMultiFieldA')), 'first', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')), array('label' => array('for' => 'ModelMultiFieldB')), 'second', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')), array('label' => array('for' => 'ModelMultiFieldC')), 'third', '/label', '/div', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.multi_field', array( 'options' => array('1' => 'first'), 'multiple' => 'checkbox', 'label' => false, 'div' => false )); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'), array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')), array('label' => array('for' => 'ModelMultiField1')), 'first', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.multi_field', array( 'options' => array('2' => 'second'), 'multiple' => 'checkbox', 'label' => false, 'div' => false )); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'), array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')), array('label' => array('for' => 'ModelMultiField2')), 'second', '/label', '/div' ); $this->assertTags($result, $expected); }
testInputMultipleCheckboxes method test input() resulting in multi select elements being generated. @access public @return void
testInputMultipleCheckboxes
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testSelectCheckboxMultipleOverrideName() { $result = $this->Form->input('category', array( 'type' => 'select', 'multiple' => 'checkbox', 'name' => 'data[fish]', 'options' => array('1', '2'), 'div' => false, 'label' => false, )); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[fish]', 'value' => '', 'id' => 'category'), array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '0', 'id' => 'Category0')), array('label' => array('for' => 'Category0')), '1', '/label', '/div', array('div' => array('class' => 'checkbox')), array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '1', 'id' => 'Category1')), array('label' => array('for' => 'Category1')), '2', '/label', '/div' ); $this->assertTags($result, $expected); }
test that select() with multiple = checkbox works with overriding name attribute. @return void
testSelectCheckboxMultipleOverrideName
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCheckbox() { $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID')) ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Model']['field'] = 'myvalue'; $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field', array('value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ModelField', 'checked' => 'checked', 'class' => 'form-error')) ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = ''; $result = $this->Form->checkbox('Model.field', array('id' => 'theID')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error')) ); $this->assertTags($result, $expected); unset($this->Form->validationErrors['Model']['field']); $result = $this->Form->checkbox('Model.field', array('value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'ModelField')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Contact.name', array('value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][name]', 'value' => '0', 'id' => 'ContactName_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][name]', 'value' => 'myvalue', 'id' => 'ContactName')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field'); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field', array('checked' => false)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')) ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 1; $result = $this->Form->checkbox('Contact.published', array('id' => 'theID')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked')) ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 0; $result = $this->Form->checkbox('Contact.published', array('id'=>'theID')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.CustomField.1.value'); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][CustomField][1][value]', 'value' => '0', 'id' => 'ModelCustomField1Value_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][CustomField][1][value]', 'value' => '1', 'id' => 'ModelCustomField1Value')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('CustomField.1.value'); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[CustomField][1][value]', 'value' => '0', 'id' => 'CustomField1Value_'), array('input' => array('type' => 'checkbox', 'name' => 'data[CustomField][1][value]', 'value' => '1', 'id' => 'CustomField1Value')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Test.test', array('name' => 'myField')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0', 'id' => 'TestTest_'), array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1', 'id' => 'TestTest')) ); $this->assertTags($result, $expected); }
testCheckbox method Test generation of checkboxes @access public @return void
testCheckbox
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCheckboxCheckedOption() { $result = $this->Form->checkbox('Model.field', array('checked' => 'checked')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field', array('checked' => 1)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field', array('checked' => true)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field', array('checked' => false)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')) ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = 1; $result = $this->Form->checkbox('Model.field', array('checked' => false)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')) ); $this->assertTags($result, $expected); }
test the checked option for checkboxes. @return void
testCheckboxCheckedOption
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCheckboxHiddenDisabling() { $result = $this->Form->checkbox('Account.show_name', array('disabled' => false)); $expected = array( array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')), array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName')) ); $this->assertTags($result, $expected); }
Test that specifying false in the 'disabled' option will not disable either the hidden input or the checkbox input @return void
testCheckboxHiddenDisabling
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testDateTime() { extract($this->dateRegex); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', null, array('empty' => false)); $now = strtotime('now'); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('F', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => date('h', $now), 'selected' => 'selected')), date('g', $now), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => date('i', $now), 'selected' => 'selected')), date('i', $now), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => date('a', $now), 'selected' => 'selected')), date('a', $now), '/option', '*/select' ); $this->assertTags($result, $expected); $result = $this->Form->dateTime('Contact.date', 'DMY', '12'); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => '')), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', false); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => '')), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', ''); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => '')), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', '', array('interval' => 5)); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '00', '/option', array('option' => array('value' => '05')), '05', '/option', array('option' => array('value' => '10')), '10', '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', '', array('minuteInterval' => 5)); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '00', '/option', array('option' => array('value' => '05')), '05', '/option', array('option' => array('value' => '10')), '10', '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->Form->data['Contact']['data'] = null; $result = $this->Form->dateTime('Contact.date', 'DMY', '12'); $expected = array( array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')), $minutesRegex, array('option' => array('value' => '')), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->Form->data['Model']['field'] = date('Y') . '-01-01 00:00:00'; $now = strtotime($this->Form->data['Model']['field']); $result = $this->Form->dateTime('Model.field', 'DMY', '12', null, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')), $monthsRegex, array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('F', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '/option', '*/select', array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')), $hoursRegex, array('option' => array('value' => date('h', $now), 'selected' => 'selected')), date('g', $now), '/option', '*/select', ':', array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')), $minutesRegex, array('option' => array('value' => date('i', $now), 'selected' => 'selected')), date('i', $now), '/option', '*/select', ' ', array('select' => array('name' => 'data[Model][field][meridian]', 'id' => 'ModelFieldMeridian')), $meridianRegex, array('option' => array('value' => date('a', $now), 'selected' => 'selected')), date('a', $now), '/option', '*/select' ); $this->assertTags($result, $expected); $selected = strtotime('2008-10-26 12:33:00'); $result = $this->Form->dateTime('Model.field', 'DMY', '12', $selected); $this->assertPattern('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result); $this->Form->create('Contact'); $result = $this->Form->input('published'); $now = strtotime('now'); $expected = array( 'div' => array('class' => 'input date'), 'label' => array('for' => 'ContactPublishedMonth'), 'Published', '/label', array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')), $monthsRegex, array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('F', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '/option', '*/select', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('published2', array('type' => 'date')); $now = strtotime('now'); $expected = array( 'div' => array('class' => 'input date'), 'label' => array('for' => 'ContactPublished2Month'), 'Published2', '/label', array('select' => array('name' => 'data[Contact][published2][month]', 'id' => 'ContactPublished2Month')), $monthsRegex, array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('F', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][published2][day]', 'id' => 'ContactPublished2Day')), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][published2][year]', 'id' => 'ContactPublished2Year')), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '/option', '*/select', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('ContactTag'); $expected = array( 'div' => array('class' => 'input select'), 'label' => array('for' => 'ContactTagContactTag'), 'Contact Tag', '/label', array('input' => array('type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_')), array('select' => array('name' => 'data[ContactTag][ContactTag][]', 'multiple' => 'multiple', 'id' => 'ContactTagContactTag')), '/select', '/div' ); $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->input('published', array('monthNames' => false)); $now = strtotime('now'); $expected = array( 'div' => array('class' => 'input date'), 'label' => array('for' => 'ContactPublishedMonth'), 'Published', '/label', array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')), 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/', array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('m', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '/option', '*/select', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('published', array('type' => 'time')); $now = strtotime('now'); $expected = array( 'div' => array('class' => 'input time'), 'label' => array('for' => 'ContactPublishedHour'), 'Published', '/label', array('select' => array('name' => 'data[Contact][published][hour]', 'id' => 'ContactPublishedHour')), 'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/', array('option' => array('value' => date('h', $now), 'selected' => 'selected')), date('g', $now), '/option', '*/select', ':', ); $this->assertTags($result, $expected); $result = $this->Form->input('published', array( 'timeFormat' => 24, 'interval' => 5, 'selected' => strtotime('2009-09-03 13:37:00'), 'type' => 'datetime' )); $this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result); $this->assertNoErrors(); $this->Form->data['Contact'] = array( 'date' => array( 'day' => '', 'month' => '', 'year' => '', 'hour' => '', 'min' => '', 'meridian' => '' ) ); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', null, array('empty' => false)); }
testDateTime method Test generation of date/time select elements @access public @return void
testDateTime
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testDatetimeWithDefault() { $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', null, array('value' => '2009-06-01 11:15:30')); $this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result); $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', null, array( 'default' => '2009-06-01 11:15:30' )); $this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result); $this->assertPattern('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result); }
test that datetime() and default values work. @return void
testDatetimeWithDefault
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testDateTimeWithBogusData() { $result = $this->Form->dateTime('Contact.updated', 'DMY', '12', 'CURRENT_TIMESTAMP'); $this->assertNoPattern('/selected="selected">\d/', $result); }
test that bogus non-date time data doesn't cause errors. @return void
testDateTimeWithBogusData
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testFormDateTimeMulti() { extract($this->dateRegex); $result = $this->Form->dateTime('Contact.1.updated'); $expected = array( array('select' => array('name' => 'data[Contact][1][updated][day]', 'id' => 'Contact1UpdatedDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][1][updated][month]', 'id' => 'Contact1UpdatedMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][1][updated][year]', 'id' => 'Contact1UpdatedYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][1][updated][hour]', 'id' => 'Contact1UpdatedHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][1][updated][min]', 'id' => 'Contact1UpdatedMin')), $minutesRegex, array('option' => array('value' => '')), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); $result = $this->Form->dateTime('Contact.2.updated'); $expected = array( array('select' => array('name' => 'data[Contact][2][updated][day]', 'id' => 'Contact2UpdatedDay')), $daysRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][2][updated][month]', 'id' => 'Contact2UpdatedMonth')), $monthsRegex, array('option' => array('value' => '')), '/option', '*/select', '-', array('select' => array('name' => 'data[Contact][2][updated][year]', 'id' => 'Contact2UpdatedYear')), $yearsRegex, array('option' => array('value' => '')), '/option', '*/select', array('select' => array('name' => 'data[Contact][2][updated][hour]', 'id' => 'Contact2UpdatedHour')), $hoursRegex, array('option' => array('value' => '')), '/option', '*/select', ':', array('select' => array('name' => 'data[Contact][2][updated][min]', 'id' => 'Contact2UpdatedMin')), $minutesRegex, array('option' => array('value' => '')), '/option', '*/select', ' ', array('select' => array('name' => 'data[Contact][2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')), $meridianRegex, array('option' => array('value' => '')), '/option', '*/select' ); $this->assertTags($result, $expected); }
testFormDateTimeMulti method test multiple datetime element generation @access public @return void
testFormDateTimeMulti
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testMonth() { $result = $this->Form->month('Model.field'); $expected = array( array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), date('F', strtotime('2008-01-01 00:00:00')), '/option', array('option' => array('value' => '02')), date('F', strtotime('2008-02-01 00:00:00')), '/option', '*/select', ); $this->assertTags($result, $expected); $result = $this->Form->month('Model.field', null, array('empty' => true)); $expected = array( array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), date('F', strtotime('2008-01-01 00:00:00')), '/option', array('option' => array('value' => '02')), date('F', strtotime('2008-02-01 00:00:00')), '/option', '*/select', ); $this->assertTags($result, $expected); $result = $this->Form->month('Model.field', null, array('monthNames' => false)); $expected = array( array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '01', '/option', array('option' => array('value' => '02')), '02', '/option', '*/select', ); $this->assertTags($result, $expected); $monthNames = array( '01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun', '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'); $result = $this->Form->month('Model.field', null, array('monthNames' => $monthNames)); $expected = array( array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), 'Jan', '/option', array('option' => array('value' => '02')), 'Feb', '/option', '*/select', ); $this->assertTags($result, $expected); }
testMonth method @access public @return void
testMonth
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testDay() { extract($this->dateRegex); $result = $this->Form->day('Model.field', false); $expected = array( array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $daysRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = '2006-10-10 23:12:32'; $result = $this->Form->day('Model.field'); $expected = array( array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $daysRegex, array('option' => array('value' => '10', 'selected' => 'selected')), '10', '/option', $daysRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = ''; $result = $this->Form->day('Model.field', '10'); $expected = array( array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $daysRegex, array('option' => array('value' => '10', 'selected' => 'selected')), '10', '/option', $daysRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = '2006-10-10 23:12:32'; $result = $this->Form->day('Model.field', true); $expected = array( array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $daysRegex, array('option' => array('value' => '10', 'selected' => 'selected')), '10', '/option', $daysRegex, '/select', ); $this->assertTags($result, $expected); }
testDay method @access public @return void
testDay
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testMinute() { extract($this->dateRegex); $result = $this->Form->minute('Model.field'); $expected = array( array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '00', '/option', array('option' => array('value' => '01')), '01', '/option', array('option' => array('value' => '02')), '02', '/option', $minutesRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = '2006-10-10 00:12:32'; $result = $this->Form->minute('Model.field'); $expected = array( array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '00', '/option', array('option' => array('value' => '01')), '01', '/option', array('option' => array('value' => '02')), '02', '/option', $minutesRegex, array('option' => array('value' => '12', 'selected' => 'selected')), '12', '/option', $minutesRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = ''; $result = $this->Form->minute('Model.field', null, array('interval' => 5)); $expected = array( array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '00', '/option', array('option' => array('value' => '05')), '05', '/option', array('option' => array('value' => '10')), '10', '/option', $minutesRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = '2006-10-10 00:10:32'; $result = $this->Form->minute('Model.field', null, array('interval' => 5)); $expected = array( array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '00', '/option', array('option' => array('value' => '05')), '05', '/option', array('option' => array('value' => '10', 'selected' => 'selected')), '10', '/option', $minutesRegex, '/select', ); $this->assertTags($result, $expected); }
testMinute method @access public @return void
testMinute
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testHour() { extract($this->dateRegex); $result = $this->Form->hour('Model.field', false); $expected = array( array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $hoursRegex, '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = '2006-10-10 00:12:32'; $result = $this->Form->hour('Model.field', false); $expected = array( array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $hoursRegex, array('option' => array('value' => '12', 'selected' => 'selected')), '12', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = ''; $result = $this->Form->hour('Model.field', true, '23'); $expected = array( array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '00')), '0', '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $hoursRegex, array('option' => array('value' => '23', 'selected' => 'selected')), '23', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = '2006-10-10 00:12:32'; $result = $this->Form->hour('Model.field', true); $expected = array( array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '00', 'selected' => 'selected')), '0', '/option', array('option' => array('value' => '01')), '1', '/option', array('option' => array('value' => '02')), '2', '/option', $hoursRegex, '/select', ); $this->assertTags($result, $expected); unset($this->Form->data['Model']['field']); $result = $this->Form->hour('Model.field', true, 'now'); $thisHour = date('H'); $optValue = date('G'); $this->assertPattern('/<option value="' . $thisHour . '" selected="selected">'. $optValue .'<\/option>/', $result); }
testHour method @access public @return void
testHour
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testYear() { $result = $this->Form->year('Model.field', 2006, 2007); $expected = array( array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $result = $this->Form->year('Model.field', 2006, 2007, null, array('orderYear' => 'asc')); $expected = array( array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '2006')), '2006', '/option', array('option' => array('value' => '2007')), '2007', '/option', '/select', ); $this->assertTags($result, $expected); $this->data['Contact']['published'] = ''; $result = $this->Form->year('Contact.published', 2006, 2007, null, array('class' => 'year')); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = '2006-10-10'; $result = $this->Form->year('Contact.published', 2006, 2007, null, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006', 'selected' => 'selected')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = ''; $result = $this->Form->year('Contact.published', 2006, 2007, false); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = '2006-10-10'; $result = $this->Form->year('Contact.published', 2006, 2007, false, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006', 'selected' => 'selected')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = ''; $result = $this->Form->year('Contact.published', 2006, 2007, 2007); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '')), '/option', array('option' => array('value' => '2007', 'selected' => 'selected')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = '2006-10-10'; $result = $this->Form->year('Contact.published', 2006, 2007, 2007, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '2007', 'selected' => 'selected')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = ''; $result = $this->Form->year('Contact.published', 2006, 2008, 2007, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '2008')), '2008', '/option', array('option' => array('value' => '2007', 'selected' => 'selected')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data['Contact']['published'] = '2006-10-10'; $result = $this->Form->year('Contact.published', 2006, 2008, null, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '2008')), '2008', '/option', array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006', 'selected' => 'selected')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); $this->Form->data = array(); $this->Form->create('Contact'); $result = $this->Form->year('published', 2006, 2008, null, array('empty' => false)); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')), array('option' => array('value' => '2008')), '2008', '/option', array('option' => array('value' => '2007')), '2007', '/option', array('option' => array('value' => '2006')), '2006', '/option', '/select', ); $this->assertTags($result, $expected); }
testYear method @access public @return void
testYear
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testTextArea() { $this->Form->data = array('Model' => array('field' => 'some test data')); $result = $this->Form->textarea('Model.field'); $expected = array( 'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), 'some test data', '/textarea', ); $this->assertTags($result, $expected); $result = $this->Form->textarea('Model.tmp'); $expected = array( 'textarea' => array('name' => 'data[Model][tmp]', 'id' => 'ModelTmp'), '/textarea', ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars')); $result = $this->Form->textarea('Model.field'); $expected = array( 'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'), '/textarea', ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars')); $result = $this->Form->textarea('Model.field', array('escape' => false)); $expected = array( 'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), 'some <strong>test</strong> data with <a href="#">HTML</a> chars', '/textarea', ); $this->assertTags($result, $expected); $this->Form->data['Model']['0']['OtherModel']['field'] = null; $result = $this->Form->textarea('Model.0.OtherModel.field'); $expected = array( 'textarea' => array('name' => 'data[Model][0][OtherModel][field]', 'id' => 'Model0OtherModelField'), '/textarea' ); $this->assertTags($result, $expected); }
testTextArea method @access public @return void
testTextArea
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testHiddenField() { $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Model']['field'] = 'test'; $result = $this->Form->hidden('Model.field', array('id' => 'theID')); $this->assertTags($result, array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'theID', 'value' => 'test'))); }
testHiddenField method @access public @return void
testHiddenField
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testFileUploadField() { $result = $this->Form->file('Model.upload'); $this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload'))); $this->Form->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0); $result = $this->Form->input('Model.upload', array('type' => 'file')); $expected = array( 'div' => array('class' => 'input file'), 'label' => array('for' => 'ModelUpload'), 'Upload', '/label', 'input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload'), '/div' ); $this->assertTags($result, $expected); }
testFileUploadField method @access public @return void
testFileUploadField
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testFileUploadOnOtherModel() { ClassRegistry::removeObject('view'); $controller =& new Controller(); $controller->name = 'ValidateUsers'; $controller->uses = array('ValidateUser'); $controller->constructClasses(); $view =& new View($controller, true); $this->Form->create('ValidateUser', array('type' => 'file')); $result = $this->Form->file('ValidateProfile.city'); $expected = array( 'input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'id' => 'ValidateProfileCity') ); $this->assertTags($result, $expected); }
test File upload input on a model not used in create(); @return void
testFileUploadOnOtherModel
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testButton() { $result = $this->Form->button('Hi'); $this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button')); $result = $this->Form->button('Clear Form >', array('type' => 'reset')); $this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button')); $result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm')); $this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button')); $result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true)); $this->assertTags($result, array('button' => array('type' => 'reset'), '&lt;Clear Form&gt;', '/button')); $result = $this->Form->button('Upload Text', array('onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'", 'escape' => false)); $this->assertNoPattern('/\&039/', $result); }
testButton method @access public @return void
testButton
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCreate() { $result = $this->Form->create('Contact'); $encoding = strtolower(Configure::read('App.encoding')); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding ), 'div' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'GET')); $expected = array('form' => array( 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add', 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'get')); $expected = array('form' => array( 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add', 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'put')); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'file')); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data' ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $this->Form->data['Contact']['id'] = 1; $this->Form->params['action'] = 'edit'; $result = $this->Form->create('Contact'); $expected = array( 'form' => array( 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/div' ); $this->assertTags($result, $expected); $this->Form->data['Contact']['id'] = 1; $this->Form->params['action'] = 'edit'; $result = $this->Form->create('Contact', array('type' => 'file')); $expected = array( 'form' => array( 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1', 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data' ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/div' ); $this->assertTags($result, $expected); $this->Form->data['ContactNonStandardPk']['pk'] = 1; $result = $this->Form->create('ContactNonStandardPk'); $expected = array( 'form' => array( 'id' => 'ContactNonStandardPkEditForm', 'method' => 'post', 'action' => '/contact_non_standard_pks/edit/1','accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('id' => 'TestId')); $expected = array( 'form' => array( 'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/div' ); $this->assertTags($result, $expected); $this->Form->params['action'] = 'add'; $result = $this->Form->create('User', array('url' => array('action' => 'login'))); $expected = array( 'form' => array( 'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->create('User', array('action' => 'login')); $expected = array( 'form' => array( 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->create('User', array('url' => '/users/login')); $expected = array( 'form' => array('method' => 'post', 'action' => '/users/login','accept-charset' => $encoding), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $this->Form->params['controller'] = 'pages'; $this->Form->params['models'] = array('User', 'Post'); $result = $this->Form->create('User', array('action' => 'signup')); $expected = array( 'form' => array( 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $this->Form->data = array(); $this->Form->params['controller'] = 'contacts'; $this->Form->params['models'] = array('Contact'); $result = $this->Form->create(array('url' => array('action' => 'index', 'param'))); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param', 'accept-charset' => 'utf-8' ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); }
test the create() method @access public @return void
testCreate
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCreateWithInputDefaults() { $this->Form->create('User', array( 'inputDefaults' => array('div' => false, 'label' => false) )); $result = $this->Form->input('username'); $expected = array( 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername') ); $this->assertTags($result, $expected); $result = $this->Form->input('username', array('div' => true, 'label' => 'username')); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'UserUsername'), 'username', '/label', 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'), '/div' ); $this->assertTags($result, $expected); }
test that inputDefaults are stored and used. @return void
testCreateWithInputDefaults
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCreateWithAcceptCharset() { $result = $this->Form->create('UserForm', array( 'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1' ) ); $expected = array( 'form' => array( 'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm', 'accept-charset' => 'iso-8859-1' ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); }
test automatic accept-charset overriding @return void
testCreateWithAcceptCharset
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCreateQuerystringParams() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array( 'type' => 'post', 'escape' => false, 'url' => array( 'controller' => 'controller', 'action' => 'action', '?' => array('param1' => 'value1', 'param2' => 'value2') ) )); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/controller/action?param1=value1&amp;param2=value2', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array( 'type' => 'post', 'url' => array( 'controller' => 'controller', 'action' => 'action', '?' => array('param1' => 'value1', 'param2' => 'value2') ) )); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/controller/action?param1=value1&amp;param2=value2', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); }
Test base form url when url param is passed with multiple parameters (&)
testCreateQuerystringParams
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCreateWithMultipleIdInData() { $encoding = strtolower(Configure::read('App.encoding')); $this->Form->data['Contact']['id'] = array(1, 2); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); }
test that create() doesn't cause errors by multiple id's being in the primary key as could happen with multiple select or checkboxes. @return void
testCreateWithMultipleIdInData
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testCreatePassedArgs() { $encoding = strtolower(Configure::read('App.encoding')); $this->Form->data['Contact']['id'] = 1; $result = $this->Form->create('Contact', array( 'type' => 'post', 'escape' => false, 'url' => array( 'action' => 'edit', 'myparam' ) )); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/edit/myparam', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected, true); }
test that create() doesn't add in extra passed params. @return void
testCreatePassedArgs
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testGetFormCreate() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array('type' => 'get')); $this->assertTags($result, array('form' => array( 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add', 'accept-charset' => $encoding ))); $result = $this->Form->text('Contact.name'); $this->assertTags($result, array('input' => array( 'name' => 'name', 'type' => 'text', 'id' => 'ContactName', ))); $result = $this->Form->password('password'); $this->assertTags($result, array('input' => array( 'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword' ))); $this->assertNoPattern('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result); $result = $this->Form->text('user_form'); $this->assertTags($result, array('input' => array( 'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm' ))); }
test creating a get form, and get form inputs. @access public @return void
testGetFormCreate
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testGetFormWithFalseModel() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create(false, array('type' => 'get')); $expected = array('form' => array( 'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add', 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->text('reason'); $expected = array( 'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason') ); $this->assertTags($result, $expected); }
test get form, and inputs when the model param is false @return void
testGetFormWithFalseModel
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testDateTimeWithGetForms() { extract($this->dateRegex); $this->Form->create('Contact', array('type' => 'get')); $result = $this->Form->datetime('created'); $this->assertPattern('/name="created\[year\]"/', $result, 'year name attribute is wrong.'); $this->assertPattern('/name="created\[month\]"/', $result, 'month name attribute is wrong.'); $this->assertPattern('/name="created\[day\]"/', $result, 'day name attribute is wrong.'); $this->assertPattern('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.'); $this->assertPattern('/name="created\[min\]"/', $result, 'min name attribute is wrong.'); $this->assertPattern('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.'); }
test that datetime() works with GET style forms. @return void
testDateTimeWithGetForms
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testFormMagicInput() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('name'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ContactName'), 'Name', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][name]', 'id' => 'ContactName', 'maxlength' => '255' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('non_existing_field_in_contact_model'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ContactNonExistingFieldInContactModel'), 'Non Existing Field In Contact Model', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][non_existing_field_in_contact_model]', 'id' => 'ContactNonExistingFieldInContactModel' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Address.street'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'AddressStreet'), 'Street', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Address][street]', 'id' => 'AddressStreet' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Address.non_existing_field_in_model'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'AddressNonExistingFieldInModel'), 'Non Existing Field In Model', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Address][non_existing_field_in_model]', 'id' => 'AddressNonExistingFieldInModel' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('name', array('div' => false)); $expected = array( 'label' => array('for' => 'ContactName'), 'Name', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][name]', 'id' => 'ContactName', 'maxlength' => '255' ) ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.non_existing'); $expected = array( 'div' => array('class' => 'input text required'), 'label' => array('for' => 'ContactNonExisting'), 'Non Existing', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][non_existing]', 'id' => 'ContactNonExisting' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.imrequired'); $expected = array( 'div' => array('class' => 'input text required'), 'label' => array('for' => 'ContactImrequired'), 'Imrequired', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][imrequired]', 'id' => 'ContactImrequired' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.imalsorequired'); $expected = array( 'div' => array('class' => 'input text required'), 'label' => array('for' => 'ContactImalsorequired'), 'Imalsorequired', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][imalsorequired]', 'id' => 'ContactImalsorequired' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.imrequiredtoo'); $expected = array( 'div' => array('class' => 'input text required'), 'label' => array('for' => 'ContactImrequiredtoo'), 'Imrequiredtoo', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]', 'id' => 'ContactImrequiredtoo' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.required_one'); $expected = array( 'div' => array('class' => 'input text required'), 'label' => array('for' => 'ContactRequiredOne'), 'Required One', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][required_one]', 'id' => 'ContactRequiredOne' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.imnotrequired'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ContactImnotrequired'), 'Imnotrequired', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][imnotrequired]', 'id' => 'ContactImnotrequired' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.imalsonotrequired'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ContactImalsonotrequired'), 'Imalsonotrequired', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]', 'id' => 'ContactImalsonotrequired' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.imnotrequiredeither'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ContactImnotrequiredeither'), 'Imnotrequiredeither', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]', 'id' => 'ContactImnotrequiredeither' ), '/div' ); $this->assertTags($result, $expected); extract($this->dateRegex); $now = strtotime('now'); $result = $this->Form->input('Contact.published', array('div' => false)); $expected = array( 'label' => array('for' => 'ContactPublishedMonth'), 'Published', '/label', array('select' => array( 'name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth' )), $monthsRegex, array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('F', $now), '/option', '*/select', '-', array('select' => array( 'name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay' )), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array( 'name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear' )), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '*/select' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.updated', array('div' => false)); $expected = array( 'label' => array('for' => 'ContactUpdatedMonth'), 'Updated', '/label', array('select' => array( 'name' => 'data[Contact][updated][month]', 'id' => 'ContactUpdatedMonth' )), $monthsRegex, array('option' => array('value' => date('m', $now), 'selected' => 'selected')), date('F', $now), '/option', '*/select', '-', array('select' => array( 'name' => 'data[Contact][updated][day]', 'id' => 'ContactUpdatedDay' )), $daysRegex, array('option' => array('value' => date('d', $now), 'selected' => 'selected')), date('j', $now), '/option', '*/select', '-', array('select' => array( 'name' => 'data[Contact][updated][year]', 'id' => 'ContactUpdatedYear' )), $yearsRegex, array('option' => array('value' => date('Y', $now), 'selected' => 'selected')), date('Y', $now), '*/select' ); $this->assertTags($result, $expected); $result = $this->Form->input('User.stuff'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'UserStuff'), 'Stuff', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[User][stuff]', 'id' => 'UserStuff', 'maxlength' => 10 ), '/div' ); $this->assertTags($result, $expected, true); }
testFormMagicInput method @access public @return void
testFormMagicInput
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testForMagicInputNonExistingNorValidated() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false)); $expected = array( 'label' => array('for' => 'ContactNonExistingNorValidated'), 'Non Existing Nor Validated', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]', 'id' => 'ContactNonExistingNorValidated' ) ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.non_existing_nor_validated', array( 'div' => false, 'value' => 'my value' )); $expected = array( 'label' => array('for' => 'ContactNonExistingNorValidated'), 'Non Existing Nor Validated', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]', 'value' => 'my value', 'id' => 'ContactNonExistingNorValidated' ) ); $this->assertTags($result, $expected); $this->Form->data = array( 'Contact' => array('non_existing_nor_validated' => 'CakePHP magic' )); $result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false)); $expected = array( 'label' => array('for' => 'ContactNonExistingNorValidated'), 'Non Existing Nor Validated', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]', 'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated' ) ); $this->assertTags($result, $expected); }
testForMagicInputNonExistingNorValidated method @access public @return void
testForMagicInputNonExistingNorValidated
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testFormMagicInputLabel() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding ), 'div' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.name', array('div' => false, 'label' => false)); $this->assertTags($result, array('input' => array( 'name' => 'data[Contact][name]', 'type' => 'text', 'id' => 'ContactName', 'maxlength' => '255') )); $result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label')); $expected = array( 'label' => array('for' => 'ContactName'), 'My label', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][name]', 'id' => 'ContactName', 'maxlength' => '255' ) ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.name', array( 'div' => false, 'label' => array('class' => 'mandatory') )); $expected = array( 'label' => array('for' => 'ContactName', 'class' => 'mandatory'), 'Name', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][name]', 'id' => 'ContactName', 'maxlength' => '255' ) ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.name', array( 'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label') )); $expected = array( 'label' => array('for' => 'ContactName', 'class' => 'mandatory'), 'My label', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][name]', 'id' => 'ContactName', 'maxlength' => '255' ) ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.name', array( 'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id') )); $expected = array( 'label' => array('for' => 'my_id'), 'Name', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][name]', 'id' => 'my_id', 'maxlength' => '255' ) ); $this->assertTags($result, $expected); $result = $this->Form->input('1.id'); $this->assertTags($result, array('input' => array( 'type' => 'hidden', 'name' => 'data[Contact][1][id]', 'id' => 'Contact1Id' ))); $result = $this->Form->input("1.name"); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'Contact1Name'), 'Name', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Contact][1][name]', 'id' => 'Contact1Name', 'maxlength' => '255' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.1.id'); $this->assertTags($result, array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Contact][1][id]', 'id' => 'Contact1Id' ) )); $result = $this->Form->input("Model.1.name"); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'Model1Name'), 'Name', '/label', 'input' => array( 'type' => 'text', 'name' => 'data[Model][1][name]', 'id' => 'Model1Name' ), '/div' ); $this->assertTags($result, $expected); }
testFormMagicInputLabel method @access public @return void
testFormMagicInputLabel
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testFormEnd() { $this->assertEqual($this->Form->end(), '</form>'); $result = $this->Form->end(''); $expected = array( 'div' => array('class' => 'submit'), 'input' => array('type' => 'submit', 'value' => ''), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end(array('label' => '')); $expected = array( 'div' => array('class' => 'submit'), 'input' => array('type' => 'submit', 'value' => ''), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end('save'); $expected = array( 'div' => array('class' => 'submit'), 'input' => array('type' => 'submit', 'value' => 'save'), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end(array('label' => 'save')); $expected = array( 'div' => array('class' => 'submit'), 'input' => array('type' => 'submit', 'value' => 'save'), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever')); $expected = array( 'div' => array('class' => 'submit'), 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end(array('name' => 'Whatever')); $expected = array( 'div' => array('class' => 'submit'), 'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good')); $expected = array( 'div' => array('class' => 'good'), 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'), '/div', '/form' ); $this->assertTags($result, $expected); $result = $this->Form->end(array( 'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good') )); $expected = array( 'div' => array('class' => 'good'), 'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'), '/div', '/form' ); $this->assertTags($result, $expected); }
testFormEnd method @access public @return void
testFormEnd
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testMultipleFormWithIdFields() { $this->Form->create('UserForm'); $result = $this->Form->input('id'); $this->assertTags($result, array('input' => array( 'type' => 'hidden', 'name' => 'data[UserForm][id]', 'id' => 'UserFormId' ))); $result = $this->Form->input('ValidateItem.id'); $this->assertTags($result, array('input' => array( 'type' => 'hidden', 'name' => 'data[ValidateItem][id]', 'id' => 'ValidateItemId' ))); $result = $this->Form->input('ValidateUser.id'); $this->assertTags($result, array('input' => array( 'type' => 'hidden', 'name' => 'data[ValidateUser][id]', 'id' => 'ValidateUserId' ))); }
testMultipleFormWithIdFields method @access public @return void
testMultipleFormWithIdFields
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testDbLessModel() { $this->Form->create('TestMail'); $result = $this->Form->input('name'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'TestMailName'), 'Name', '/label', 'input' => array( 'name' => 'data[TestMail][name]', 'type' => 'text', 'id' => 'TestMailName' ), '/div' ); $this->assertTags($result, $expected); ClassRegistry::init('TestMail'); $this->Form->create('TestMail'); $result = $this->Form->input('name'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'TestMailName'), 'Name', '/label', 'input' => array( 'name' => 'data[TestMail][name]', 'type' => 'text', 'id' => 'TestMailName' ), '/div' ); $this->assertTags($result, $expected); }
testDbLessModel method @access public @return void
testDbLessModel
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testBrokenness() { /* * #4 This test has two parents and four children. By default (as of r7117) both * parents are show but the first parent is missing a child. This is the inconsistency * in the default behaviour - one parent has all children, the other does not - dependent * on the data values. */ $result = $this->Form->select('Model.field', array( 'Fred' => array( 'freds_son_1' => 'Fred', 'freds_son_2' => 'Freddie' ), 'Bert' => array( 'berts_son_1' => 'Albert', 'berts_son_2' => 'Bertie') ), null, array('showParents' => true, 'empty' => false) ); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('optgroup' => array('label' => 'Fred')), array('option' => array('value' => 'freds_son_1')), 'Fred', '/option', array('option' => array('value' => 'freds_son_2')), 'Freddie', '/option', '/optgroup', array('optgroup' => array('label' => 'Bert')), array('option' => array('value' => 'berts_son_1')), 'Albert', '/option', array('option' => array('value' => 'berts_son_2')), 'Bertie', '/option', '/optgroup', '/select' ); $this->assertTags($result, $expected); /* * #2 This is structurally identical to the test above (#1) - only the parent name has * changed, so we should expect the same select list data, just with a different name * for the parent. As of #7117, this test fails because option 3 => 'Three' disappears. * This is where data corruption can occur, because when a select value is missing from * a list a form will substitute the first value in the list - without the user knowing. * If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not * affect the availability of 3 => 'Three' as a valid option. */ $options = array(1 => 'One', 2 => 'Two', 'Three' => array( 3 => 'Three', 4 => 'Four', 5 => 'Five' )); $result = $this->Form->select( 'Model.field', $options, null, array('showParents' => true, 'empty' => false) ); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => 1)), 'One', '/option', array('option' => array('value' => 2)), 'Two', '/option', array('optgroup' => array('label' => 'Three')), array('option' => array('value' => 3)), 'Three', '/option', array('option' => array('value' => 4)), 'Four', '/option', array('option' => array('value' => 5)), 'Five', '/option', '/optgroup', '/select' ); $this->assertTags($result, $expected); }
testBrokenness method @access public @return void
testBrokenness
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testMultiRecordForm() { $this->Form->create('ValidateProfile'); $this->Form->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value'; $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name'); $expected = array( 'div' => array('class' => 'input textarea'), 'label' => array('for' => 'ValidateProfile1ValidateItem2Name'), 'Name', '/label', 'textarea' => array( 'id' => 'ValidateProfile1ValidateItem2Name', 'name' => 'data[ValidateProfile][1][ValidateItem][2][name]', 'cols' => 30, 'rows' => 6 ), 'Value', '/textarea', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created',array('empty' => true)); $expected = array( 'div' => array('class' => 'input date'), 'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'), 'Created', '/label', array('select' => array( 'name' => 'data[ValidateProfile][1][ValidateItem][2][created][month]', 'id' => 'ValidateProfile1ValidateItem2CreatedMonth' ) ), array('option' => array('value' => '')), '/option', $this->dateRegex['monthsRegex'], '/select', '-', array('select' => array( 'name' => 'data[ValidateProfile][1][ValidateItem][2][created][day]', 'id' => 'ValidateProfile1ValidateItem2CreatedDay' ) ), array('option' => array('value' => '')), '/option', $this->dateRegex['daysRegex'], '/select', '-', array('select' => array( 'name' => 'data[ValidateProfile][1][ValidateItem][2][created][year]', 'id' => 'ValidateProfile1ValidateItem2CreatedYear' ) ), array('option' => array('value' => '')), '/option', $this->dateRegex['yearsRegex'], '/select', '/div' ); $this->assertTags($result, $expected); $this->Form->validationErrors['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = 'Error'; $this->Form->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1'; $result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id'); $expected = array( 'div' => array('class' => 'input select error'), 'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'), 'Profile', '/label', 'select' => array( 'name' => 'data[ValidateProfile][1][ValidateItem][2][profile_id]', 'id' => 'ValidateProfile1ValidateItem2ProfileId', 'class' => 'form-error' ), '/select', array('div' => array('class' => 'error-message')), 'Error', '/div', '/div' ); $this->assertTags($result, $expected); }
Test the generation of fields for a multi record form. @return void
testMultiRecordForm
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testMultiRecordFormValidationErrors() { $this->Form->create('ValidateProfile'); $this->Form->validationErrors['ValidateProfile'][2]['ValidateItem'][1]['name'] = 'Error in field name'; $result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div')); $this->Form->validationErrors['ValidateProfile'][2]['city'] = 'Error in field city'; $result = $this->Form->error('ValidateProfile.2.city'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); $result = $this->Form->error('2.city'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); }
test the correct display of multi-record form validation errors. @return void
testMultiRecordFormValidationErrors
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function testInputTemplate() { $result = $this->Form->input('Contact.email', array( 'type' => 'text', 'format' => array('input') )); $expected = array( 'div' => array('class' => 'input text'), 'input' => array( 'type' => 'text', 'name' => 'data[Contact][email]', 'id' => 'ContactEmail' ), '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.email', array( 'type' => 'text', 'format' => array('input', 'label'), 'label' => '<em>Email (required)</em>' )); $expected = array( 'div' => array('class' => 'input text'), array('input' => array( 'type' => 'text', 'name' => 'data[Contact][email]', 'id' => 'ContactEmail' )), 'label' => array('for' => 'ContactEmail'), 'em' => array(), 'Email (required)', '/em', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Contact.email', array( 'type' => 'text', 'format' => array('input', 'between', 'label', 'after'), 'between' => '<div>Something in the middle</div>', 'after' => '<span>Some text at the end</span>' )); $expected = array( 'div' => array('class' => 'input text'), array('input' => array( 'type' => 'text', 'name' => 'data[Contact][email]', 'id' => 'ContactEmail' )), array('div' => array()), 'Something in the middle', '/div', 'label' => array('for' => 'ContactEmail'), 'Email', '/label', 'span' => array(), 'Some text at the end', '/span', '/div' ); $this->assertTags($result, $expected); }
tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error" @return void
testInputTemplate
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/form.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/form.test.php
MIT
function startTest() { $this->Html =& new HtmlHelper(); $view =& new View(new TheHtmlTestController()); ClassRegistry::addObject('view', $view); $this->_appEncoding = Configure::read('App.encoding'); $this->_asset = Configure::read('Asset'); $this->_debug = Configure::read('debug'); }
setUp method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function endTest() { Configure::write('App.encoding', $this->_appEncoding); Configure::write('Asset', $this->_asset); Configure::write('debug', $this->_debug); ClassRegistry::flush(); unset($this->Html); }
endTest method @access public @return void
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testDocType() { $result = $this->Html->docType(); $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; $this->assertEqual($result, $expected); $result = $this->Html->docType('html4-strict'); $expected = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'; $this->assertEqual($result, $expected); $this->assertNull($this->Html->docType('non-existing-doctype')); }
testDocType method @access public @return void
testDocType
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testLink() { $result = $this->Html->link('/home'); $expected = array('a' => array('href' => '/home'), 'preg:/\/home/', '/a'); $this->assertTags($result, $expected); $result = $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index', 'full_base' => true)); $expected = array('a' => array('href' => FULL_BASE_URL . '/posts'), 'Posts', '/a'); $this->assertTags($result, $expected); $result = $this->Html->link('Home', '/home', array('confirm' => 'Are you sure you want to do this?')); $expected = array( 'a' => array('href' => '/home', 'onclick' => 'return confirm(&#039;Are you sure you want to do this?&#039;);'), 'Home', '/a' ); $this->assertTags($result, $expected, true); $result = $this->Html->link('Home', '/home', array('default' => false)); $expected = array( 'a' => array('href' => '/home', 'onclick' => 'event.returnValue = false; return false;'), 'Home', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Next >', '#'); $expected = array( 'a' => array('href' => '#'), 'Next &gt;', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Next >', '#', array('escape' => true)); $expected = array( 'a' => array('href' => '#'), 'Next &gt;', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Next >', '#', array('escape' => 'utf-8')); $expected = array( 'a' => array('href' => '#'), 'Next &gt;', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Next >', '#', array('escape' => false)); $expected = array( 'a' => array('href' => '#'), 'Next >', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Next >', '#', array( 'title' => 'to escape &#8230; or not escape?', 'escape' => false )); $expected = array( 'a' => array('href' => '#', 'title' => 'to escape &#8230; or not escape?'), 'Next >', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Next >', '#', array( 'title' => 'to escape &#8230; or not escape?', 'escape' => true )); $expected = array( 'a' => array('href' => '#', 'title' => 'to escape &amp;#8230; or not escape?'), 'Next &gt;', '/a' ); $this->assertTags($result, $expected); $result = $this->Html->link('Original size', array( 'controller' => 'images', 'action' => 'view', 3, '?' => array('height' => 100, 'width' => 200) )); $expected = array( 'a' => array('href' => '/images/view/3?height=100&amp;width=200'), 'Original size', '/a' ); $this->assertTags($result, $expected); Configure::write('Asset.timestamp', false); $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false)); $expected = array( 'a' => array('href' => '#'), 'img' => array('src' => 'img/test.gif', 'alt' => ''), '/a' ); $this->assertTags($result, $expected); $result = $this->Html->image('test.gif', array('url' => '#')); $expected = array( 'a' => array('href' => '#'), 'img' => array('src' => 'img/test.gif', 'alt' => ''), '/a' ); $this->assertTags($result, $expected); Configure::write('Asset.timestamp', 'force'); $result = $this->Html->link($this->Html->image('test.gif'), '#', array('escape' => false)); $expected = array( 'a' => array('href' => '#'), 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''), '/a' ); $this->assertTags($result, $expected); $result = $this->Html->image('test.gif', array('url' => '#')); $expected = array( 'a' => array('href' => '#'), 'img' => array('src' => 'preg:/img\/test\.gif\?\d*/', 'alt' => ''), '/a' ); $this->assertTags($result, $expected); }
testLink method @access public @return void
testLink
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testImageTag() { Configure::write('Asset.timestamp', false); $result = $this->Html->image('test.gif'); $this->assertTags($result, array('img' => array('src' => 'img/test.gif', 'alt' => ''))); $result = $this->Html->image('http://google.com/logo.gif'); $this->assertTags($result, array('img' => array('src' => 'http://google.com/logo.gif', 'alt' => ''))); $result = $this->Html->image(array('controller' => 'test', 'action' => 'view', 1, 'ext' => 'gif')); $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => ''))); $result = $this->Html->image('/test/view/1.gif'); $this->assertTags($result, array('img' => array('src' => '/test/view/1.gif', 'alt' => ''))); }
testImageTag method @access public @return void
testImageTag
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testImageWithTimestampping() { Configure::write('Asset.timestamp', 'force'); $this->Html->webroot = '/'; $result = $this->Html->image('cake.icon.png'); $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => ''))); Configure::write('debug', 0); Configure::write('Asset.timestamp', 'force'); $result = $this->Html->image('cake.icon.png'); $this->assertTags($result, array('img' => array('src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => ''))); $webroot = $this->Html->webroot; $this->Html->webroot = '/testing/longer/'; $result = $this->Html->image('cake.icon.png'); $expected = array( 'img' => array('src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '') ); $this->assertTags($result, $expected); $this->Html->webroot = $webroot; }
test image() with Asset.timestamp @return void
testImageWithTimestampping
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testImageTagWithTheme() { if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) { return; } App::import('Core', 'File'); $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'img' . DS . '__cake_test_image.gif'; $file =& new File($testfile, true); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) )); Configure::write('Asset.timestamp', true); Configure::write('debug', 1); $this->Html->webroot = '/'; $this->Html->theme = 'test_theme'; $result = $this->Html->image('__cake_test_image.gif'); $this->assertTags($result, array( 'img' => array( 'src' => 'preg:/\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/', 'alt' => '' ))); $webroot = $this->Html->webroot; $this->Html->webroot = '/testing/'; $result = $this->Html->image('__cake_test_image.gif'); $this->assertTags($result, array( 'img' => array( 'src' => 'preg:/\/testing\/theme\/test_theme\/img\/__cake_test_image\.gif\?\d+/', 'alt' => '' ))); $this->Html->webroot = $webroot; $dir =& new Folder(WWW_ROOT . 'theme' . DS . 'test_theme'); $dir->delete(); }
Tests creation of an image tag using a theme and asset timestamping @access public @return void @link https://trac.cakephp.org/ticket/6490
testImageTagWithTheme
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testThemeAssetsInMainWebrootPath() { Configure::write('Asset.timestamp', false); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) )); $webRoot = Configure::read('App.www_root'); Configure::write('App.www_root', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'webroot' . DS); $webroot = $this->Html->webroot; $this->Html->theme = 'test_theme'; $result = $this->Html->css('webroot_test'); $expected = array( 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/webroot_test\.css/') ); $this->assertTags($result, $expected); $webroot = $this->Html->webroot; $this->Html->theme = 'test_theme'; $result = $this->Html->css('theme_webroot'); $expected = array( 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*theme\/test_theme\/css\/theme_webroot\.css/') ); $this->assertTags($result, $expected); Configure::write('App.www_root', $webRoot); }
test theme assets in main webroot path @access public @return void
testThemeAssetsInMainWebrootPath
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testStyle() { $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px')); $expected = 'display:none; margin:10px;'; $this->assertPattern('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected); $result = $this->Html->style(array('display'=> 'none', 'margin'=>'10px'), false); $lines = explode("\n", $result); $this->assertPattern('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]); $this->assertPattern('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]); }
testStyle method @access public @return void
testStyle
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testCssLink() { Configure::write('Asset.timestamp', false); Configure::write('Asset.filter.css', false); $result = $this->Html->css('screen'); $expected = array( 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => 'preg:/.*css\/screen\.css/') ); $this->assertTags($result, $expected); $result = $this->Html->css('screen.css'); $this->assertTags($result, $expected); $result = $this->Html->css('my.css.library'); $expected['link']['href'] = 'preg:/.*css\/my\.css\.library\.css/'; $this->assertTags($result, $expected); $result = $this->Html->css('screen.css?1234'); $expected['link']['href'] = 'preg:/.*css\/screen\.css\?1234/'; $this->assertTags($result, $expected); $result = $this->Html->css('http://whatever.com/screen.css?1234'); $expected['link']['href'] = 'preg:/http:\/\/.*\/screen\.css\?1234/'; $this->assertTags($result, $expected); Configure::write('Asset.filter.css', 'css.php'); $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/.*ccss\/cake\.generic\.css/'; $this->assertTags($result, $expected); $result = $this->Html->css('//example.com/css/cake.generic.css'); $expected['link']['href'] = 'preg:/.*example\.com\/css\/cake\.generic\.css/'; $this->assertTags($result, $expected); Configure::write('Asset.filter.css', false); $result = explode("\n", trim($this->Html->css(array('cake.generic', 'vendor.generic')))); $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/'; $this->assertTags($result[0], $expected); $expected['link']['href'] = 'preg:/.*css\/vendor\.generic\.css/'; $this->assertTags($result[1], $expected); $this->assertEqual(count($result), 2); ClassRegistry::removeObject('view'); $view =& new HtmlHelperMockView(); ClassRegistry::addObject('view', $view); $view->expectAt(0, 'addScript', array(new PatternExpectation('/css_in_head.css/'))); $result = $this->Html->css('css_in_head', null, array('inline' => false)); $this->assertNull($result); $view =& ClassRegistry::getObject('view'); $view->expectAt(1, 'addScript', array(new NoPatternExpectation('/inline=""/'))); $result = $this->Html->css('more_css_in_head', null, array('inline' => false)); $this->assertNull($result); }
testCssLink method @access public @return void
testCssLink
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testCssTimestamping() { Configure::write('debug', 2); Configure::write('Asset.timestamp', true); $expected = array( 'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => '') ); $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); Configure::write('debug', 0); $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css/'; $this->assertTags($result, $expected); Configure::write('Asset.timestamp', 'force'); $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); $webroot = $this->Html->webroot; $this->Html->webroot = '/testing/'; $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); $this->Html->webroot = $webroot; $webroot = $this->Html->webroot; $this->Html->webroot = '/testing/longer/'; $result = $this->Html->css('cake.generic'); $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); $this->Html->webroot = $webroot; }
test use of css() and timestamping @return void
testCssTimestamping
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testScriptTimestamping() { $skip = $this->skipIf(!is_writable(JS), 'webroot/js is not Writable, timestamp testing has been skipped'); if ($skip) { return; } Configure::write('debug', 2); Configure::write('Asset.timestamp', true); touch(WWW_ROOT . 'js' . DS. '__cake_js_test.js'); $timestamp = substr(strtotime('now'), 0, 8); $result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false)); $this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s'); Configure::write('debug', 0); Configure::write('Asset.timestamp', 'force'); $result = $this->Html->script('__cake_js_test', array('inline' => true, 'once' => false)); $this->assertPattern('/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"/', $result, 'Timestamp value not found %s'); unlink(WWW_ROOT . 'js' . DS. '__cake_js_test.js'); Configure::write('Asset.timestamp', false); }
test timestamp enforcement for script tags. @return void
testScriptTimestamping
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testScript() { Configure::write('Asset.timestamp', false); $result = $this->Html->script('foo'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'js/foo.js') ); $this->assertTags($result, $expected); $result = $this->Html->script(array('foobar', 'bar')); $expected = array( array('script' => array('type' => 'text/javascript', 'src' => 'js/foobar.js')), '/script', array('script' => array('type' => 'text/javascript', 'src' => 'js/bar.js')), '/script', ); $this->assertTags($result, $expected); $result = $this->Html->script('jquery-1.3'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.js') ); $this->assertTags($result, $expected); $result = $this->Html->script('test.json'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js') ); $this->assertTags($result, $expected); $result = $this->Html->script('http://example.com/test.json'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'http://example.com/test.json') ); $this->assertTags($result, $expected); $result = $this->Html->script('/plugin/js/jquery-1.3.2.js?someparam=foo'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => '/plugin/js/jquery-1.3.2.js?someparam=foo') ); $this->assertTags($result, $expected); $result = $this->Html->script('test.json.js?foo=bar'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'js/test.json.js?foo=bar') ); $this->assertTags($result, $expected); $result = $this->Html->script('foo'); $this->assertNull($result, 'Script returned upon duplicate inclusion %s'); $result = $this->Html->script(array('foo', 'bar', 'baz')); $this->assertNoPattern('/foo.js/', $result); $result = $this->Html->script('foo', array('inline' => true, 'once' => false)); $this->assertNotNull($result); $result = $this->Html->script('jquery-1.3.2', array('defer' => true, 'encoding' => 'utf-8')); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'js/jquery-1.3.2.js', 'defer' => 'defer', 'encoding' => 'utf-8') ); $this->assertTags($result, $expected); $view =& ClassRegistry::getObject('view'); $view =& new HtmlHelperMockView(); $view->expectAt(0, 'addScript', array(new PatternExpectation('/script_in_head.js/'))); $result = $this->Html->script('script_in_head', array('inline' => false)); $this->assertNull($result); }
test that scripts added with uses() are only ever included once. test script tag generation @return void
testScript
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testScriptAssetFilter() { Configure::write('Asset.filter.js', 'js.php'); $result = $this->Html->script('jquery-1.3'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => 'cjs/jquery-1.3.js') ); $this->assertTags($result, $expected); $result = $this->Html->script('//example.com/js/jquery-1.3.js'); $expected = array( 'script' => array('type' => 'text/javascript', 'src' => '//example.com/js/jquery-1.3.js') ); $this->assertTags($result, $expected); }
Test that Asset.filter.js works. @return void
testScriptAssetFilter
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testScriptInTheme() { if ($this->skipIf(!is_writable(WWW_ROOT . 'theme'), 'Cannot write to webroot/theme')) { return; } App::import('Core', 'File'); $testfile = WWW_ROOT . 'theme' . DS . 'test_theme' . DS . 'js' . DS . '__test_js.js'; $file =& new File($testfile, true); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) )); $this->Html->webroot = '/'; $this->Html->theme = 'test_theme'; $result = $this->Html->script('__test_js.js'); $expected = array( 'script' => array('src' => '/theme/test_theme/js/__test_js.js', 'type' => 'text/javascript') ); $this->assertTags($result, $expected); App::build(); }
test a script file in the webroot/theme dir. @return void
testScriptInTheme
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testScriptBlock() { $result = $this->Html->scriptBlock('window.foo = 2;'); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'window.foo = 2;', $this->cDataEnd, '/script', ); $this->assertTags($result, $expected); $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), 'window.foo = 2;', '/script', ); $this->assertTags($result, $expected); $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => true)); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'window.foo = 2;', $this->cDataEnd, '/script', ); $this->assertTags($result, $expected); $view =& ClassRegistry::getObject('view'); $view =& new HtmlHelperMockView(); $view->expectAt(0, 'addScript', array(new PatternExpectation('/window\.foo\s\=\s2;/'))); $result = $this->Html->scriptBlock('window.foo = 2;', array('inline' => false)); $this->assertNull($result); $result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false, 'encoding' => 'utf-8')); $expected = array( 'script' => array('type' => 'text/javascript', 'encoding' => 'utf-8'), 'window.foo = 2;', '/script', ); $this->assertTags($result, $expected); }
test Script block generation @return void
testScriptBlock
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testScriptStartAndScriptEnd() { $result = $this->Html->scriptStart(array('safe' => true)); $this->assertNull($result); echo 'this is some javascript'; $result = $this->Html->scriptEnd(); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'this is some javascript', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Html->scriptStart(array('safe' => false)); $this->assertNull($result); echo 'this is some javascript'; $result = $this->Html->scriptEnd(); $expected = array( 'script' => array('type' => 'text/javascript'), 'this is some javascript', '/script' ); $this->assertTags($result, $expected); ClassRegistry::removeObject('view'); $View =& new HtmlHelperMockView(); $View->expectOnce('addScript'); ClassRegistry::addObject('view', $View); $result = $this->Html->scriptStart(array('safe' => false, 'inline' => false)); $this->assertNull($result); echo 'this is some javascript'; $result = $this->Html->scriptEnd(); $this->assertNull($result); }
test script tag output buffering when using scriptStart() and scriptEnd(); @return void
testScriptStartAndScriptEnd
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testCharsetTag() { Configure::write('App.encoding', null); $result = $this->Html->charset(); $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8'))); Configure::write('App.encoding', 'ISO-8859-1'); $result = $this->Html->charset(); $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=iso-8859-1'))); $result = $this->Html->charset('UTF-7'); $this->assertTags($result, array('meta' => array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-7'))); }
testCharsetTag method @access public @return void
testCharsetTag
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testBreadcrumb() { $this->Html->addCrumb('First', '#first'); $this->Html->addCrumb('Second', '#second'); $this->Html->addCrumb('Third', '#third'); $result = $this->Html->getCrumbs(); $expected = array( array('a' => array('href' => '#first')), 'First', '/a', '&raquo;', array('a' => array('href' => '#second')), 'Second', '/a', '&raquo;', array('a' => array('href' => '#third')), 'Third', '/a', ); $this->assertTags($result, $expected); $result = $this->Html->getCrumbs(' &gt; '); $expected = array( array('a' => array('href' => '#first')), 'First', '/a', ' &gt; ', array('a' => array('href' => '#second')), 'Second', '/a', ' &gt; ', array('a' => array('href' => '#third')), 'Third', '/a', ); $this->assertTags($result, $expected); $this->assertPattern('/^<a[^<>]+>First<\/a> &gt; <a[^<>]+>Second<\/a> &gt; <a[^<>]+>Third<\/a>$/', $result); $this->assertPattern('/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/', $result); $this->assertPattern('/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/', $result); $this->assertPattern('/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/', $result); $this->assertNoPattern('/<a[^<>]+[^href]=[^<>]*>/', $result); $this->Html->addCrumb('Fourth', null); $result = $this->Html->getCrumbs(); $expected = array( array('a' => array('href' => '#first')), 'First', '/a', '&raquo;', array('a' => array('href' => '#second')), 'Second', '/a', '&raquo;', array('a' => array('href' => '#third')), 'Third', '/a', '&raquo;', 'Fourth' ); $this->assertTags($result, $expected); }
testBreadcrumb method @access public @return void
testBreadcrumb
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testNestedList() { $list = array( 'Item 1', 'Item 2' => array( 'Item 2.1' ), 'Item 3', 'Item 4' => array( 'Item 4.1', 'Item 4.2', 'Item 4.3' => array( 'Item 4.3.1', 'Item 4.3.2' ) ), 'Item 5' => array( 'Item 5.1', 'Item 5.2' ) ); $result = $this->Html->nestedList($list); $expected = array( '<ul', '<li', 'Item 1', '/li', '<li', 'Item 2', '<ul', '<li', 'Item 2.1', '/li', '/ul', '/li', '<li', 'Item 3', '/li', '<li', 'Item 4', '<ul', '<li', 'Item 4.1', '/li', '<li', 'Item 4.2', '/li', '<li', 'Item 4.3', '<ul', '<li', 'Item 4.3.1', '/li', '<li', 'Item 4.3.2', '/li', '/ul', '/li', '/ul', '/li', '<li', 'Item 5', '<ul', '<li', 'Item 5.1', '/li', '<li', 'Item 5.2', '/li', '/ul', '/li', '/ul' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, null); $expected = array( '<ul', '<li', 'Item 1', '/li', '<li', 'Item 2', '<ul', '<li', 'Item 2.1', '/li', '/ul', '/li', '<li', 'Item 3', '/li', '<li', 'Item 4', '<ul', '<li', 'Item 4.1', '/li', '<li', 'Item 4.2', '/li', '<li', 'Item 4.3', '<ul', '<li', 'Item 4.3.1', '/li', '<li', 'Item 4.3.2', '/li', '/ul', '/li', '/ul', '/li', '<li', 'Item 5', '<ul', '<li', 'Item 5.1', '/li', '<li', 'Item 5.2', '/li', '/ul', '/li', '/ul' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, array(), array(), 'ol'); $expected = array( '<ol', '<li', 'Item 1', '/li', '<li', 'Item 2', '<ol', '<li', 'Item 2.1', '/li', '/ol', '/li', '<li', 'Item 3', '/li', '<li', 'Item 4', '<ol', '<li', 'Item 4.1', '/li', '<li', 'Item 4.2', '/li', '<li', 'Item 4.3', '<ol', '<li', 'Item 4.3.1', '/li', '<li', 'Item 4.3.2', '/li', '/ol', '/li', '/ol', '/li', '<li', 'Item 5', '<ol', '<li', 'Item 5.1', '/li', '<li', 'Item 5.2', '/li', '/ol', '/li', '/ol' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, 'ol'); $expected = array( '<ol', '<li', 'Item 1', '/li', '<li', 'Item 2', '<ol', '<li', 'Item 2.1', '/li', '/ol', '/li', '<li', 'Item 3', '/li', '<li', 'Item 4', '<ol', '<li', 'Item 4.1', '/li', '<li', 'Item 4.2', '/li', '<li', 'Item 4.3', '<ol', '<li', 'Item 4.3.1', '/li', '<li', 'Item 4.3.2', '/li', '/ol', '/li', '/ol', '/li', '<li', 'Item 5', '<ol', '<li', 'Item 5.1', '/li', '<li', 'Item 5.2', '/li', '/ol', '/li', '/ol' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, array('class'=>'list')); $expected = array( array('ul' => array('class' => 'list')), '<li', 'Item 1', '/li', '<li', 'Item 2', array('ul' => array('class' => 'list')), '<li', 'Item 2.1', '/li', '/ul', '/li', '<li', 'Item 3', '/li', '<li', 'Item 4', array('ul' => array('class' => 'list')), '<li', 'Item 4.1', '/li', '<li', 'Item 4.2', '/li', '<li', 'Item 4.3', array('ul' => array('class' => 'list')), '<li', 'Item 4.3.1', '/li', '<li', 'Item 4.3.2', '/li', '/ul', '/li', '/ul', '/li', '<li', 'Item 5', array('ul' => array('class' => 'list')), '<li', 'Item 5.1', '/li', '<li', 'Item 5.2', '/li', '/ul', '/li', '/ul' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, array(), array('class' => 'item')); $expected = array( '<ul', array('li' => array('class' => 'item')), 'Item 1', '/li', array('li' => array('class' => 'item')), 'Item 2', '<ul', array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul', '/li', array('li' => array('class' => 'item')), 'Item 3', '/li', array('li' => array('class' => 'item')), 'Item 4', '<ul', array('li' => array('class' => 'item')), 'Item 4.1', '/li', array('li' => array('class' => 'item')), 'Item 4.2', '/li', array('li' => array('class' => 'item')), 'Item 4.3', '<ul', array('li' => array('class' => 'item')), 'Item 4.3.1', '/li', array('li' => array('class' => 'item')), 'Item 4.3.2', '/li', '/ul', '/li', '/ul', '/li', array('li' => array('class' => 'item')), 'Item 5', '<ul', array('li' => array('class' => 'item')), 'Item 5.1', '/li', array('li' => array('class' => 'item')), 'Item 5.2', '/li', '/ul', '/li', '/ul' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, array(), array('even' => 'even', 'odd' => 'odd')); $expected = array( '<ul', array('li' => array('class' => 'odd')), 'Item 1', '/li', array('li' => array('class' => 'even')), 'Item 2', '<ul', array('li' => array('class' => 'odd')), 'Item 2.1', '/li', '/ul', '/li', array('li' => array('class' => 'odd')), 'Item 3', '/li', array('li' => array('class' => 'even')), 'Item 4', '<ul', array('li' => array('class' => 'odd')), 'Item 4.1', '/li', array('li' => array('class' => 'even')), 'Item 4.2', '/li', array('li' => array('class' => 'odd')), 'Item 4.3', '<ul', array('li' => array('class' => 'odd')), 'Item 4.3.1', '/li', array('li' => array('class' => 'even')), 'Item 4.3.2', '/li', '/ul', '/li', '/ul', '/li', array('li' => array('class' => 'odd')), 'Item 5', '<ul', array('li' => array('class' => 'odd')), 'Item 5.1', '/li', array('li' => array('class' => 'even')), 'Item 5.2', '/li', '/ul', '/li', '/ul' ); $this->assertTags($result, $expected); $result = $this->Html->nestedList($list, array('class'=>'list'), array('class' => 'item')); $expected = array( array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 1', '/li', array('li' => array('class' => 'item')), 'Item 2', array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 2.1', '/li', '/ul', '/li', array('li' => array('class' => 'item')), 'Item 3', '/li', array('li' => array('class' => 'item')), 'Item 4', array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 4.1', '/li', array('li' => array('class' => 'item')), 'Item 4.2', '/li', array('li' => array('class' => 'item')), 'Item 4.3', array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 4.3.1', '/li', array('li' => array('class' => 'item')), 'Item 4.3.2', '/li', '/ul', '/li', '/ul', '/li', array('li' => array('class' => 'item')), 'Item 5', array('ul' => array('class' => 'list')), array('li' => array('class' => 'item')), 'Item 5.1', '/li', array('li' => array('class' => 'item')), 'Item 5.2', '/li', '/ul', '/li', '/ul' ); $this->assertTags($result, $expected); }
testNestedList method @access public @return void
testNestedList
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testMeta() { $result = $this->Html->meta('this is an rss feed', array('controller' => 'posts', 'ext' => 'rss')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed'))); $result = $this->Html->meta('rss', array('controller' => 'posts', 'ext' => 'rss'), array('title' => 'this is an rss feed')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.rss/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'this is an rss feed'))); $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xml/', 'type' => 'application/atom+xml', 'title' => 'atom'))); $result = $this->Html->meta('non-existing'); $this->assertTags($result, array('<meta')); $result = $this->Html->meta('non-existing', '/posts.xpp'); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => 'non-existing'))); $result = $this->Html->meta('non-existing', '/posts.xpp', array('type' => 'atom')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/posts\.xpp/', 'type' => 'application/atom+xml', 'title' => 'non-existing'))); $result = $this->Html->meta('atom', array('controller' => 'posts', 'ext' => 'xml'), array('link' => '/articles.rss')); $this->assertTags($result, array('link' => array('href' => 'preg:/.*\/articles\.rss/', 'type' => 'application/atom+xml', 'title' => 'atom'))); $result = $this->Html->meta(array('link' => 'favicon.ico', 'rel' => 'icon')); $expected = array( 'link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'icon'), array('link' => array('href' => 'preg:/.*favicon\.ico/', 'rel' => 'shortcut icon')) ); $this->assertTags($result, $expected); $result = $this->Html->meta('icon', 'favicon.ico'); $expected = array( 'link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'icon'), array('link' => array('href' => 'preg:/.*favicon\.ico/', 'type' => 'image/x-icon', 'rel' => 'shortcut icon')) ); $this->assertTags($result, $expected); $result = $this->Html->meta('keywords', 'these, are, some, meta, keywords'); $this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords'))); $this->assertPattern('/\s+\/>$/', $result); $result = $this->Html->meta('description', 'this is the meta description'); $this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description'))); $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL')); $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL'))); $this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false))); $view =& ClassRegistry::getObject('view'); $result = $view->__scripts[0]; $this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL'))); }
testMeta method @access public @return void
testMeta
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testTableHeaders() { $result = $this->Html->tableHeaders(array('ID', 'Name', 'Date')); $expected = array('<tr', '<th', 'ID', '/th', '<th', 'Name', '/th', '<th', 'Date', '/th', '/tr'); $this->assertTags($result, $expected); }
testTableHeaders method @access public @return void
testTableHeaders
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testTableCells() { $tr = array( 'td content 1', array('td content 2', array("width" => "100px")), array('td content 3', "width=100px") ); $result = $this->Html->tableCells($tr); $expected = array( '<tr', '<td', 'td content 1', '/td', array('td' => array('width' => '100px')), 'td content 2', '/td', array('td' => array('width' => 'preg:/100px/')), 'td content 3', '/td', '/tr' ); $this->assertTags($result, $expected); $tr = array('td content 1', 'td content 2', 'td content 3'); $result = $this->Html->tableCells($tr, null, null, true); $expected = array( '<tr', array('td' => array('class' => 'column-1')), 'td content 1', '/td', array('td' => array('class' => 'column-2')), 'td content 2', '/td', array('td' => array('class' => 'column-3')), 'td content 3', '/td', '/tr' ); $this->assertTags($result, $expected); $tr = array('td content 1', 'td content 2', 'td content 3'); $result = $this->Html->tableCells($tr, true); $expected = array( '<tr', array('td' => array('class' => 'column-1')), 'td content 1', '/td', array('td' => array('class' => 'column-2')), 'td content 2', '/td', array('td' => array('class' => 'column-3')), 'td content 3', '/td', '/tr' ); $this->assertTags($result, $expected); $tr = array( array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3') ); $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even')); $expected = "<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>"; $this->assertEqual($result, $expected); $tr = array( array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3') ); $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even')); $expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>"; $this->assertEqual($result, $expected); $tr = array( array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3'), array('td content 1', 'td content 2', 'td content 3') ); $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even')); $result = $this->Html->tableCells($tr, array('class' => 'odd'), array('class' => 'even'), false, false); $expected = "<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"even\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>\n<tr class=\"odd\"><td>td content 1</td> <td>td content 2</td> <td>td content 3</td></tr>"; $this->assertEqual($result, $expected); }
testTableCells method @access public @return void
testTableCells
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testTag() { $result = $this->Html->tag('div'); $this->assertTags($result, '<div'); $result = $this->Html->tag('div', 'text'); $this->assertTags($result, '<div', 'text', '/div'); $result = $this->Html->tag('div', '<text>', 'class-name'); $this->assertTags($result, array('div' => array('class' => 'class-name'), 'preg:/<text>/', '/div')); $result = $this->Html->tag('div', '<text>', array('class' => 'class-name', 'escape' => true)); $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div')); }
testTag method @access public @return void
testTag
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testDiv() { $result = $this->Html->div('class-name'); $this->assertTags($result, array('div' => array('class' => 'class-name'))); $result = $this->Html->div('class-name', 'text'); $this->assertTags($result, array('div' => array('class' => 'class-name'), 'text', '/div')); $result = $this->Html->div('class-name', '<text>', array('escape' => true)); $this->assertTags($result, array('div' => array('class' => 'class-name'), '&lt;text&gt;', '/div')); }
testDiv method @access public @return void
testDiv
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function testPara() { $result = $this->Html->para('class-name', ''); $this->assertTags($result, array('p' => array('class' => 'class-name'))); $result = $this->Html->para('class-name', 'text'); $this->assertTags($result, array('p' => array('class' => 'class-name'), 'text', '/p')); $result = $this->Html->para('class-name', '<text>', array('escape' => true)); $this->assertTags($result, array('p' => array('class' => 'class-name'), '&lt;text&gt;', '/p')); }
testPara method @access public @return void
testPara
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/html.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/html.test.php
MIT
function scripts() { return $this->__scripts; }
scripts method @access public @return void
scripts
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function startTest() { $this->Javascript =& new JavascriptHelper(); $this->Javascript->Html =& new HtmlHelper(); $this->Javascript->Form =& new FormHelper(); $this->View =& new TheView(new TheJsTestController()); ClassRegistry::addObject('view', $this->View); }
setUp method @access public @return void
startTest
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function endTest() { unset($this->Javascript->Html); unset($this->Javascript->Form); unset($this->Javascript); ClassRegistry::removeObject('view'); unset($this->View); }
tearDown method @access public @return void
endTest
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testConstruct() { $Javascript =& new JavascriptHelper(array('safe')); $this->assertTrue($Javascript->safe); $Javascript =& new JavascriptHelper(array('safe' => false)); $this->assertFalse($Javascript->safe); }
testConstruct method @access public @return void
testConstruct
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testLink() { Configure::write('Asset.timestamp', false); $result = $this->Javascript->link('script.js'); $expected = '<script type="text/javascript" src="js/script.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('script'); $expected = '<script type="text/javascript" src="js/script.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('scriptaculous.js?load=effects'); $expected = '<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('some.json.libary'); $expected = '<script type="text/javascript" src="js/some.json.libary.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('jquery-1.1.2'); $expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('jquery-1.1.2'); $expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('/plugin/js/jquery-1.1.2'); $expected = '<script type="text/javascript" src="/plugin/js/jquery-1.1.2.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('/some_other_path/myfile.1.2.2.min.js'); $expected = '<script type="text/javascript" src="/some_other_path/myfile.1.2.2.min.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('some_other_path/myfile.1.2.2.min.js'); $expected = '<script type="text/javascript" src="js/some_other_path/myfile.1.2.2.min.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('some_other_path/myfile.1.2.2.min'); $expected = '<script type="text/javascript" src="js/some_other_path/myfile.1.2.2.min.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('http://example.com/jquery.js'); $expected = '<script type="text/javascript" src="http://example.com/jquery.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link(array('prototype.js', 'scriptaculous.js')); $this->assertPattern('/^\s*<script\s+type="text\/javascript"\s+src=".*js\/prototype\.js"[^<>]*><\/script>/', $result); $this->assertPattern('/<\/script>\s*<script[^<>]+>/', $result); $this->assertPattern('/<script\s+type="text\/javascript"\s+src=".*js\/scriptaculous\.js"[^<>]*><\/script>\s*$/', $result); $result = $this->Javascript->link('jquery-1.1.2', false); $resultScripts = $this->View->scripts(); reset($resultScripts); $expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>'; $this->assertNull($result); $this->assertEqual(count($resultScripts), 1); $this->assertEqual(current($resultScripts), $expected); }
testLink method @access public @return void
testLink
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testFilteringAndTimestamping() { if ($this->skipIf(!is_writable(JS), 'JavaScript directory not writable, skipping JS asset timestamp tests. %s')) { return; } cache(str_replace(WWW_ROOT, '', JS) . '__cake_js_test.js', 'alert("test")', '+999 days', 'public'); $timestamp = substr(strtotime('now'), 0, 8); Configure::write('Asset.timestamp', true); $result = $this->Javascript->link('__cake_js_test'); $this->assertPattern('/^<script[^<>]+src=".*js\/__cake_js_test\.js\?' . $timestamp . '[0-9]{2}"[^<>]*>/', $result); $debug = Configure::read('debug'); Configure::write('debug', 0); $result = $this->Javascript->link('__cake_js_test'); $expected = '<script type="text/javascript" src="js/__cake_js_test.js"></script>'; $this->assertEqual($result, $expected); Configure::write('Asset.timestamp', 'force'); $result = $this->Javascript->link('__cake_js_test'); $this->assertPattern('/^<script[^<>]+src=".*js\/__cake_js_test.js\?' . $timestamp . '[0-9]{2}"[^<>]*>/', $result); Configure::write('debug', $debug); Configure::write('Asset.timestamp', false); $old = Configure::read('Asset.filter.js'); Configure::write('Asset.filter.js', 'js.php'); $result = $this->Javascript->link('__cake_js_test'); $this->assertPattern('/^<script[^<>]+src=".*cjs\/__cake_js_test\.js"[^<>]*>/', $result); Configure::write('Asset.filter.js', true); $result = $this->Javascript->link('jquery-1.1.2'); $expected = '<script type="text/javascript" src="cjs/jquery-1.1.2.js"></script>'; $this->assertEqual($result, $expected); $result = $this->Javascript->link('folderjs/jquery-1.1.2'); $expected = '<script type="text/javascript" src="cjs/folderjs/jquery-1.1.2.js"></script>'; $this->assertEqual($result, $expected); if ($old === null) { Configure::delete('Asset.filter.js'); } $debug = Configure::read('debug'); $webroot = $this->Javascript->webroot; Configure::write('debug', 0); Configure::write('Asset.timestamp', 'force'); $this->Javascript->webroot = '/testing/'; $result = $this->Javascript->link('__cake_js_test'); $this->assertPattern('/^<script[^<>]+src="\/testing\/js\/__cake_js_test\.js\?\d+"[^<>]*>/', $result); $this->Javascript->webroot = '/testing/longer/'; $result = $this->Javascript->link('__cake_js_test'); $this->assertPattern('/^<script[^<>]+src="\/testing\/longer\/js\/__cake_js_test\.js\?\d+"[^<>]*>/', $result); $this->Javascript->webroot = $webroot; Configure::write('debug', $debug); unlink(JS . '__cake_js_test.js'); }
testFilteringAndTimestamping method @access public @return void
testFilteringAndTimestamping
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testValue() { $result = $this->Javascript->value(array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8))); $expected = '{"title":"New thing","indexes":[5,6,7,8]}'; $this->assertEqual($result, $expected); $result = $this->Javascript->value(null); $this->assertEqual($result, 'null'); $result = $this->Javascript->value(true); $this->assertEqual($result, 'true'); $result = $this->Javascript->value(false); $this->assertEqual($result, 'false'); $result = $this->Javascript->value(5); $this->assertEqual($result, '5'); $result = $this->Javascript->value(floatval(5.3)); $this->assertPattern('/^5.3[0]+$/', $result); $result = $this->Javascript->value(''); $expected = '""'; $this->assertEqual($result, $expected); $result = $this->Javascript->value('CakePHP' . "\n" . 'Rapid Development Framework'); $expected = '"CakePHP\\nRapid Development Framework"'; $this->assertEqual($result, $expected); $result = $this->Javascript->value('CakePHP' . "\r\n" . 'Rapid Development Framework' . "\r" . 'For PHP'); $expected = '"CakePHP\\nRapid Development Framework\\nFor PHP"'; $this->assertEqual($result, $expected); $result = $this->Javascript->value('CakePHP: "Rapid Development Framework"'); $expected = '"CakePHP: \\"Rapid Development Framework\\""'; $this->assertEqual($result, $expected); $result = $this->Javascript->value('CakePHP: \'Rapid Development Framework\''); $expected = '"CakePHP: \\\'Rapid Development Framework\\\'"'; $this->assertEqual($result, $expected); }
testValue method @access public @return void
testValue
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testObjectGeneration() { $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8)); $result = $this->Javascript->object($object); $expected = '{"title":"New thing","indexes":[5,6,7,8]}'; $this->assertEqual($result, $expected); $result = $this->Javascript->object(array('default' => 0)); $expected = '{"default":0}'; $this->assertEqual($result, $expected); $result = $this->Javascript->object(array( '2007' => array( 'Spring' => array('1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')), 'Fall' => array('1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')) ), '2006' => array( 'Spring' => array('1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky')), 'Fall' => array('1' => array('id' => 1, 'name' => 'Josh'), '2' => array('id' => 2, 'name' => 'Becky') )) )); $expected = '{"2007":{"Spring":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}},"Fall":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}}},"2006":{"Spring":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}},"Fall":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}}}}'; $this->assertEqual($result, $expected); if (ini_get('precision') >= 12) { $number = 3.141592653589; if (!$this->Javascript->useNative) { $number = sprintf("%.11f", $number); } $result = $this->Javascript->object(array('Object' => array(true, false, 1, '02101', 0, -1, 3.141592653589, "1"))); $expected = '{"Object":[true,false,1,"02101",0,-1,' . $number . ',"1"]}'; $this->assertEqual($result, $expected); $result = $this->Javascript->object(array('Object' => array(true => true, false, -3.141592653589, -10))); $expected = '{"Object":{"1":true,"2":false,"3":' . (-1 * $number) . ',"4":-10}}'; $this->assertEqual($result, $expected); } $result = $this->Javascript->object(new TestJavascriptObject()); $expected = '{"property1":"value1","property2":2}'; $this->assertEqual($result, $expected); $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8)); $result = $this->Javascript->object($object, array('block' => true)); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, '{"title":"New thing","indexes":[5,6,7,8]}', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8), 'object' => array('inner' => array('value' => 1))); $result = $this->Javascript->object($object); $expected = '{"title":"New thing","indexes":[5,6,7,8],"object":{"inner":{"value":1}}}'; $this->assertEqual($result, $expected); foreach (array('true' => true, 'false' => false, 'null' => null) as $expected => $data) { $result = $this->Javascript->object($data); $this->assertEqual($result, $expected); } $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8), 'object' => array('inner' => array('value' => 1))); $result = $this->Javascript->object($object, array('prefix' => 'PREFIX', 'postfix' => 'POSTFIX')); $this->assertPattern('/^PREFIX/', $result); $this->assertPattern('/POSTFIX$/', $result); $this->assertNoPattern('/.PREFIX./', $result); $this->assertNoPattern('/.POSTFIX./', $result); if ($this->Javascript->useNative) { $this->Javascript->useNative = false; $this->testObjectGeneration(); $this->Javascript->useNative = true; } }
testObjectGeneration method @access public @return void
testObjectGeneration
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testObjectNonNative() { $oldNative = $this->Javascript->useNative; $this->Javascript->useNative = false; $object = array( 'Object' => array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3' ) ); $expected = '{"Object":{"key1":val1,"key2":"val2","key3":val3}}'; $result = $this->Javascript->object($object, array('quoteKeys' => false, 'stringKeys' => array('key1', 'key3'))); $this->assertEqual($result, $expected); $expected = '{?Object?:{?key1?:"val1",?key2?:"val2",?key3?:"val3"}}'; $result = $this->Javascript->object($object, array('q' => '?')); $this->assertEqual($result, $expected); $expected = '{?Object?:{?key1?:"val1",?key2?:val2,?key3?:"val3"}}'; $result = $this->Javascript->object($object, array( 'q' => '?', 'stringKeys' => array('key3', 'key1') )); $this->assertEqual($result, $expected); $expected = '{?Object?:{?key1?:val1,?key2?:"val2",?key3?:val3}}'; $result = $this->Javascript->object($object, array( 'q' => '?', 'stringKeys' => array('key3', 'key1'), 'quoteKeys' => false )); $this->assertEqual($result, $expected); $this->Javascript->useNative = $oldNative; }
testObjectNonNative method @access public @return void
testObjectNonNative
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testScriptBlock() { $result = $this->Javascript->codeBlock('something'); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'something', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('allowCache' => true, 'safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), 'something', '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('allowCache' => false, 'safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), 'something', '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', true); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'something', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', false); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'something', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), 'something', '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('safe' => true)); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'something', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock(null, array('safe' => true, 'allowCache' => false)); $this->assertNull($result); echo 'this is some javascript'; $result = $this->Javascript->blockEnd(); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, 'this is some javascript', $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock(); $this->assertNull($result); echo "alert('hey');"; $result = $this->Javascript->blockEnd(); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "alert('hey');", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $this->Javascript->cacheEvents(false, true); $this->assertFalse($this->Javascript->inBlock); $result = $this->Javascript->codeBlock(); $this->assertIdentical($result, null); $this->assertTrue($this->Javascript->inBlock); echo 'alert("this is a buffered script");'; $result = $this->Javascript->blockEnd(); $this->assertIdentical($result, null); $this->assertFalse($this->Javascript->inBlock); $result = $this->Javascript->getCache(); $this->assertEqual('alert("this is a buffered script");', $result); }
testScriptBlock method @access public @return void
testScriptBlock
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testOutOfLineScriptWriting() { echo $this->Javascript->codeBlock('$(document).ready(function() { });', array('inline' => false)); $this->Javascript->codeBlock(null, array('inline' => false)); echo '$(function(){ });'; $this->Javascript->blockEnd(); $script = $this->View->scripts(); $this->assertEqual(count($script), 2); $this->assertPattern('/' . preg_quote('$(document).ready(function() { });', '/') . '/', $script[0]); $this->assertPattern('/' . preg_quote('$(function(){ });', '/') . '/', $script[1]); }
testOutOfLineScriptWriting method @access public @return void
testOutOfLineScriptWriting
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testEvent() { $result = $this->Javascript->event('myId', 'click', 'something();'); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { something(); }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click', 'something();', array('safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), "Event.observe($('myId'), 'click', function(event) { something(); }, false);", '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click'); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click', 'something();', false); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { something(); }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click', 'something();', array('useCapture' => true)); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { something(); }, true);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('document', 'load'); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe(document, 'load', function(event) { }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('$(\'myId\')', 'click', 'something();', array('safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), "Event.observe($('myId'), 'click', function(event) { something(); }, false);", '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->event('\'document\'', 'load', 'something();', array('safe' => false)); $expected = array( 'script' => array('type' => 'text/javascript'), "Event.observe('document', 'load', function(event) { something(); }, false);", '/script' ); $this->assertTags($result, $expected); $this->Javascript->cacheEvents(); $result = $this->Javascript->event('myId', 'click', 'something();'); $this->assertNull($result); $result = $this->Javascript->getCache(); $this->assertPattern('/^' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '$/s', $result); $result = $this->Javascript->event('#myId', 'alert(event);'); $this->assertNull($result); $result = $this->Javascript->getCache(); $this->assertPattern('/^\s*var Rules = {\s*\'#myId\': function\(element, event\)\s*{\s*alert\(event\);\s*}\s*}\s*EventSelectors\.start\(Rules\);\s*$/s', $result); }
testEvent method @access public @return void
testEvent
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testWriteEvents() { $this->Javascript->cacheEvents(); $result = $this->Javascript->event('myId', 'click', 'something();'); $this->assertNull($result); $result = $this->Javascript->writeEvents(); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { something(); }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->getCache(); $this->assertTrue(empty($result)); $this->Javascript->cacheEvents(); $result = $this->Javascript->event('myId', 'click', 'something();'); $this->assertNull($result); $result = $this->Javascript->writeEvents(false); $resultScripts = $this->View->scripts(); reset($resultScripts); $this->assertNull($result); $this->assertEqual(count($resultScripts), 1); $result = current($resultScripts); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { something(); }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->getCache(); $this->assertTrue(empty($result)); }
testWriteEvents method @access public @return void
testWriteEvents
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testEscapeScript() { $result = $this->Javascript->escapeScript(''); $expected = ''; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeScript('CakePHP' . "\n" . 'Rapid Development Framework'); $expected = 'CakePHP\\nRapid Development Framework'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeScript('CakePHP' . "\r\n" . 'Rapid Development Framework' . "\r" . 'For PHP'); $expected = 'CakePHP\\nRapid Development Framework\\nFor PHP'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeScript('CakePHP: "Rapid Development Framework"'); $expected = 'CakePHP: \\"Rapid Development Framework\\"'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeScript('CakePHP: \'Rapid Development Framework\''); $expected = 'CakePHP: \\\'Rapid Development Framework\\\''; $this->assertEqual($result, $expected); }
testEscapeScript method @access public @return void
testEscapeScript
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testEscapeString() { $result = $this->Javascript->escapeString(''); $expected = ''; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('CakePHP' . "\n" . 'Rapid Development Framework'); $expected = 'CakePHP\\nRapid Development Framework'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('CakePHP' . "\r\n" . 'Rapid Development Framework' . "\r" . 'For PHP'); $expected = 'CakePHP\\nRapid Development Framework\\nFor PHP'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('CakePHP: "Rapid Development Framework"'); $expected = 'CakePHP: \\"Rapid Development Framework\\"'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('CakePHP: \'Rapid Development Framework\''); $expected = "CakePHP: \\'Rapid Development Framework\\'"; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('my \\"string\\"'); $expected = 'my \\\\\\"string\\\\\\"'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('my string\nanother line'); $expected = 'my string\\\nanother line'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('String with \n string that looks like newline'); $expected = 'String with \\\n string that looks like newline'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('String with \n string that looks like newline'); $expected = 'String with \\\n string that looks like newline'; $this->assertEqual($result, $expected); }
testEscapeString method @access public @return void
testEscapeString
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testObjectDecodeCompatibility() { if (!function_exists('json_decode')) { return; } $this->Javascript->useNative = false; $data = array("simple string"); $result = $this->Javascript->object($data); $this->assertEqual(json_decode($result), $data); $data = array('my \"string\"'); $result = $this->Javascript->object($data); $this->assertEqual(json_decode($result), $data); $data = array('my \\"string\\"'); $result = $this->Javascript->object($data); $this->assertEqual(json_decode($result), $data); }
test that text encoded with Javascript::object decodes properly @return void
testObjectDecodeCompatibility
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testAfterRender() { $this->Javascript->cacheEvents(); $result = $this->Javascript->event('myId', 'click', 'something();'); $this->assertNull($result); ob_start(); $this->Javascript->afterRender(); $result = ob_get_clean(); $expected = array( 'script' => array('type' => 'text/javascript'), $this->cDataStart, "Event.observe($('myId'), 'click', function(event) { something(); }, false);", $this->cDataEnd, '/script' ); $this->assertTags($result, $expected); $result = $this->Javascript->getCache(); $this->assertTrue(empty($result)); $old = $this->Javascript->enabled; $this->Javascript->enabled = false; $this->Javascript->cacheEvents(); $result = $this->Javascript->event('myId', 'click', 'something();'); $this->assertNull($result); ob_start(); $this->Javascript->afterRender(); $result = ob_get_clean(); $this->assertTrue(empty($result)); $result = $this->Javascript->getCache(); $this->assertPattern('/^' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '$/s', $result); $this->Javascript->enabled = $old; }
testAfterRender method @access public @return void
testAfterRender
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/javascript.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/javascript.test.php
MIT
function testDomReady() { $result = $this->Jquery->domReady('foo.name = "bar";'); $expected = '$(document).ready(function () {foo.name = "bar";});'; $this->assertEqual($result, $expected); }
test dom ready event creation @return void
testDomReady
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/jquery_engine.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/jquery_engine.test.php
MIT
function testRequestWithAlternateJqueryObject() { $this->Jquery->jQueryObject = '$j'; $result = $this->Jquery->request('/people/edit/1', array( 'update' => '#updated', 'success' => 'doFoo', 'method' => 'post', 'dataExpression' => true, 'data' => '$j("#someId").serialize()', 'wrapCallbacks' => false )); $expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});'; $this->assertEqual($result, $expected); }
test that alternate jQuery object values work for request() @return void
testRequestWithAlternateJqueryObject
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/jquery_engine.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/jquery_engine.test.php
MIT
function testSortable() { $this->Jquery->get('#myList'); $result = $this->Jquery->sortable(array( 'distance' => 5, 'containment' => 'parent', 'start' => 'onStart', 'complete' => 'onStop', 'sort' => 'onSort', 'wrapCallbacks' => false )); $expected = '$("#myList").sortable({containment:"parent", distance:5, sort:onSort, start:onStart, stop:onStop});'; $this->assertEqual($result, $expected); $result = $this->Jquery->sortable(array( 'distance' => 5, 'containment' => 'parent', 'start' => 'onStart', 'complete' => 'onStop', 'sort' => 'onSort', )); $expected = '$("#myList").sortable({containment:"parent", distance:5, sort:function (event, ui) {onSort}, start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});'; $this->assertEqual($result, $expected); }
test sortable list generation @return void
testSortable
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/jquery_engine.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/jquery_engine.test.php
MIT
function testSerializeForm() { $this->Jquery->get('#element'); $result = $this->Jquery->serializeForm(array('isForm' => false)); $expected = '$("#element").closest("form").serialize();'; $this->assertEqual($result, $expected); $result = $this->Jquery->serializeForm(array('isForm' => true)); $expected = '$("#element").serialize();'; $this->assertEqual($result, $expected); $result = $this->Jquery->serializeForm(array('isForm' => false, 'inline' => true)); $expected = '$("#element").closest("form").serialize()'; $this->assertEqual($result, $expected); }
test the serializeForm method @return void
testSerializeForm
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/jquery_engine.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/jquery_engine.test.php
MIT
function testMap($options = array()) { return $this->_mapOptions('request', $options); }
test method for testing option mapping @return array
testMap
php
Datawalke/Coordino
cake/tests/cases/libs/view/helpers/js.test.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/cases/libs/view/helpers/js.test.php
MIT