Commit 5d309c20 by Carsten Brandt

added unit tests for boolean attributes

fixes #1022
parent 34cfb356
...@@ -592,6 +592,13 @@ EOD; ...@@ -592,6 +592,13 @@ EOD;
$this->assertTrue(!array_key_exists('style', $options)); $this->assertTrue(!array_key_exists('style', $options));
} }
public function testBooleanAttributes()
{
$this->assertEquals('<input type="email" name="mail">', Html::input('email', 'mail', null, ['required' => false]));
$this->assertEquals('<input type="email" name="mail" required>', Html::input('email', 'mail', null, ['required' => true]));
$this->assertEquals('<input type="email" name="mail" required="hi">', Html::input('email', 'mail', null, ['required' => 'hi']));
}
protected function getDataItems() protected function getDataItems()
{ {
return [ return [
......
<?php
/**
* @author Carsten Brandt <mail@cebe.cc>
*/
namespace yiiunit\framework\widgets;
use yii\base\DynamicModel;
use yii\widgets\ActiveForm;
/**
* @group widgets
*/
class ActiveFormTest extends \yiiunit\TestCase
{
protected function setUp()
{
$this->mockApplication();
}
public function testBooleanAttributes()
{
$o = ['template' => '{input}'];
$model = new DynamicModel(['name']);
ob_start();
$form = new ActiveForm(['action' => './']);
ob_end_clean();
$this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]" required>
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => true]));
$this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]">
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => false]));
$this->assertEquals(<<<EOF
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]">
</div>
EOF
, (string) $form->field($model, 'name', $o)->input('email', ['required' => false]));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment