|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Widgets\Tests\ContentDecorator; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Yiisoft\Definitions\Exception\CircularReferenceException; |
|
9
|
|
|
use Yiisoft\Definitions\Exception\InvalidConfigException; |
|
10
|
|
|
use Yiisoft\Definitions\Exception\NotInstantiableException; |
|
11
|
|
|
use Yiisoft\Factory\NotFoundException; |
|
12
|
|
|
use Yiisoft\Yii\Widgets\ContentDecorator; |
|
13
|
|
|
use Yiisoft\Yii\Widgets\Tests\Support\Assert; |
|
14
|
|
|
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
|
18
|
|
|
*/ |
|
19
|
|
|
final class ContentDecoratorTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
use TestTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @link https://github.com/yiisoft/yii2/issues/15536 |
|
25
|
|
|
* |
|
26
|
|
|
* @throws CircularReferenceException |
|
27
|
|
|
* @throws InvalidConfigException |
|
28
|
|
|
* @throws NotFoundException |
|
29
|
|
|
* @throws NotInstantiableException |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testContentDecorator(): void |
|
32
|
|
|
{ |
|
33
|
|
|
ContentDecorator::widget()->viewFile('@public/view/layout.php')->begin(); |
|
|
|
|
|
|
34
|
|
|
echo "<div class='left-column'>\n"; |
|
35
|
|
|
echo "<p>This is a left bar!</p>\n"; |
|
36
|
|
|
echo "</div>\n"; |
|
37
|
|
|
echo "<div class='right-column'>\n"; |
|
38
|
|
|
echo "<p>This is a right bar!</p>\n"; |
|
39
|
|
|
echo '</div>'; |
|
40
|
|
|
$html = ContentDecorator::end(); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertStringContainsString('<title>Test</title>', $html); |
|
43
|
|
|
|
|
44
|
|
|
Assert::equalsWithoutLE( |
|
45
|
|
|
<<<HTML |
|
46
|
|
|
<!DOCTYPE html> |
|
47
|
|
|
<html lang="en"> |
|
48
|
|
|
<head> |
|
49
|
|
|
<title>Test</title> |
|
50
|
|
|
</head> |
|
51
|
|
|
<body> |
|
52
|
|
|
<div class='left-column'> |
|
53
|
|
|
<p>This is a left bar!</p> |
|
54
|
|
|
</div> |
|
55
|
|
|
<div class='right-column'> |
|
56
|
|
|
<p>This is a right bar!</p> |
|
57
|
|
|
</div></body> |
|
58
|
|
|
</html> |
|
59
|
|
|
|
|
60
|
|
|
HTML, |
|
61
|
|
|
$html, |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|