form.test.php

来自「Cake Framwork , Excellent」· PHP 代码 · 共 1,949 行 · 第 1/5 页

PHP
1,949
字号
			'/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);	}/** * testLabel method * * @access public * @return void */	function testLabel() {		$this->Form->text('Person/name');		$result = $this->Form->label();		$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));		$this->Form->text('Person.name');		$result = $this->Form->label();		$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));		$result = $this->Form->label('Person.first_name');		$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '/label'));		$result = $this->Form->label('Person.first_name', 'Your first name');		$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '/label'));		$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));		$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '/label'));		$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));		$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));		$result = $this->Form->label('Person.first_name', '');		$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '/label'));		$result = $this->Form->label('Person.2.name', '');		$this->assertTags($result, array('label' => array('for' => 'Person2Name'), '/label'));	}/** * testTextbox method * * @access public * @return void */	function testTextbox() {		$result = $this->Form->text('Model.field');		$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField')));		$result = $this->Form->text('Model.field', array('type' => 'password'));		$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField')));		$result = $this->Form->text('Model.field', array('id' => 'theID'));		$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'theID')));		$this->Form->data['Model']['text'] = 'test <strong>HTML</strong> values';		$result = $this->Form->text('Model/text');		$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test &lt;strong&gt;HTML&lt;/strong&gt; values', 'id' => 'ModelText')));		$this->Form->validationErrors['Model']['text'] = 1;		$this->Form->data['Model']['text'] = 'test';		$result = $this->Form->text('Model/text', array('id' => 'theID'));		$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));	}/** * testDefaultValue method * * @access public * @return void */	function testDefaultValue() {		$this->Form->data['Model']['field'] = 'test';		$result = $this->Form->text('Model.field', array('default' => 'default value'));		$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));		unset($this->Form->data['Model']['field']);		$result = $this->Form->text('Model.field', array('default' => 'default value'));		$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));	}/** * testFieldError method * * @access public * @return void */	function testFieldError() {		$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>');	}/** * testPassword method * * @access public * @return void */	function testPassword() {		$result = $this->Form->password('Model.field');		$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', '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')));	}/** * testRadio method * * @access public * @return void */	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('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);		$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->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);	}/** * testSelect method * * @access public * @return void */	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('op

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?