Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Commit

Permalink
Add test for checkobx helper, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed May 11, 2014
1 parent 8a146da commit 6804967
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 34 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,16 @@ The option `disable-twb` can be passed to the element to disable rendering it in
Checkbox helper can be called in a view with the view helper service `formCheckbox(\Zend\Form\Checkbox $oElement)` :

```php
$this->formCheckbox(new \Zend\Form\Element\Checkbox());
$this->formCheckbox(new \Zend\Form\Element\Checkbox('checkbox-input'));
```
This helper accepts a checkbox element as first param. As the input is rendered into a label element, the label position (append by default) can passed as an option

```php
$this->formCheckbox(new \Zend\Form\Element\Checkbox('checkbox-input',array(
'label' => 'Prepend label',
'label_options' => array('position' => \Zend\Form\View\Helper\FormRow::LABEL_PREPEND)
)));
```
This helper accepts a checkbox element as first param.
The option `disable-twb` (boolean) can be passed to the element to disable rendering it in a `div` container.

#### Form collection : `TwbBundle\Form\View\Helper\TwbBundleFormCollection`

Expand Down Expand Up @@ -264,6 +270,16 @@ $this->badge('badge message',array('class' => 'pull-right');
This helper accepts a message as first param, and attributes for badge container as second param (optionnal).
The class attribute "badge" is auto added to the badge container.

#### Button group : `TwbBundle\View\Helper\TwbBundleButtonGroup`

Button group helper can be called in a view with the view helper service `buttonGroup(array $aButtons = null, array $aButtonGroupOptions = null)` :

```php
$this->buttonGroup(array(new \Zend\Form\Element\Button('left', array('label' => 'Left'))),array('class' => 'pull-right');
```
This helper accepts an array of buttons as first param, and attributes for button group container as second param (optionnal).
The buttons can be instance of `\Zend\Form\Element\Button` or array containing data to build an element with the `\Zend\Form\Factory`

#### Glyphicon : `TwbBundle\View\Helper\TwbBundleGlyphicon`

Glyphicon helper can be called in a view with the view helper service `glyphicon($sGlyphicon = null, array $aGlyphiconAttributes = null)` :
Expand Down
73 changes: 42 additions & 31 deletions tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCheckboxTest.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
<?php
namespace TwbBundleTest\Form\View\Helper;
class TwbBundleFormCheckboxTest extends \PHPUnit_Framework_TestCase{
/**
* @var \TwbBundle\Form\View\Helper\TwbBundleFormCheckbox
*/
protected $formCheckboxHelper;

/**
* @see \PHPUnit_Framework_TestCase::setUp()
*/
public function setUp(){
$oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('view_helper_manager');
$oRenderer = new \Zend\View\Renderer\PhpRenderer();
$this->formCheckboxHelper = $oViewHelperPluginManager->get('formCheckbox')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRenderElementWithWrongElement(){
$this->formCheckboxHelper->render(new \Zend\Form\Element());
}

/**
* @expectedException \LogicException
*/
public function testRenderElementWithEmptyName(){
$this->formCheckboxHelper->render(new \Zend\Form\Element\Checkbox(''));
}
}
<?php

namespace TwbBundleTest\Form\View\Helper;

class TwbBundleFormCheckboxTest extends \PHPUnit_Framework_TestCase {

/**
* @var \TwbBundle\Form\View\Helper\TwbBundleFormCheckbox
*/
protected $formCheckboxHelper;

/**
* @see \PHPUnit_Framework_TestCase::setUp()
*/
public function setUp() {
$oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('view_helper_manager');
$oRenderer = new \Zend\View\Renderer\PhpRenderer();
$this->formCheckboxHelper = $oViewHelperPluginManager->get('formCheckbox')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRenderElementWithWrongElement() {
$this->formCheckboxHelper->render(new \Zend\Form\Element());
}

/**
* @expectedException \LogicException
*/
public function testRenderElementWithEmptyName() {
$this->formCheckboxHelper->render(new \Zend\Form\Element\Checkbox(''));
}

public function testRenderWithLabelPrepend() {
$this->assertEquals('<input type="hidden" name="prepend" value="0"><label>Prepend label <input type="checkbox" name="prepend" value="1"></label>', $this->formCheckboxHelper->render(new \Zend\Form\Element\Checkbox('prepend', array(
'label' => 'Prepend label',
'label_options' => array('position' => \Zend\Form\View\Helper\FormRow::LABEL_PREPEND)
))));
}

}

0 comments on commit 6804967

Please sign in to comment.