mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-05 15:04:38 +01:00
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?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);
|
|
}
|
|
|
|
} |