1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Yiisoft\Widget\Tests; |
5
|
|
|
|
6
|
|
|
use Yiisoft\Tests\TestCase; |
7
|
|
|
use Yiisoft\Widget\Tests\Stubs\TestWidget; |
8
|
|
|
use Yiisoft\Widget\Tests\Stubs\TestWidgetA; |
9
|
|
|
use Yiisoft\Widget\Tests\Stubs\TestWidgetB; |
10
|
|
|
use Yiisoft\Widget\Widget; |
11
|
|
|
use Yiisoft\Widget\Exception\InvalidConfigException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* WidgetTest. |
15
|
|
|
*/ |
16
|
|
|
class WidgetTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var Widget $widget |
20
|
|
|
*/ |
21
|
|
|
protected $widget; |
22
|
|
|
|
23
|
|
|
public function testWidget(): void |
24
|
|
|
{ |
25
|
|
|
$testWidget = (new TestWidget($this->webView)) |
26
|
|
|
->id('w0') |
27
|
|
|
->run(); |
28
|
|
|
|
29
|
|
|
$this->assertSame('<run-w0>', $testWidget); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testBeginEnd(): void |
33
|
|
|
{ |
34
|
|
|
ob_start(); |
35
|
|
|
ob_implicit_flush(0); |
36
|
|
|
|
37
|
|
|
$testWidgetA = (new TestWidgetA($this->webView)) |
38
|
|
|
->id('test') |
39
|
|
|
->begin(); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(Widget::class, $testWidgetA); |
42
|
|
|
|
43
|
|
|
$testWidgetA->end(); |
44
|
|
|
|
45
|
|
|
$output = ob_get_clean(); |
46
|
|
|
|
47
|
|
|
$this->assertSame('<run-test>', $output); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testWidgetConstruc(): void |
51
|
|
|
{ |
52
|
|
|
ob_start(); |
53
|
|
|
ob_implicit_flush(0); |
54
|
|
|
|
55
|
|
|
$testWidgetB = (new TestWidgetB($this->webView, $this->logger)) |
56
|
|
|
->id('test') |
57
|
|
|
->begin(); |
58
|
|
|
|
59
|
|
|
$this->assertInstanceOf(Widget::class, $testWidgetB); |
60
|
|
|
|
61
|
|
|
$testWidgetB->end(); |
62
|
|
|
|
63
|
|
|
$output = ob_get_clean(); |
64
|
|
|
|
65
|
|
|
$this->assertSame('<run-test-construct>', $output); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @depends testBeginEnd |
70
|
|
|
*/ |
71
|
|
|
public function testStackTracking(): void |
72
|
|
|
{ |
73
|
|
|
$this->expectException(InvalidConfigException::class); |
74
|
|
|
$testWidgetA = new TestWidgetA($this->webView); |
75
|
|
|
$testWidgetA->end(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @depends testBeginEnd |
80
|
|
|
*/ |
81
|
|
|
public function testStackTrackingDisorder(): void |
82
|
|
|
{ |
83
|
|
|
$this->expectException(InvalidConfigException::class); |
84
|
|
|
$testWidgetA = new TestWidgetA($this->webView); |
85
|
|
|
$testWidgetB = new TestWidgetB($this->webView, $this->logger); |
86
|
|
|
$testWidgetA->begin(); |
87
|
|
|
$testWidgetB->end(); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|