This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters