@@ -162,4 +162,53 @@ public function testRun404OverrideByClosure()
162
162
163
163
//--------------------------------------------------------------------
164
164
165
+ public function testControllersCanReturnString ()
166
+ {
167
+ $ _SERVER ['argv ' ] = [
168
+ 'index.php ' ,
169
+ 'pages/about ' ,
170
+ ];
171
+ $ _SERVER ['argc ' ] = 2 ;
172
+
173
+ // Inject mock router.
174
+ $ routes = Services::routes ();
175
+ $ routes ->add ('pages/(:segment) ' , function ($ segment )
176
+ {
177
+ return 'You want to see " ' .esc ($ segment ).'" page. ' ;
178
+ });
179
+ $ router = Services::router ($ routes );
180
+ Services::injectMock ('router ' , $ router );
181
+
182
+ ob_start ();
183
+ $ this ->codeigniter ->run ();
184
+ $ output = ob_get_clean ();
185
+
186
+ $ this ->assertContains ('You want to see "about" page. ' , $ output );
187
+ }
188
+
189
+ public function testControllersCanReturnResponseObject ()
190
+ {
191
+ $ _SERVER ['argv ' ] = [
192
+ 'index.php ' ,
193
+ 'pages/about ' ,
194
+ ];
195
+ $ _SERVER ['argc ' ] = 2 ;
196
+
197
+ // Inject mock router.
198
+ $ routes = Services::routes ();
199
+ $ routes ->add ('pages/(:segment) ' , function ($ segment )
200
+ {
201
+ $ response = Services::response ();
202
+ $ string = "You want to see 'about' page. " ;
203
+ return $ response ->setBody ($ string );
204
+ });
205
+ $ router = Services::router ($ routes );
206
+ Services::injectMock ('router ' , $ router );
207
+
208
+ ob_start ();
209
+ $ this ->codeigniter ->run ();
210
+ $ output = ob_get_clean ();
211
+
212
+ $ this ->assertContains ("You want to see 'about' page. " , $ output );
213
+ }
165
214
}
0 commit comments