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('', $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('' . PHP_EOL . '', $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('', $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('', $html); } public function testRegisterregisterCsrfMetaTags() { $this->mockWebApplication([ 'components' => [ 'request' => [ 'scriptFile' => __DIR__ . '/baseUrl/index.php', 'scriptUrl' => '/baseUrl/index.php', ], 'cache' => [ 'class' => FileCache::className(), ], ], ]); $view = new View(); $view->registerCsrfMetaTags(); $html = $view->render('@yiiunit/data/views/layout.php', ['content' => 'content']); $this->assertContains('', $html); $this->assertContains('', $html); $this->assertContains('~', $html, $matches)) { $this->fail("No CSRF-token meta tag found. HTML was:\n$html"); } return $matches[1]; } }