3
3
namespace Pd \AsyncControl \UI ;
4
4
5
5
use Mockery ;
6
- use Nette \Application \UI \ITemplate ;
7
- use Nette \Application \UI \ITemplateFactory ;
6
+
7
+ use Nette \Bridges \ApplicationLatte \TemplateFactory ;
8
+ use Nette \Bridges \ApplicationLatte \Template ;
8
9
use Nette \Application \UI \Presenter ;
9
10
use Tester \Assert ;
10
11
use Tester \TestCase ;
11
12
12
13
13
14
require_once __DIR__ . '/../../vendor/autoload.php ' ;
14
15
16
+ \Tester \Environment::bypassFinals ();
17
+
15
18
/**
16
19
* @testCase
17
20
*/
18
21
final class AsyncControlTest extends TestCase
19
22
{
20
23
21
- const VALID_SIGNAL = 'control-form-submit ' ;
22
- const FRAGMENT_PARAMETER = '_escaped_fragment_ ' ;
23
-
24
24
25
25
public function testHandleAjax (): void
26
26
{
27
27
$ presenter = Mockery::mock (Presenter::class);
28
28
$ presenter ->shouldReceive ('isAjax ' )->once ()->andReturn (TRUE );
29
- $ presenter ->shouldReceive ('getPayload ' )->andReturn ($ payload = new \stdClass );
29
+ $ presenter ->shouldReceive ('getPayload ' )->andReturn ($ payload = new \stdClass () );
30
30
$ presenter ->shouldReceive ('sendPayload ' )->once ();
31
- /**
32
- * @var AsyncControl|Mockery\Mock $control
33
- */
34
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
31
+
32
+ $ control = Mockery::mock (AsyncControl::class)->makePartial ()->shouldAllowMockingProtectedMethods ();
35
33
$ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
36
34
$ renderedContent = 'rendered content ' ;
37
- $ control ->shouldReceive ('renderAsync ' )->once ()->andReturnUsing (function () use ($ renderedContent ) {
35
+ $ control ->shouldReceive ('doRender ' )->once ()->andReturnUsing (function () use ($ renderedContent ) {
38
36
echo $ renderedContent ;
39
37
})
40
38
;
@@ -51,9 +49,7 @@ final class AsyncControlTest extends TestCase
51
49
$ presenter ->shouldReceive ('isAjax ' )->once ()->andReturn (FALSE );
52
50
$ presenter ->shouldNotReceive ('getPayload ' );
53
51
$ presenter ->shouldNotReceive ('sendPayload ' );
54
- /**
55
- * @var AsyncControl|Mockery\Mock $control
56
- */
52
+
57
53
$ control = Mockery::mock (AsyncControl::class)->makePartial ();
58
54
$ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
59
55
$ control ->shouldNotReceive ('renderAsync ' );
@@ -62,77 +58,34 @@ final class AsyncControlTest extends TestCase
62
58
}
63
59
64
60
65
- public function testRenderAsyncLoadLink (): void
61
+ public function testRenderAsyncLoadsLink (): void
66
62
{
67
- /**
68
- * @var AsyncControl|Mockery\Mock $control
69
- */
70
63
$ control = Mockery::mock (AsyncControl::class)->makePartial ();
71
64
72
- $ template = Mockery::mock (ITemplate::class);
65
+ $ template = Mockery::mock (Template::class);
66
+ $ template ->shouldReceive ('add ' )->once ()->with ('link ' , Mockery::type (AsyncControlLink::class));
73
67
$ template ->shouldReceive ('setFile ' )->once ()->withAnyArgs ();
74
68
$ template ->shouldReceive ('render ' )->once ();
75
69
76
- $ templateFactory = Mockery::mock (ITemplateFactory ::class);
70
+ $ templateFactory = Mockery::mock (TemplateFactory ::class);
77
71
$ templateFactory ->shouldReceive ('createTemplate ' )->once ()->with ($ control )->andReturn ($ template );
78
72
79
73
$ presenter = Mockery::mock (Presenter::class);
80
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn (NULL );
81
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (Presenter::SIGNAL_KEY )->andReturn (NULL );
82
74
$ presenter ->shouldReceive ('getTemplateFactory ' )->once ()->andReturn ($ templateFactory );
83
75
84
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
85
- $ control ->shouldReceive ('getUniqueId ' )->once ()->andReturn ('control ' );
86
- $ control ->renderAsync ();
87
- }
88
-
89
-
90
- public function testRenderWithSignal (): void
91
- {
92
- $ presenter = Mockery::mock (Presenter::class);
93
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn (NULL );
94
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (Presenter::SIGNAL_KEY )->andReturn (self ::VALID_SIGNAL );
95
- /**
96
- * @var AsyncControl|Mockery\Mock $control
97
- */
98
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
99
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
100
- $ control ->shouldReceive ('getUniqueId ' )->once ()->andReturn ('control ' );
101
- $ control ->shouldReceive ('render ' )->once ();
102
- $ control ->renderAsync ();
103
- }
104
-
105
-
106
- public function testRenderWithFragment (): void
107
- {
108
- $ presenter = Mockery::mock (Presenter::class);
109
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn ('' );
110
- /**
111
- * @var AsyncControl|Mockery\Mock $control
112
- */
113
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
114
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
115
- $ control ->shouldReceive ('render ' )->once ();
76
+ $ control ->shouldReceive ('getPresenter ' )->once ()->andReturn ($ presenter );
116
77
$ control ->renderAsync ();
117
78
}
118
79
119
80
120
81
public function testRenderAsyncRenderer (): void
121
82
{
122
- $ presenter = Mockery::mock (Presenter::class);
123
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (self ::FRAGMENT_PARAMETER )->andReturn (NULL );
124
- $ presenter ->shouldReceive ('getParameter ' )->once ()->with (Presenter::SIGNAL_KEY )->andReturn (self ::VALID_SIGNAL );
125
- /**
126
- * @var AsyncControl|Mockery\Mock $control
127
- */
128
- $ control = Mockery::mock (AsyncControl::class)->makePartial ();
129
- $ control ->shouldReceive ('getPresenter ' )->andReturn ($ presenter );
130
- $ control ->shouldReceive ('getUniqueId ' )->once ()->andReturn ('control ' );
83
+ $ control = Mockery::mock (AsyncControl::class)->makePartial ()->shouldAllowMockingProtectedMethods ();
131
84
$ asyncRendered = FALSE ;
132
85
$ control ->setAsyncRenderer (function () use (&$ asyncRendered ) {
133
86
$ asyncRendered = TRUE ;
134
87
});
135
- $ control ->renderAsync ();
88
+ $ control ->doRender ();
136
89
Assert::equal (TRUE , $ asyncRendered );
137
90
}
138
91
0 commit comments