-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
1 parent
53f1619
commit d11d4cc
Showing
1 changed file
with
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* @link https://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license https://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yiiunit\framework\widgets; | ||
|
||
use Yii; | ||
use yii\web\AssetManager; | ||
use yii\web\View; | ||
use yii\widgets\MaskedInput; | ||
|
||
/** | ||
* @group widgets | ||
*/ | ||
class MaskedInputTest extends \yiiunit\TestCase | ||
{ | ||
/** | ||
* @var MaskedInput | ||
*/ | ||
private $maskedInput; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->mockApplication(); | ||
|
||
Yii::setAlias('@testWeb', '/'); | ||
Yii::setAlias('@testWebRoot', '@yiiunit/data/web'); | ||
Yii::setAlias('@bower', '@app/../vendor/bower-asset'); | ||
|
||
$this->maskedInput = new MaskedInput([ | ||
'name' => 'phone', | ||
'mask' => '999-999-9999' | ||
]); | ||
|
||
$this->maskedInput->setView($this->getView()); | ||
|
||
} | ||
|
||
public function testMaskedInputValidState() | ||
{ | ||
$this->maskedInput->name = 'phone'; | ||
$this->maskedInput->mask = '999-999-9999'; | ||
|
||
$this->maskedInput->init(); | ||
|
||
ob_start(); | ||
$this->maskedInput->run(); | ||
$output = ob_get_clean(); | ||
|
||
$expected = '<input type="text" id="w0" class="form-control" name="phone" data-plugin-inputmask="inputmask_7b93eb48">'; | ||
|
||
$this->assertEqualsWithoutLE($expected, $output); | ||
} | ||
|
||
/** | ||
* Helper methods. | ||
*/ | ||
protected function getView() | ||
{ | ||
$view = new View(); | ||
$view->setAssetManager(new AssetManager([ | ||
'basePath' => '@testWebRoot/assets', | ||
'baseUrl' => '@testWeb/assets', | ||
])); | ||
|
||
return $view; | ||
} | ||
} |