You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
<?php |
|
|
|
namespace yiiunit\framework\web; |
|
|
|
use yii\web\View; |
|
use yiiunit\TestCase; |
|
|
|
/** |
|
* @group web |
|
*/ |
|
class ViewTest extends TestCase |
|
{ |
|
protected function setUp() |
|
{ |
|
parent::setUp(); |
|
} |
|
|
|
public function testRegisterJsFileWithAlias() |
|
{ |
|
$this->mockWebApplication([ |
|
'components' => [ |
|
'request' => [ |
|
'scriptFile' => __DIR__ .'/baseUrl/index.php', |
|
'scriptUrl' => '/baseUrl/index.php', |
|
] |
|
] |
|
]); |
|
|
|
$view = new View(); |
|
$view->registerJsFile('@web/js/somefile.js', ['position' => View::POS_HEAD]); |
|
$html = $view->render('@yiiunit/data/views/layout.php', ['content' => 'content']); |
|
$this->assertContains('<script src="/baseUrl/js/somefile.js"></script></head>', $html); |
|
|
|
$view = new View(); |
|
$view->registerJsFile('@web/js/somefile.js', ['position' => View::POS_BEGIN]); |
|
$html = $view->render('@yiiunit/data/views/layout.php', ['content' => 'content']); |
|
$this->assertContains('<body>'."\n".'<script src="/baseUrl/js/somefile.js"></script>', $html); |
|
|
|
$view = new View(); |
|
$view->registerJsFile('@web/js/somefile.js', ['position' => View::POS_END]); |
|
$html = $view->render('@yiiunit/data/views/layout.php', ['content' => 'content']); |
|
$this->assertContains('<script src="/baseUrl/js/somefile.js"></script></body>', $html); |
|
} |
|
|
|
public function testRegisterCssFileWithAlias() |
|
{ |
|
$this->mockWebApplication([ |
|
'components' => [ |
|
'request' => [ |
|
'scriptFile' => __DIR__ .'/baseUrl/index.php', |
|
'scriptUrl' => '/baseUrl/index.php', |
|
] |
|
] |
|
]); |
|
|
|
$view = new View(); |
|
$view->registerCssFile('@web/css/somefile.css'); |
|
$html = $view->render('@yiiunit/data/views/layout.php', ['content' => 'content']); |
|
$this->assertContains('<link href="/baseUrl/css/somefile.css" rel="stylesheet"></head>', $html); |
|
} |
|
|
|
} |