44namespace Search \Test \TestCase \Controller \Component ;
55
66use Cake \Controller \Controller ;
7+ use Cake \Event \Event ;
8+ use Cake \Http \Response ;
79use Cake \Http \ServerRequest ;
810use Cake \ORM \Table ;
911use Cake \Routing \RouteBuilder ;
@@ -63,26 +65,36 @@ public function testInitializePost()
6365 ->withEnv ('REQUEST_METHOD ' , 'POST ' );
6466
6567 $ this ->Controller ->setRequest ($ request );
66-
67- $ response = $ this ->Search ->startup ();
68+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
69+ $ this ->Search ->startup ($ event );
70+ $ response = $ event ->getResult ();
71+ $ this ->assertInstanceOf (Response::class, $ response );
6872 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
6973
7074 $ this ->Search ->setConfig ('actions ' , false );
71- $ response = $ this ->Search ->startup ();
72- $ this ->assertNull ($ response );
75+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
76+ $ this ->Search ->startup ($ event );
77+ $ this ->assertNull ($ event ->getResult ());
7378
7479 $ this ->Search ->setConfig ('actions ' , 'does-not-exist ' , false );
75- $ response = $ this ->Search ->startup ();
76- $ this ->assertNull ($ response );
80+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
81+ $ this ->Search ->startup ($ event );
82+ $ this ->assertNull ($ event ->getResult ());
7783
7884 $ this ->Search ->setConfig ('actions ' , 'index ' , false );
7985 $ this ->Controller ->setResponse ($ this ->Controller ->getResponse ()->withHeader ('Location ' , '' ));
80- $ response = $ this ->Search ->startup ();
86+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
87+ $ this ->Search ->startup ($ event );
88+ $ response = $ event ->getResult ();
89+ $ this ->assertInstanceOf (Response::class, $ response );
8190 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
8291
8392 $ this ->Search ->setConfig ('actions ' , ['index ' , 'does-not-exist ' ], false );
8493 $ this ->Controller ->setResponse ($ this ->Controller ->getResponse ()->withHeader ('Location ' , '' ));
85- $ response = $ this ->Search ->startup ();
94+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
95+ $ this ->Search ->startup ($ event );
96+ $ response = $ event ->getResult ();
97+ $ this ->assertInstanceOf (Response::class, $ response );
8698 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
8799
88100 $ this ->Search ->setConfig ('actions ' , true );
@@ -93,16 +105,23 @@ public function testInitializePost()
93105 'type ' => 'open ' ,
94106 'pass ' => ['open ' ],
95107 ])
96- ->withRequestTarget ('/users/my-predictions ' );
108+ ->withRequestTarget ('/users/my-predictions ' )
109+ ->withData ('foo ' , 'bar ' );
97110 $ this ->Controller ->setRequest ($ request );
98111
99112 $ this ->Controller ->setResponse ($ this ->Controller ->getResponse ()->withHeader ('Location ' , '' ));
100- $ response = $ this ->Search ->startup ();
113+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
114+ $ this ->Search ->startup ($ event );
115+ $ response = $ event ->getResult ();
116+ $ this ->assertInstanceOf (Response::class, $ response );
101117 $ this ->assertEquals ('http://localhost/users/my-predictions?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
102118
103119 $ this ->Controller ->setRequest ($ this ->Controller ->getRequest ()->withData ('foo ' , '' ));
104120 $ this ->Controller ->setResponse ($ this ->Controller ->getResponse ()->withHeader ('Location ' , '' ));
105- $ response = $ this ->Search ->startup ();
121+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
122+ $ this ->Search ->startup ($ event );
123+ $ response = $ event ->getResult ();
124+ $ this ->assertInstanceOf (Response::class, $ response );
106125 $ this ->assertEquals ('http://localhost/users/my-predictions ' , $ response ->getHeaderLine ('Location ' ));
107126 }
108127
@@ -123,11 +142,15 @@ public function testInitializePostWithEmptyValues()
123142 ->withEnv ('REQUEST_METHOD ' , 'POST ' );
124143
125144 $ this ->Controller ->setRequest ($ request );
145+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
126146
127147 $ this ->Search ->configShallow ('emptyValues ' , [
128148 'checkbox ' => '0 ' ,
129149 ]);
130- $ response = $ this ->Search ->startup ();
150+ $ this ->Search ->startup ($ event );
151+ $ response = $ event ->getResult ();
152+
153+ $ this ->assertInstanceOf (Response::class, $ response );
131154 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
132155 }
133156
@@ -148,13 +171,17 @@ public function testInitializePostWithEmptyValuesCallable()
148171 ->withEnv ('REQUEST_METHOD ' , 'POST ' );
149172
150173 $ this ->Controller ->setRequest ($ request );
174+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
151175
152176 $ this ->Search ->configShallow ('emptyValues ' , [
153177 'checkbox ' => function ($ value , array $ params ): bool {
154178 return $ value === '0 ' ;
155179 },
156180 ]);
157- $ response = $ this ->Search ->startup ();
181+ $ this ->Search ->startup ($ event );
182+ $ response = $ event ->getResult ();
183+
184+ $ this ->assertInstanceOf (Response::class, $ response );
158185 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
159186 }
160187
@@ -179,8 +206,11 @@ public function testInitializePostWithQueryStringWhitelist()
179206 ->withEnv ('REQUEST_METHOD ' , 'POST ' );
180207
181208 $ this ->Controller ->setRequest ($ request );
209+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
210+ $ this ->Search ->startup ($ event );
211+ $ response = $ event ->getResult ();
182212
183- $ response = $ this ->Search -> startup ( );
213+ $ this ->assertInstanceOf (Response::class, $ response );
184214 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar&sort=created&direction=desc ' , $ response ->getHeaderLine ('Location ' ));
185215 }
186216
@@ -207,9 +237,13 @@ public function testInitializePostWithNestedQueryString()
207237 ->withEnv ('REQUEST_METHOD ' , 'POST ' );
208238
209239 $ this ->Controller ->setRequest ($ request );
240+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
210241
211242 $ this ->Search ->configShallow ('queryStringWhitelist ' , ['scope.sort ' , 'scope.direction ' ]);
212- $ response = $ this ->Search ->startup ();
243+ $ this ->Search ->startup ($ event );
244+ $ response = $ event ->getResult ();
245+
246+ $ this ->assertInstanceOf (Response::class, $ response );
213247 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar&scope%5Bsort%5D=created&scope%5Bdirection%5D=desc ' , $ response ->getHeaderLine ('Location ' ));
214248 }
215249
@@ -237,7 +271,10 @@ public function testInitializePostWithQueryStringWhitelistEmpty()
237271
238272 // Needed as config() would not do anything here due to internal default behavior of merging here
239273 $ this ->Search ->configShallow ('queryStringWhitelist ' , []);
240- $ response = $ this ->Search ->startup ();
274+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
275+ $ this ->Search ->startup ($ event );
276+ $ response = $ event ->getResult ();
277+ $ this ->assertInstanceOf (Response::class, $ response );
241278 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
242279 }
243280
@@ -257,8 +294,11 @@ public function testConversionWithRedirect()
257294 ->withEnv ('REQUEST_METHOD ' , 'POST ' );
258295
259296 $ this ->Controller ->setRequest ($ request );
297+ $ event = new Event ('Controller.startup ' , $ this ->Controller );
298+ $ this ->Search ->startup ($ event );
299+ $ response = $ event ->getResult ();
260300
261- $ response = $ this ->Search -> startup ( );
301+ $ this ->assertInstanceOf (Response::class, $ response );
262302 $ this ->assertEquals ('http://localhost/Posts/index/pass?foo=bar ' , $ response ->getHeaderLine ('Location ' ));
263303 }
264304
0 commit comments