ActiveFormTest.php 1.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?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
{
16 17 18 19 20 21 22 23 24 25 26
    protected function setUp()
    {
        $this->mockApplication();
    }

    public function testBooleanAttributes()
    {
        $o = ['template' => '{input}'];

        $model = new DynamicModel(['name']);
        ob_start();
Qiang Xue committed
27
        $form = new ActiveForm(['action' => '/something']);
28 29 30
        ob_end_clean();

        $this->assertEquals(<<<EOF
31 32 33 34 35 36
<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]));

37
        $this->assertEquals(<<<EOF
38 39 40 41
<div class="form-group field-dynamicmodel-name">
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]">
</div>
EOF
42
            , (string) $form->field($model, 'name', $o)->input('email', ['required' => false]));
43 44


45
        $this->assertEquals(<<<EOF
46
<div class="form-group field-dynamicmodel-name">
47
<input type="email" id="dynamicmodel-name" class="form-control" name="DynamicModel[name]" required="test">
48 49
</div>
EOF
50
            , (string) $form->field($model, 'name', $o)->input('email', ['required' => 'test']));
51

52
    }
53
}