generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
6 changed files
with
96 additions
and
2 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
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
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
70 changes: 70 additions & 0 deletions
70
tests/ViewRenderer/RenderCombinations/RenderCombinationsTest.php
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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\View\Renderer\Tests\ViewRenderer\RenderCombinations; | ||
|
||
use HttpSoft\Message\ResponseFactory; | ||
use HttpSoft\Message\StreamFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Aliases\Aliases; | ||
use Yiisoft\DataResponse\DataResponseFactory; | ||
use Yiisoft\Html\Tag\Link; | ||
use Yiisoft\View\WebView; | ||
use Yiisoft\Yii\View\Renderer\LinkTagsInjectionInterface; | ||
use Yiisoft\Yii\View\Renderer\ViewRenderer; | ||
|
||
final class RenderCombinationsTest extends TestCase | ||
{ | ||
private const EXPECTED_VIEW = 'test'; | ||
private const EXPECTED_CONTENT = <<<HTML | ||
<html> | ||
<head><link href="style.css" rel="stylesheet"></head> | ||
<body> | ||
test</body> | ||
</html> | ||
HTML; | ||
|
||
public function testRenderAfterRenderPartial(): void | ||
{ | ||
$renderer = $this->createRenderer(); | ||
|
||
$this->assertSame(self::EXPECTED_VIEW, $renderer->renderPartialAsString('view')); | ||
$this->assertSame(self::EXPECTED_CONTENT, (string) $renderer->render('view')->getBody()); | ||
} | ||
|
||
public function testRenderPartialAfterRender(): void | ||
{ | ||
$renderer = $this->createRenderer(); | ||
|
||
$this->assertSame(self::EXPECTED_CONTENT, (string) $renderer->render('view')->getBody()); | ||
$this->assertSame(self::EXPECTED_VIEW, $renderer->renderPartialAsString('view')); | ||
} | ||
|
||
public function testRenderTwice(): void | ||
{ | ||
$renderer = $this->createRenderer(); | ||
|
||
$this->assertSame(self::EXPECTED_CONTENT, (string) $renderer->render('view')->getBody()); | ||
$this->assertSame(self::EXPECTED_CONTENT, (string) $renderer->render('view')->getBody()); | ||
} | ||
|
||
private function createRenderer(): ViewRenderer | ||
{ | ||
return new ViewRenderer( | ||
new DataResponseFactory(new ResponseFactory(), new StreamFactory()), | ||
new Aliases(), | ||
new WebView(), | ||
__DIR__, | ||
__DIR__ . '/layout.php', | ||
[ | ||
new class () implements LinkTagsInjectionInterface { | ||
public function getLinkTags(): array | ||
{ | ||
return [Link::toCssFile('style.css')]; | ||
} | ||
}, | ||
] | ||
); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @var Yiisoft\View\WebView $this | ||
* @var string $content | ||
*/ | ||
|
||
$this->beginPage(); | ||
?><html> | ||
<head><?php $this->head() ?></head> | ||
<body> | ||
<?= $content ?> | ||
<?php $this->endBody() ?> | ||
</body> | ||
</html><?php | ||
$this->endPage(); |
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,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
echo 'test'; |