form.test.php

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

PHP
1,949
字号
		$expected = array(			'div' => array('class' => 'input file'),			'label' => array('for' => 'ContactEmail'),			'Email',			'/label',			array('input' => array('type' => 'file', 'name' => 'data[Contact][email]', 'class' => 'textbox', 'value' => '', 'id' => 'ContactEmail')),			'/div'		);		$this->assertTags($result, $expected);		$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));		$result = explode(':', $result);		$this->assertPattern('/option value="23"/', $result[0]);		$this->assertNoPattern('/option value="24"/', $result[0]);		$result = $this->Form->input('Model.field', array('type' => 'time', 'timeFormat' => 12));		$result = explode(':', $result);		$this->assertPattern('/option value="12"/', $result[0]);		$this->assertNoPattern('/option value="13"/', $result[0]);		$result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'));		$this->assertPattern('/id="customIDDay"/', $result);		$this->assertPattern('/id="customIDHour"/', $result);		$result = explode('</select><select', $result);		$result = explode(':', $result[1]);		$this->assertPattern('/option value="23"/', $result[0]);		$this->assertNoPattern('/option value="24"/', $result[0]);		$result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 12));		$result = explode('</select><select', $result);		$result = explode(':', $result[1]);		$this->assertPattern('/option value="12"/', $result[0]);		$this->assertNoPattern('/option value="13"/', $result[0]);		$this->Form->data = array('Contact' => array('phone' => 'Hello & World > weird chars' ));		$result = $this->Form->input('Contact.phone');		$expected = array(			'div' => array('class' => 'input text'),			'label' => array('for' => 'ContactPhone'),			'Phone',			'/label',			array('input' => array('type' => 'text', 'name' => 'data[Contact][phone]', 'value' => 'Hello &amp; World &gt; weird chars', 'id' => 'ContactPhone', 'maxlength' => 255)),			'/div'		);		$this->assertTags($result, $expected);		unset($this->Form->data);		$this->Form->validationErrors['Model']['field'] = 'Badness!';		$result = $this->Form->input('Model.field');		$expected = array(			'div' => array('class' => 'input text error'),			'label' => array('for' => 'ModelField'),			'Field',			'/label',			'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),			array('div' => array('class' => 'error-message')),			'Badness!',			'/div',			'/div'		);		$this->assertTags($result, $expected);		$result = $this->Form->input('Model.field', array('div' => false, 'error' => array('wrap' => 'span')));		$expected = array(			'label' => array('for' => 'ModelField'),			'Field',			'/label',			'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),			array('span' => array('class' => 'error-message')),			'Badness!',			'/span'		);        // debug($result);exit;		$this->assertTags($result, $expected);		$result = $this->Form->input('Model.field', array('div' => array('tag' => 'span'), 'error' => array('wrap' => false)));		$expected = array(			'span' => array('class' => 'input text error'),			'label' => array('for' => 'ModelField'),			'Field',			'/label',			'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),			'Badness!',			'/span'		);		$this->assertTags($result, $expected);		$result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy'));		$expected = array(			'div' => array('class' => 'input text error'),			'label' => array('for' => 'ModelField'),			'Field',			'/label',			'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),			'A message to you, Rudy',			array('div' => array('class' => 'error-message')),			'Badness!',			'/div',			'/div'		);		$this->assertTags($result, $expected);		$this->Form->setEntity(null);		$this->Form->setEntity('Model.field');		$result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy', 'error' => false));		$expected = array(			'div' => array('class' => 'input text'),			'label' => array('for' => 'ModelField'),			'Field',			'/label',			'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'),			'A message to you, Rudy',			'/div'		);		$this->assertTags($result, $expected);		unset($this->Form->validationErrors['Model']['field']);		$result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy'));		$expected = array(			'div' => array('class' => 'input text'),			'label' => array('for' => 'ModelField'),			'Field',			'/label',			'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'),			'A message to you, Rudy',			'/div'		);		$this->assertTags($result, $expected);		$this->Form->data = array('Model' => array('user_id' => 'value'));		$view =& ClassRegistry::getObject('view');		$view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');		$result = $this->Form->input('Model.user_id', array('empty' => true));		$expected = array(			'div' => array('class' => 'input select'),			'label' => array('for' => 'ModelUserId'),			'User',			'/label',			'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'),			array('option' => array('value' => '')),			'/option',			array('option' => array('value' => 'value', 'selected' => 'selected')),			'good',			'/option',			array('option' => array('value' => 'other')),			'bad',			'/option',			'/select',			'/div'		);		$this->assertTags($result, $expected);		$this->Form->data = array('User' => array('User' => array('value')));		$view =& ClassRegistry::getObject('view');		$view->viewVars['users'] = array('value' => 'good', 'other' => 'bad');		$result = $this->Form->input('User.User', array('empty' => true));		$expected = array(			'div' => array('class' => 'input select'),			'label' => array('for' => 'UserUser'),			'User',			'/label',			'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => ''),			'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),			array('option' => array('value' => '')),			'/option',			array('option' => array('value' => 'value', 'selected' => 'selected')),			'good',			'/option',			array('option' => array('value' => 'other')),			'bad',			'/option',			'/select',			'/div'		);		$this->assertTags($result, $expected);	}/** * testFormInputs method * * @access public * @return void */	function testFormInputs() {		$this->Form->create('Contact');		$result = $this->Form->inputs('The Legend');		$expected = array(			'<fieldset',			'<legend',			'The Legend',			'/legend',			'*/fieldset',		);		$this->assertTags($result, $expected);		$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));		$expected = array(			'fieldset' => array('class' => 'classy-stuff'),			'<legend',			'Field of Dreams',			'/legend',			'*/fieldset'		);		$this->assertTags($result, $expected);		$View = ClassRegistry::getObject('view');		$this->Form->create('Contact');		$this->Form->params['prefix'] = 'admin';		$this->Form->action = 'admin_edit';		$result = $this->Form->inputs();		$expected = array(			'<fieldset',			'<legend',			'Edit Contact',			'/legend',			'*/fieldset',		);		$this->assertTags($result, $expected);		$this->Form->create('Contact');		$result = $this->Form->inputs(false);		$expected = array(			'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input password')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input datetime')),			'*/div',			array('div' => array('class' => 'input select')),			'*/div',		);		$this->assertTags($result, $expected);		$this->Form->create('Contact');		$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));		$expected = array(			'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input password')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input datetime')),			'*/div',			array('div' => array('class' => 'input select')),			'*/div',		);		$this->assertTags($result, $expected);		$this->Form->create('Contact');		$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));		$expected = array(			'fieldset' => array(),			'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input password')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input datetime')),			'*/div',			array('div' => array('class' => 'input select')),			'*/div',			'/fieldset'		);		$this->assertTags($result, $expected);		$this->Form->create('Contact');		$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));		$expected = array(			'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input password')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input datetime')),			'*/div',			array('div' => array('class' => 'input select')),			'*/div',		);		$this->assertTags($result, $expected);		$this->Form->create('Contact');		$result = $this->Form->inputs('Hello');		$expected = array(			'fieldset' => array(),			'legend' => array(),			'Hello',			'/legend',			'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input password')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input datetime')),			'*/div',			array('div' => array('class' => 'input select')),			'*/div',			'/fieldset'		);		$this->assertTags($result, $expected);		$this->Form->create('Contact');		$result = $this->Form->inputs(array('legend' => 'Hello'));		$expected = array(			'fieldset' => array(),			'legend' => array(),			'Hello',			'/legend',			'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'),			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input text')),			'*/div',			array('div' => array('class' => 'input password')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input date')),			'*/div',			array('div' => array('class' => 'input datetime')),			'*/div',			array('div' => array('class' => 'input select')),			'*/div',			'/fieldset'		);		$this->assertTags($result, $expected);	}/** * testSelectAsCheckbox method * * @access public * @return void */	function testSelectAsCheckbox() {		$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox'));		$expected = array(			'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''),			array('div' => array('class' => 'checkbox')),			array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),			array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),			'first',			'/label',			'/div',			array('div' => array('class' => 'checkbox')),			array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),			array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),			'second',			'/label',

⌨️ 快捷键说明

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