Skip to content

Commit d11d4cc

Browse files
implement masked input tests
1 parent 53f1619 commit d11d4cc

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* @link https://www.yiiframework.com/
4+
* @copyright Copyright (c) 2008 Yii Software LLC
5+
* @license https://www.yiiframework.com/license/
6+
*/
7+
8+
namespace yiiunit\framework\widgets;
9+
10+
use Yii;
11+
use yii\web\AssetManager;
12+
use yii\web\View;
13+
use yii\widgets\MaskedInput;
14+
15+
/**
16+
* @group widgets
17+
*/
18+
class MaskedInputTest extends \yiiunit\TestCase
19+
{
20+
/**
21+
* @var MaskedInput
22+
*/
23+
private $maskedInput;
24+
25+
protected function setUp(): void
26+
{
27+
parent::setUp();
28+
$this->mockApplication();
29+
30+
Yii::setAlias('@testWeb', '/');
31+
Yii::setAlias('@testWebRoot', '@yiiunit/data/web');
32+
Yii::setAlias('@bower', '@app/../vendor/bower-asset');
33+
34+
$this->maskedInput = new MaskedInput([
35+
'name' => 'phone',
36+
'mask' => '999-999-9999'
37+
]);
38+
39+
$this->maskedInput->setView($this->getView());
40+
41+
}
42+
43+
public function testMaskedInputValidState()
44+
{
45+
$this->maskedInput->name = 'phone';
46+
$this->maskedInput->mask = '999-999-9999';
47+
48+
$this->maskedInput->init();
49+
50+
ob_start();
51+
$this->maskedInput->run();
52+
$output = ob_get_clean();
53+
54+
$expected = '<input type="text" id="w0" class="form-control" name="phone" data-plugin-inputmask="inputmask_7b93eb48">';
55+
56+
$this->assertEqualsWithoutLE($expected, $output);
57+
}
58+
59+
/**
60+
* Helper methods.
61+
*/
62+
protected function getView()
63+
{
64+
$view = new View();
65+
$view->setAssetManager(new AssetManager([
66+
'basePath' => '@testWebRoot/assets',
67+
'baseUrl' => '@testWeb/assets',
68+
]));
69+
70+
return $view;
71+
}
72+
}

0 commit comments

Comments
 (0)