Browse Source

Remove option `errorMessage` for FormHelper::input().

Similar display can be achieved by modifying template.
ADmad 12 years ago
parent
commit
c81e11b7b2
2 changed files with 64 additions and 83 deletions
  1. 0 1
      src/View/Helper/FormHelper.php
  2. 64 82
      tests/TestCase/View/Helper/FormHelperTest.php

+ 0 - 1
src/View/Helper/FormHelper.php

@@ -827,7 +827,6 @@ class FormHelper extends Helper {
  * - `options` - For widgets that take options e.g. radio, select.
  * - `error` - Control the error message that is produced. Set to `false` to disable any kind of error reporting (field
  *    error and error messages).
- * - `errorMessage` - Boolean to control rendering error messages (field error will still occur).
  * - `empty` - String or boolean to enable empty select box options.
  * - `before` - Content to place before the label + input.
  * - `after` - Content to place after the label + input.

+ 64 - 82
tests/TestCase/View/Helper/FormHelperTest.php

@@ -1920,43 +1920,49 @@ class FormHelperTest extends TestCase {
 	}
 
 /**
- * Test validation errors.
+ * test error message display
  *
  * @return void
  */
-	public function testPasswordValidation() {
-		$this->markTestIncomplete('Need to revisit once models work again.');
-		$Contact->validationErrors['password'] = array('Please provide a password');
+	public function testErrorMessageDisplay() {
+		$this->article['errors'] = [
+			'Article' => ['title' => 'error message']
+		];
+		$this->Form->create($this->article);
 
-		$result = $this->Form->input('Contact.password');
-		$expected = array(
-			'div' => array('class' => 'input password error'),
-			'label' => array('for' => 'ContactPassword'),
-			'Password',
+		$result = $this->Form->input('Article.title');
+		$expected = [
+			'div' => ['class' => 'input text error'],
+			'label' => ['for' => 'article-title'],
+			'Title',
 			'/label',
-			'input' => array(
-				'type' => 'password', 'name' => 'Contact[password]',
-				'id' => 'ContactPassword', 'class' => 'form-error'
-			),
-			array('div' => array('class' => 'error-message')),
-			'Please provide a password',
+			'input' => [
+				'type' => 'text', 'name' => 'Article[title]',
+				'id' => 'article-title', 'class' => 'form-error'
+			],
+			['div' => ['class' => 'error-message']],
+			'error message',
 			'/div',
 			'/div'
-		);
+		];
 		$this->assertTags($result, $expected);
 
-		$result = $this->Form->input('Contact.password', array('errorMessage' => false));
-		$expected = array(
-			'div' => array('class' => 'input password error'),
-			'label' => array('for' => 'ContactPassword'),
-			'Password',
+		$result = $this->Form->input('Article.title', [
+			'templates' => [
+				'groupContainerError' => '<div class="input {{type}}{{required}} error">{{content}}</div>'
+			]
+		]);
+		$expected = [
+			'div' => ['class' => 'input text error'],
+			'label' => ['for' => 'article-title'],
+			'Title',
 			'/label',
-			'input' => array(
-				'type' => 'password', 'name' => 'Contact[password]',
-				'id' => 'ContactPassword', 'class' => 'form-error'
-			),
+			'input' => [
+				'type' => 'text', 'name' => 'Article[title]',
+				'id' => 'article-title', 'class' => 'form-error'
+			],
 			'/div'
-		);
+		];
 		$this->assertTags($result, $expected);
 	}
 
@@ -1966,38 +1972,26 @@ class FormHelperTest extends TestCase {
  * @return void
  */
 	public function testEmptyErrorValidation() {
-		$this->markTestIncomplete('Need to revisit once models work again.');
-		$this->Form->validationErrors['Contact']['password'] = '';
+		$this->article['errors'] = [
+			'Article' => ['title' => '']
+		];
+		$this->Form->create($this->article);
 
-		$result = $this->Form->input('Contact.password');
-		$expected = array(
-			'div' => array('class' => 'input password error'),
-			'label' => array('for' => 'ContactPassword'),
-			'Password',
+		$result = $this->Form->input('Article.title');
+		$expected = [
+			'div' => ['class' => 'input text error'],
+			'label' => ['for' => 'article-title'],
+			'Title',
 			'/label',
-			'input' => array(
-				'type' => 'password', 'name' => 'Contact[password]',
-				'id' => 'ContactPassword', 'class' => 'form-error'
-			),
-			array('div' => array('class' => 'error-message')),
-			array(),
+			'input' => [
+				'type' => 'text', 'name' => 'Article[title]',
+				'id' => 'article-title', 'class' => 'form-error'
+			],
+			['div' => ['class' => 'error-message']],
+			[],
 			'/div',
 			'/div'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->input('Contact.password', array('errorMessage' => false));
-		$expected = array(
-			'div' => array('class' => 'input password error'),
-			'label' => array('for' => 'ContactPassword'),
-			'Password',
-			'/label',
-			'input' => array(
-				'type' => 'password', 'name' => 'Contact[password]',
-				'id' => 'ContactPassword', 'class' => 'form-error'
-			),
-			'/div'
-		);
+		];
 		$this->assertTags($result, $expected);
 	}
 
@@ -2007,38 +2001,26 @@ class FormHelperTest extends TestCase {
  * @return void
  */
 	public function testEmptyInputErrorValidation() {
-		$this->markTestIncomplete('Need to revisit once models work again.');
-		$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
+		$this->article['errors'] = [
+			'Article' => ['title' => 'error message']
+		];
+		$this->Form->create($this->article);
 
-		$result = $this->Form->input('Contact.password', array('error' => ''));
-		$expected = array(
-			'div' => array('class' => 'input password error'),
-			'label' => array('for' => 'ContactPassword'),
-			'Password',
+		$result = $this->Form->input('Article.title', array('error' => ''));
+		$expected = [
+			'div' => ['class' => 'input text error'],
+			'label' => ['for' => 'article-title'],
+			'Title',
 			'/label',
-			'input' => array(
-				'type' => 'password', 'name' => 'Contact[password]',
-				'id' => 'ContactPassword', 'class' => 'form-error'
-			),
-			array('div' => array('class' => 'error-message')),
-			array(),
+			'input' => [
+				'type' => 'text', 'name' => 'Article[title]',
+				'id' => 'article-title', 'class' => 'form-error'
+			],
+			['div' => ['class' => 'error-message']],
+			[],
 			'/div',
 			'/div'
-		);
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
-		$expected = array(
-			'div' => array('class' => 'input password error'),
-			'label' => array('for' => 'ContactPassword'),
-			'Password',
-			'/label',
-			'input' => array(
-				'type' => 'password', 'name' => 'Contact[password]',
-				'id' => 'ContactPassword', 'class' => 'form-error'
-			),
-			'/div'
-		);
+		];
 		$this->assertTags($result, $expected);
 	}