Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Added minlength to the validTagAttributes array on multiple elements #211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/View/Helper/FormEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FormEmail extends FormInput
'form' => true,
'list' => true,
'maxlength' => true,
'minlength' => true,
'multiple' => true,
'pattern' => true,
'placeholder' => true,
Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/FormPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FormPassword extends FormInput
'disabled' => true,
'form' => true,
'maxlength' => true,
'minlength' => true,
'pattern' => true,
'placeholder' => true,
'readonly' => true,
Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/FormTel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FormTel extends FormInput
'form' => true,
'list' => true,
'maxlength' => true,
'minlength' => true,
'pattern' => true,
'placeholder' => true,
'readonly' => true,
Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/FormText.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FormText extends FormInput
'form' => true,
'list' => true,
'maxlength' => true,
'minlength' => true,
'pattern' => true,
'placeholder' => true,
'readonly' => true,
Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/FormUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FormUrl extends FormInput
'form' => true,
'list' => true,
'maxlength' => true,
'minlength' => true,
'pattern' => true,
'placeholder' => true,
'readonly' => true,
Expand Down
2 changes: 2 additions & 0 deletions test/View/Helper/FormEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function validAttributes()
['max', 'assertNotContains'],
['maxlength', 'assertContains'],
['min', 'assertNotContains'],
['minlength', 'assertContains'],
['multiple', 'assertContains'],
['pattern', 'assertContains'],
['placeholder', 'assertContains'],
Expand Down Expand Up @@ -103,6 +104,7 @@ public function getCompleteElement()
'max' => 'value',
'maxlength' => 'value',
'min' => 'value',
'minlength' => 'value',
'multiple' => 'multiple',
'name' => 'value',
'pattern' => 'value',
Expand Down
2 changes: 2 additions & 0 deletions test/View/Helper/FormPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function validAttributes()
['max', 'assertNotContains'],
['maxlength', 'assertContains'],
['min', 'assertNotContains'],
['minlength', 'assertContains'],
['multiple', 'assertNotContains'],
['pattern', 'assertContains'],
['placeholder', 'assertContains'],
Expand Down Expand Up @@ -103,6 +104,7 @@ public function getCompleteElement()
'max' => 'value',
'maxlength' => 'value',
'min' => 'value',
'minlength' => 'value',
'multiple' => 'multiple',
'name' => 'value',
'pattern' => 'value',
Expand Down
154 changes: 154 additions & 0 deletions test/View/Helper/FormSearchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Form\View\Helper;

use Zend\Form\Element;
use Zend\Form\View\Helper\FormSearch as FormSearchHelper;

class FormSearchTest extends CommonTestCase
{
public function setUp()
{
$this->helper = new FormSearchHelper();
parent::setUp();
}

public function testRaisesExceptionWhenNameIsNotPresentInElement()
{
$element = new Element();
$this->expectException('Zend\Form\Exception\DomainException');
$this->expectExceptionMessage('name');
$this->helper->render($element);
}

public function testGeneratesTextInputTagWithElement()
{
$element = new Element('foo');
$markup = $this->helper->render($element);
$this->assertContains('<input ', $markup);
$this->assertContains('type="search"', $markup);
}

public function testGeneratesTextInputTagRegardlessOfElementType()
{
$element = new Element('foo');
$element->setAttribute('type', 'email');
$markup = $this->helper->render($element);
$this->assertContains('<input ', $markup);
$this->assertContains('type="search"', $markup);
}

public function validAttributes()
{
return [
['name', 'assertContains'],
['accept', 'assertNotContains'],
['alt', 'assertNotContains'],
['autocomplete', 'assertContains'],
['autofocus', 'assertContains'],
['checked', 'assertNotContains'],
['dirname', 'assertContains'],
['disabled', 'assertContains'],
['form', 'assertContains'],
['formaction', 'assertNotContains'],
['formenctype', 'assertNotContains'],
['formmethod', 'assertNotContains'],
['formnovalidate', 'assertNotContains'],
['formtarget', 'assertNotContains'],
['height', 'assertNotContains'],
['list', 'assertContains'],
['max', 'assertNotContains'],
['maxlength', 'assertContains'],
['min', 'assertNotContains'],
['minlength', 'assertContains'],
['multiple', 'assertNotContains'],
['pattern', 'assertContains'],
['placeholder', 'assertContains'],
['readonly', 'assertContains'],
['required', 'assertContains'],
['size', 'assertContains'],
['src', 'assertNotContains'],
['step', 'assertNotContains'],
['value', 'assertContains'],
['width', 'assertNotContains'],
];
}

public function getCompleteElement()
{
$element = new Element('foo');
$element->setAttributes([
'accept' => 'value',
'alt' => 'value',
'autocomplete' => 'on',
'autofocus' => 'autofocus',
'checked' => 'checked',
'dirname' => 'value',
'disabled' => 'disabled',
'form' => 'value',
'formaction' => 'value',
'formenctype' => 'value',
'formmethod' => 'value',
'formnovalidate' => 'value',
'formtarget' => 'value',
'height' => 'value',
'id' => 'value',
'list' => 'value',
'max' => 'value',
'maxlength' => 'value',
'min' => 'value',
'minlength' => 'value',
'multiple' => 'multiple',
'name' => 'value',
'pattern' => 'value',
'placeholder' => 'value',
'readonly' => 'readonly',
'required' => 'required',
'size' => 'value',
'src' => 'value',
'step' => 'value',
'width' => 'value',
]);
$element->setValue('value');
return $element;
}

/**
* @dataProvider validAttributes
*/
public function testAllValidFormMarkupAttributesPresentInElementAreRendered($attribute, $assertion)
{
$element = $this->getCompleteElement();
$markup = $this->helper->render($element);
switch ($attribute) {
case 'value':
$expect = sprintf('%s="%s"', $attribute, $element->getValue());
break;
default:
$expect = sprintf('%s="%s"', $attribute, $element->getAttribute($attribute));
break;
}
$this->$assertion($expect, $markup);
}

public function testInvokeProxiesToRender()
{
$element = new Element('foo');
$markup = $this->helper->__invoke($element);
$this->assertContains('<input', $markup);
$this->assertContains('name="foo"', $markup);
$this->assertContains('type="search"', $markup);
}

public function testInvokeWithNoElementChainsHelper()
{
$this->assertSame($this->helper, $this->helper->__invoke());
}
}
2 changes: 2 additions & 0 deletions test/View/Helper/FormTelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function validAttributes()
['max', 'assertNotContains'],
['maxlength', 'assertContains'],
['min', 'assertNotContains'],
['minlength', 'assertContains'],
['multiple', 'assertNotContains'],
['pattern', 'assertContains'],
['placeholder', 'assertContains'],
Expand Down Expand Up @@ -103,6 +104,7 @@ public function getCompleteElement()
'max' => 'value',
'maxlength' => 'value',
'min' => 'value',
'minlength' => 'value',
'multiple' => 'multiple',
'name' => 'value',
'pattern' => 'value',
Expand Down
2 changes: 2 additions & 0 deletions test/View/Helper/FormTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function validAttributes()
['max', 'assertNotContains'],
['maxlength', 'assertContains'],
['min', 'assertNotContains'],
['minlength', 'assertContains'],
['multiple', 'assertNotContains'],
['pattern', 'assertContains'],
['placeholder', 'assertContains'],
Expand Down Expand Up @@ -103,6 +104,7 @@ public function getCompleteElement()
'max' => 'value',
'maxlength' => 'value',
'min' => 'value',
'minlength' => 'value',
'multiple' => 'multiple',
'name' => 'value',
'pattern' => 'value',
Expand Down
2 changes: 2 additions & 0 deletions test/View/Helper/FormUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function validAttributes()
['max', 'assertNotContains'],
['maxlength', 'assertContains'],
['min', 'assertNotContains'],
['minlength', 'assertContains'],
['multiple', 'assertNotContains'],
['pattern', 'assertContains'],
['placeholder', 'assertContains'],
Expand Down Expand Up @@ -103,6 +104,7 @@ public function getCompleteElement()
'max' => 'value',
'maxlength' => 'value',
'min' => 'value',
'minlength' => 'value',
'multiple' => 'multiple',
'name' => 'value',
'pattern' => 'value',
Expand Down