PageRenderTime 138ms CodeModel.GetById 51ms app.highlight 33ms RepoModel.GetById 47ms app.codeStats 1ms

/tests/Zend/Controller/FrontTest.php

https://bitbucket.org/ksekar/campus
PHP | 711 lines | 486 code | 100 blank | 125 comment | 5 complexity | 7c7db4a845adfca7eefea0cc26b833b6 MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Controller
 17 * @subpackage UnitTests
 18 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: FrontTest.php 24594 2012-01-05 21:27:01Z matthew $
 21 */
 22
 23// Call Zend_Controller_FrontTest::main() if this source file is executed directly.
 24if (!defined("PHPUnit_MAIN_METHOD")) {
 25    define("PHPUnit_MAIN_METHOD", "Zend_Controller_FrontTest::main");
 26
 27    $basePath = realpath(dirname(__FILE__) . str_repeat(DIRECTORY_SEPARATOR . '..', 3));
 28
 29    set_include_path(
 30        $basePath . DIRECTORY_SEPARATOR . 'tests'
 31        . PATH_SEPARATOR . $basePath . DIRECTORY_SEPARATOR . 'library'
 32        . PATH_SEPARATOR . get_include_path()
 33    );
 34}
 35
 36
 37require_once 'Zend/Controller/Front.php';
 38require_once 'Zend/Controller/Request/Http.php';
 39require_once 'Zend/Controller/Response/Cli.php';
 40require_once 'Zend/Controller/Dispatcher/Standard.php';
 41require_once 'Zend/Controller/Router/Rewrite.php';
 42require_once 'Zend/Controller/Action/HelperBroker.php';
 43require_once 'Zend/Controller/Action/Helper/Url.php';
 44require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
 45
 46/**
 47 * @category   Zend
 48 * @package    Zend_Controller
 49 * @subpackage UnitTests
 50 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 51 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 52 * @group      Zend_Controller
 53 * @group      Zend_Controller_Front
 54 */
 55class Zend_Controller_FrontTest extends PHPUnit_Framework_TestCase
 56{
 57    protected $_controller = null;
 58
 59    /**
 60     * Runs the test methods of this class.
 61     *
 62     * @access public
 63     * @static
 64     */
 65    public static function main()
 66    {
 67
 68        $suite  = new PHPUnit_Framework_TestSuite("Zend_Controller_FrontTest");
 69        $result = PHPUnit_TextUI_TestRunner::run($suite);
 70    }
 71
 72    public function setUp()
 73    {
 74        $this->_controller = Zend_Controller_Front::getInstance();
 75        $this->_controller->resetInstance();
 76        $this->_controller->setControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files')
 77                          ->setParam('noErrorHandler', true)
 78                          ->setParam('noViewRenderer', true)
 79                          ->returnResponse(true)
 80                          ->throwExceptions(false);
 81        Zend_Controller_Action_HelperBroker::resetHelpers();
 82    }
 83
 84    public function tearDown()
 85    {
 86        unset($this->_controller);
 87    }
 88
 89    public function testResetInstance()
 90    {
 91        $this->_controller->setParam('foo', 'bar');
 92        $this->assertEquals('bar', $this->_controller->getParam('foo'));
 93
 94        $this->_controller->resetInstance();
 95        $this->assertNull($this->_controller->getParam('bar'));
 96        $this->assertSame(array(), $this->_controller->getParams());
 97        $this->assertSame(array(), $this->_controller->getControllerDirectory());
 98    }
 99
100    /**
101     * @see ZF-3145
102     */
103    public function testResetInstanceShouldResetHelperBroker()
104    {
105        Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer());
106        Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_Url());
107        $helpers = Zend_Controller_Action_HelperBroker::getExistingHelpers();
108        $this->assertTrue(is_array($helpers));
109        $this->assertFalse(empty($helpers));
110
111        $this->_controller->resetInstance();
112        $helpers = Zend_Controller_Action_HelperBroker::getExistingHelpers();
113        $this->assertTrue(is_array($helpers));
114        $this->assertTrue(empty($helpers));
115    }
116
117    public function testSetGetRequest()
118    {
119        $request = new Zend_Controller_Request_Http();
120        $this->_controller->setRequest($request);
121        $this->assertTrue($request === $this->_controller->getRequest());
122
123        $this->_controller->resetInstance();
124        $this->_controller->setRequest('Zend_Controller_Request_Http');
125        $request = $this->_controller->getRequest();
126        $this->assertTrue($request instanceof Zend_Controller_Request_Http);
127    }
128
129    public function testSetRequestThrowsExceptionWithBadRequest()
130    {
131        try {
132            $this->_controller->setRequest('Zend_Controller_Response_Cli');
133            $this->fail('Should not be able to set invalid request class');
134        } catch (Exception $e) {
135            // success
136        }
137    }
138
139    public function testSetGetResponse()
140    {
141        $response = new Zend_Controller_Response_Cli();
142        $this->_controller->setResponse($response);
143        $this->assertTrue($response === $this->_controller->getResponse());
144
145        $this->_controller->resetInstance();
146        $this->_controller->setResponse('Zend_Controller_Response_Cli');
147        $response = $this->_controller->getResponse();
148        $this->assertTrue($response instanceof Zend_Controller_Response_Cli);
149    }
150
151    public function testSetResponseThrowsExceptionWithBadResponse()
152    {
153        try {
154            $this->_controller->setResponse('Zend_Controller_Request_Http');
155            $this->fail('Should not be able to set invalid response class');
156        } catch (Exception $e) {
157            // success
158        }
159    }
160
161    public function testSetGetRouter()
162    {
163        $router = new Zend_Controller_Router_Rewrite();
164        $this->_controller->setRouter($router);
165        $this->assertTrue($router === $this->_controller->getRouter());
166
167        $this->_controller->resetInstance();
168        $this->_controller->setRouter('Zend_Controller_Router_Rewrite');
169        $router = $this->_controller->getRouter();
170        $this->assertTrue($router instanceof Zend_Controller_Router_Rewrite);
171    }
172
173    public function testSetRouterThrowsExceptionWithBadRouter()
174    {
175        try {
176            $this->_controller->setRouter('Zend_Controller_Request_Http');
177            $this->fail('Should not be able to set invalid router class');
178        } catch (Exception $e) {
179            // success
180        }
181    }
182
183    public function testSetGetDispatcher()
184    {
185        $dispatcher = new Zend_Controller_Dispatcher_Standard();
186        $this->_controller->setDispatcher($dispatcher);
187
188        $this->assertTrue($dispatcher === $this->_controller->getDispatcher());
189    }
190
191    public function testSetGetControllerDirectory()
192    {
193        $test = $this->_controller->getControllerDirectory();
194        $expected = array('default' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
195        $this->assertSame($expected, $test);
196    }
197
198    public function testGetSetParam()
199    {
200        $this->_controller->setParam('foo', 'bar');
201        $this->assertEquals('bar', $this->_controller->getParam('foo'));
202
203        $this->_controller->setParam('bar', 'baz');
204        $this->assertEquals('baz', $this->_controller->getParam('bar'));
205    }
206
207    public function testGetSetParams()
208    {
209        $this->_controller->setParams(array('foo' => 'bar'));
210        $params = $this->_controller->getParams();
211        $this->assertTrue(isset($params['foo']));
212        $this->assertEquals('bar', $params['foo']);
213
214        $this->_controller->setParam('baz', 'bat');
215        $params = $this->_controller->getParams();
216        $this->assertTrue(isset($params['foo']));
217        $this->assertEquals('bar', $params['foo']);
218        $this->assertTrue(isset($params['baz']));
219        $this->assertEquals('bat', $params['baz']);
220
221        $this->_controller->setParams(array('foo' => 'bug'));
222        $params = $this->_controller->getParams();
223        $this->assertTrue(isset($params['foo']));
224        $this->assertEquals('bug', $params['foo']);
225        $this->assertTrue(isset($params['baz']));
226        $this->assertEquals('bat', $params['baz']);
227    }
228
229    public function testClearParams()
230    {
231        $this->_controller->setParams(array('foo' => 'bar', 'baz' => 'bat'));
232        $params = $this->_controller->getParams();
233        $this->assertTrue(isset($params['foo']));
234        $this->assertTrue(isset($params['baz']));
235
236        $this->_controller->clearParams('foo');
237        $params = $this->_controller->getParams();
238        $this->assertFalse(isset($params['foo']));
239        $this->assertTrue(isset($params['baz']));
240
241        $this->_controller->clearParams();
242        $this->assertSame(array(), $this->_controller->getParams());
243
244        $this->_controller->setParams(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'bat'));
245        $this->assertSame(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'bat'), $this->_controller->getParams());
246        $this->_controller->clearParams(array('foo', 'baz'));
247        $this->assertSame(array('bar' => 'baz'), $this->_controller->getParams());
248    }
249
250    public function testSetGetDefaultControllerName()
251    {
252        $this->assertEquals('index', $this->_controller->getDefaultControllerName());
253
254        $this->_controller->setDefaultControllerName('foo');
255        $this->assertEquals('foo', $this->_controller->getDefaultControllerName());
256    }
257
258    public function testSetGetDefaultAction()
259    {
260        $this->assertEquals('index', $this->_controller->getDefaultAction());
261
262        $this->_controller->setDefaultAction('bar');
263        $this->assertEquals('bar', $this->_controller->getDefaultAction());
264    }
265
266    /**
267     * Test default action on valid controller
268     */
269    public function testDispatch()
270    {
271        $request = new Zend_Controller_Request_Http('http://example.com/index');
272        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
273        $response = $this->_controller->dispatch($request);
274
275        $this->assertContains('Index action called', $response->getBody());
276    }
277
278    /**
279     * Test valid action on valid controller
280     */
281    public function testDispatch1()
282    {
283        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
284        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
285        $response = $this->_controller->dispatch($request);
286
287        $this->assertContains('Index action called', $response->getBody());
288    }
289
290    /**
291     * Test invalid action on valid controller
292     */
293    /*
294    public function testDispatch2()
295    {
296        $request = new Zend_Controller_Request_Http('http://example.com/index/foo');
297
298        try {
299            $this->_controller->dispatch($request);
300            $this->fail('Exception should be raised by __call');
301        } catch (Exception $e) {
302            // success
303        }
304    }
305     */
306
307    /**
308     * Test invalid controller
309     */
310    /*
311    public function testDispatch3()
312    {
313        $request = new Zend_Controller_Request_Http('http://example.com/baz');
314
315        try {
316            $this->_controller->dispatch($request);
317            $this->fail('Exception should be raised; no such controller');
318        } catch (Exception $e) {
319            // success
320        }
321    }
322     */
323
324    /**
325     * Test valid action on valid controller; test pre/postDispatch
326     */
327    public function testDispatch4()
328    {
329        $request = new Zend_Controller_Request_Http('http://example.com/foo/bar');
330        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
331        $response = $this->_controller->dispatch($request);
332
333        $body = $response->getBody();
334        $this->assertContains('Bar action called', $body, $body);
335        $this->assertContains('preDispatch called', $body, $body);
336        $this->assertContains('postDispatch called', $body, $body);
337    }
338
339    /**
340     * Test that extra arguments get passed
341     */
342    public function testDispatch5()
343    {
344        $request = new Zend_Controller_Request_Http('http://example.com/index/args');
345        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
346        $this->_controller->setParam('foo', 'bar');
347        $this->_controller->setParam('baz', 'bat');
348        $response = $this->_controller->dispatch($request);
349
350        $body = $response->getBody();
351        $this->assertContains('foo: bar', $body, $body);
352        $this->assertContains('baz: bat', $body);
353    }
354
355    /**
356     * Test using router
357     */
358    public function testDispatch6()
359    {
360        $request = new Zend_Controller_Request_Http('http://framework.zend.com/foo/bar/var1/baz');
361        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
362        $this->_controller->setRouter(new Zend_Controller_Router_Rewrite());
363        $response = $this->_controller->dispatch($request);
364
365        $body = $response->getBody();
366        $this->assertContains('Bar action called', $body);
367        $params = $request->getParams();
368        $this->assertTrue(isset($params['var1']));
369        $this->assertEquals('baz', $params['var1']);
370    }
371
372    /**
373     * Test without router, using GET params
374     */
375    public function testDispatch7()
376    {
377        if ('cli' == strtolower(php_sapi_name())) {
378            $this->markTestSkipped('Issues with $_GET in CLI interface prevents test from passing');
379        }
380        $request = new Zend_Controller_Request_Http('http://framework.zend.com/index.php?controller=foo&action=bar');
381
382        $response = new Zend_Controller_Response_Cli();
383        $response = $this->_controller->dispatch($request, $response);
384
385        $body = $response->getBody();
386        $this->assertContains('Bar action called', $body);
387    }
388
389    /**
390     * Test that run() throws exception when called from object instance
391     */
392    public function _testRunThrowsException()
393    {
394        try {
395            $this->_controller->run(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
396            $this->fail('Should not be able to call run() from object instance');
397        } catch (Exception $e) {
398            // success
399        }
400    }
401
402    /**
403     * Test that set/getBaseUrl() functionality works
404     */
405    public function testSetGetBaseUrl()
406    {
407        $this->assertNull($this->_controller->getBaseUrl());
408        $this->_controller->setBaseUrl('/index.php');
409        $this->assertEquals('/index.php', $this->_controller->getBaseUrl());
410    }
411
412    public function testSetGetBaseUrlPopulatesRequest()
413    {
414        $request = new Zend_Controller_Request_Http();
415        $this->_controller->setRequest($request);
416        $this->_controller->setBaseUrl('/index.php');
417        $this->assertEquals('/index.php', $request->getBaseUrl());
418
419        $this->assertEquals($request->getBaseUrl(), $this->_controller->getBaseUrl());
420    }
421
422    public function testSetBaseUrlThrowsExceptionOnNonString()
423    {
424        try {
425            $this->_controller->setBaseUrl(array());
426            $this->fail('Should not be able to set non-string base URL');
427        } catch (Exception $e) {
428            // success
429        }
430    }
431
432    /**
433     * Test that a set base URL is pushed to the request during the dispatch
434     * process
435     */
436    public function testBaseUrlPushedToRequest()
437    {
438        $this->_controller->setBaseUrl('/index.php');
439        $request  = new Zend_Controller_Request_Http('http://example.com/index');
440        $response = new Zend_Controller_Response_Cli();
441        $response = $this->_controller->dispatch($request, $response);
442
443        $this->assertContains('index.php', $request->getBaseUrl());
444    }
445
446    /**
447     * Test that throwExceptions() sets and returns value properly
448     */
449    public function testThrowExceptions()
450    {
451        $this->_controller->throwExceptions(true);
452        $this->assertTrue($this->_controller->throwExceptions());
453        $this->_controller->throwExceptions(false);
454        $this->assertFalse($this->_controller->throwExceptions());
455    }
456
457    public function testThrowExceptionsFluentInterface()
458    {
459        $result = $this->_controller->throwExceptions(true);
460        $this->assertSame($this->_controller, $result);
461    }
462
463    /**
464     * Test that with throwExceptions() set, an exception is thrown
465     */
466    public function testThrowExceptionsThrows()
467    {
468        $this->_controller->throwExceptions(true);
469        $this->_controller->setControllerDirectory(dirname(__FILE__));
470        $request = new Zend_Controller_Request_Http('http://framework.zend.com/bogus/baz');
471        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
472        $this->_controller->setRouter(new Zend_Controller_Router_Rewrite());
473
474        try {
475            $response = $this->_controller->dispatch($request);
476            $this->fail('Invalid controller should throw exception');
477        } catch (Exception $e) {
478            // success
479        }
480    }
481
482    /**
483     * Test that returnResponse() sets and returns value properly
484     */
485    public function testReturnResponse()
486    {
487        $this->_controller->returnResponse(true);
488        $this->assertTrue($this->_controller->returnResponse());
489        $this->_controller->returnResponse(false);
490        $this->assertFalse($this->_controller->returnResponse());
491    }
492
493    public function testReturnResponseFluentInterface()
494    {
495        $result = $this->_controller->returnResponse(true);
496        $this->assertSame($this->_controller, $result);
497    }
498
499    /**
500     * Test that with returnResponse set to false, output is echoed and equals that in the response
501     */
502    public function testReturnResponseReturnsResponse()
503    {
504        $request = new Zend_Controller_Request_Http('http://framework.zend.com/foo/bar/var1/baz');
505        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
506        $this->_controller->setRouter(new Zend_Controller_Router_Rewrite());
507        $this->_controller->returnResponse(false);
508
509        ob_start();
510        $this->_controller->dispatch($request);
511        $body = ob_get_clean();
512
513        $actual = $this->_controller->getResponse()->getBody();
514        $this->assertContains($actual, $body);
515    }
516
517    public function testRunStatically()
518    {
519        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
520        $this->_controller->setRequest($request);
521        Zend_Controller_Front::run(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
522    }
523
524    public function testRunDynamically()
525    {
526        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
527        $this->_controller->setRequest($request);
528        $this->_controller->run(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
529    }
530
531    public function testModulePathDispatched()
532    {
533        $this->_controller->addControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . '/Admin', 'admin');
534        $request = new Zend_Controller_Request_Http('http://example.com/admin/foo/bar');
535        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
536        $response = $this->_controller->dispatch($request);
537
538        $body = $response->getBody();
539        $this->assertContains('Admin_Foo::bar action called', $body, $body);
540    }
541
542    public function testModuleControllerDirectoryName()
543    {
544        $this->assertEquals('controllers', $this->_controller->getModuleControllerDirectoryName());
545        $this->_controller->setModuleControllerDirectoryName('foobar');
546        $this->assertEquals('foobar', $this->_controller->getModuleControllerDirectoryName());
547    }
548
549    public function testAddModuleDirectory()
550    {
551        $moduleDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules';
552        $this->_controller->addModuleDirectory($moduleDir);
553        $controllerDirs = $this->_controller->getControllerDirectory();
554        $this->assertTrue(isset($controllerDirs['foo']));
555        $this->assertTrue(isset($controllerDirs['bar']));
556        $this->assertTrue(isset($controllerDirs['default']));
557        $this->assertFalse(isset($controllerDirs['.svn']));
558
559        $this->assertContains('modules' . DIRECTORY_SEPARATOR . 'foo', $controllerDirs['foo']);
560        $this->assertContains('modules' . DIRECTORY_SEPARATOR . 'bar', $controllerDirs['bar']);
561        $this->assertContains('modules' . DIRECTORY_SEPARATOR . 'default', $controllerDirs['default']);
562    }
563
564    /**#@+
565     * @see ZF-2910
566     */
567    public function testShouldAllowRetrievingCurrentModuleDirectory()
568    {
569        $this->testAddModuleDirectory();
570        $request = new Zend_Controller_Request_Http();
571        $request->setModuleName('bar');
572        $this->_controller->setRequest($request);
573        $dir = $this->_controller->getModuleDirectory();
574        $this->assertContains('modules' . DIRECTORY_SEPARATOR . 'bar', $dir);
575        $this->assertNotContains('controllers', $dir);
576    }
577
578    public function testShouldAllowRetrievingSpecifiedModuleDirectory()
579    {
580        $this->testAddModuleDirectory();
581        $dir = $this->_controller->getModuleDirectory('foo');
582        $this->assertContains('modules' . DIRECTORY_SEPARATOR . 'foo', $dir);
583        $this->assertNotContains('controllers', $dir);
584    }
585
586    public function testShouldReturnNullWhenRetrievingNonexistentModuleDirectory()
587    {
588        $this->testAddModuleDirectory();
589        $this->assertNull($this->_controller->getModuleDirectory('bogus-foo-bar'));
590    }
591    /**#@-*/
592
593    /**
594     * ZF-2435
595     */
596    public function testCanRemoveIndividualModuleDirectory()
597    {
598        $moduleDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules';
599        $this->_controller->addModuleDirectory($moduleDir);
600        $controllerDirs = $this->_controller->getControllerDirectory();
601        $this->_controller->removeControllerDirectory('foo');
602        $test = $this->_controller->getControllerDirectory();
603        $this->assertNotEquals($controllerDirs, $test);
604        $this->assertFalse(array_key_exists('foo', $test));
605    }
606
607    public function testAddModuleDirectoryThrowsExceptionForInvalidDirectory()
608    {
609        $moduleDir = 'doesntexist';
610        try {
611            $this->_controller->addModuleDirectory($moduleDir);
612            $this->fail('Exception expected but not thrown');
613        }catch(Exception $e){
614            $this->assertType('Zend_Exception',$e);
615            $this->assertRegExp('/Directory \w+ not readable/',$e->getMessage());
616        }
617    }
618
619    public function testGetControllerDirectoryByModuleName()
620    {
621        $moduleDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules';
622        $this->_controller->addModuleDirectory($moduleDir);
623        $barDir = $this->_controller->getControllerDirectory('bar');
624        $this->assertNotNull($barDir);
625        $this->assertContains('modules' . DIRECTORY_SEPARATOR . 'bar', $barDir);
626    }
627
628    public function testGetControllerDirectoryByModuleNameReturnsNullOnBadModule()
629    {
630        $moduleDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules';
631        $this->_controller->addModuleDirectory($moduleDir);
632        $dir = $this->_controller->getControllerDirectory('_bazbat');
633        $this->assertNull($dir);
634    }
635
636    public function testDefaultModule()
637    {
638        $dispatcher = $this->_controller->getDispatcher();
639        $this->assertEquals($dispatcher->getDefaultModule(), $this->_controller->getDefaultModule());
640        $this->_controller->setDefaultModule('foobar');
641        $this->assertEquals('foobar', $this->_controller->getDefaultModule());
642        $this->assertEquals($dispatcher->getDefaultModule(), $this->_controller->getDefaultModule());
643    }
644
645    public function testErrorHandlerPluginRegisteredWhenDispatched()
646    {
647        $this->assertFalse($this->_controller->hasPlugin('Zend_Controller_Plugin_ErrorHandler'));
648        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
649        $this->_controller->setParam('noErrorHandler', false)
650                          ->setResponse(new Zend_Controller_Response_Cli());
651        $response = $this->_controller->dispatch($request);
652
653        $this->assertTrue($this->_controller->hasPlugin('Zend_Controller_Plugin_ErrorHandler'));
654    }
655
656    public function testErrorHandlerPluginNotRegisteredIfNoErrorHandlerSet()
657    {
658        $this->assertFalse($this->_controller->hasPlugin('Zend_Controller_Plugin_ErrorHandler'));
659        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
660        $this->_controller->setParam('noErrorHandler', true)
661                          ->setResponse(new Zend_Controller_Response_Cli());
662        $response = $this->_controller->dispatch($request);
663
664        $this->assertFalse($this->_controller->hasPlugin('Zend_Controller_Plugin_ErrorHandler'));
665    }
666
667    public function testReplaceRequestAndResponseMidStream()
668    {
669        $request = new Zend_Controller_Request_Http('http://example.com/index/replace');
670        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
671        $response = new Zend_Controller_Response_Http();
672        $responsePost = $this->_controller->dispatch($request, $response);
673
674        $requestPost  = $this->_controller->getRequest();
675
676        $this->assertNotSame($request, $requestPost);
677        $this->assertNotSame($response, $responsePost);
678
679        $this->assertContains('Reset action called', $responsePost->getBody());
680        $this->assertNotContains('Reset action called', $response->getBody());
681    }
682
683    public function testViewRendererHelperRegisteredWhenDispatched()
684    {
685        $this->assertFalse(Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer'));
686        $this->_controller->setParam('noViewRenderer', false);
687
688        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
689        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
690        $response = $this->_controller->dispatch($request);
691
692        $this->assertTrue(Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer'));
693    }
694
695    public function testViewRendererHelperNotRegisteredIfNoViewRendererSet()
696    {
697        $this->assertFalse(Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer'));
698        $this->_controller->setParam('noViewRenderer', true);
699
700        $request = new Zend_Controller_Request_Http('http://example.com/index/index');
701        $this->_controller->setResponse(new Zend_Controller_Response_Cli());
702        $response = $this->_controller->dispatch($request);
703
704        $this->assertFalse(Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer'));
705    }
706}
707
708// Call Zend_Controller_FrontTest::main() if this source file is executed directly.
709if (PHPUnit_MAIN_METHOD == "Zend_Controller_FrontTest::main") {
710    Zend_Controller_FrontTest::main();
711}