2
0

StandardTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. // Call Zend_Controller_Dispatcher_StandardTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_Controller_Dispatcher_StandardTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. require_once 'Zend/Controller/Dispatcher/Standard.php';
  8. require_once 'Zend/Controller/Action/HelperBroker.php';
  9. require_once 'Zend/Controller/Front.php';
  10. require_once 'Zend/Controller/Request/Http.php';
  11. require_once 'Zend/Controller/Request/Simple.php';
  12. require_once 'Zend/Controller/Response/Cli.php';
  13. class Zend_Controller_Dispatcher_StandardTest extends PHPUnit_Framework_TestCase
  14. {
  15. protected $_dispatcher;
  16. /**
  17. * Runs the test methods of this class.
  18. *
  19. * @access public
  20. * @static
  21. */
  22. public static function main()
  23. {
  24. $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Dispatcher_StandardTest");
  25. $result = PHPUnit_TextUI_TestRunner::run($suite);
  26. }
  27. public function setUp()
  28. {
  29. if (isset($this->error)) {
  30. unset($this->error);
  31. }
  32. $front = Zend_Controller_Front::getInstance();
  33. $front->resetInstance();
  34. Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
  35. $this->_dispatcher = new Zend_Controller_Dispatcher_Standard();
  36. $this->_dispatcher->setControllerDirectory(array(
  37. 'default' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files',
  38. 'admin' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Admin'
  39. ));
  40. }
  41. public function tearDown()
  42. {
  43. unset($this->_dispatcher);
  44. }
  45. public function testFormatControllerName()
  46. {
  47. $this->assertEquals('IndexController', $this->_dispatcher->formatControllerName('index'));
  48. $this->assertEquals('Site_CustomController', $this->_dispatcher->formatControllerName('site_custom'));
  49. }
  50. public function testFormatActionName()
  51. {
  52. $this->assertEquals('indexAction', $this->_dispatcher->formatActionName('index'));
  53. $this->assertEquals('myindexAction', $this->_dispatcher->formatActionName('myIndex'));
  54. $this->assertEquals('myindexAction', $this->_dispatcher->formatActionName('my_index'));
  55. $this->assertEquals('myIndexAction', $this->_dispatcher->formatActionName('my.index'));
  56. $this->assertEquals('myIndexAction', $this->_dispatcher->formatActionName('my-index'));
  57. }
  58. public function testSetGetControllerDirectory()
  59. {
  60. $expected = array(
  61. 'default' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files',
  62. 'admin' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Admin'
  63. );
  64. $dirs = $this->_dispatcher->getControllerDirectory();
  65. $this->assertEquals($expected, $dirs);
  66. }
  67. public function testIsDispatchable()
  68. {
  69. $request = new Zend_Controller_Request_Http();
  70. $this->assertFalse($this->_dispatcher->isDispatchable($request));
  71. $request->setControllerName('index');
  72. $this->assertTrue($this->_dispatcher->isDispatchable($request));
  73. $request->setControllerName('foo');
  74. $this->assertTrue($this->_dispatcher->isDispatchable($request));
  75. // True, because it will dispatch to default controller
  76. $request->setControllerName('bogus');
  77. $this->assertFalse($this->_dispatcher->isDispatchable($request));
  78. }
  79. public function testModuleIsDispatchable()
  80. {
  81. $request = new Zend_Controller_Request_Http();
  82. $request->setModuleName('admin');
  83. $request->setControllerName('foo');
  84. $request->setActionName('bar');
  85. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  86. $request->setModuleName('bogus');
  87. $request->setControllerName('bogus');
  88. $request->setActionName('bar');
  89. $this->assertFalse($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  90. }
  91. public function testSetGetResponse()
  92. {
  93. $response = new Zend_Controller_Response_Cli();
  94. $this->_dispatcher->setResponse($response);
  95. $this->assertTrue($response === $this->_dispatcher->getResponse());
  96. }
  97. public function testSetGetDefaultControllerName()
  98. {
  99. $this->assertEquals('index', $this->_dispatcher->getDefaultControllerName());
  100. $this->_dispatcher->setDefaultControllerName('foo');
  101. $this->assertEquals('foo', $this->_dispatcher->getDefaultControllerName());
  102. }
  103. public function testSetGetDefaultAction()
  104. {
  105. $this->assertEquals('index', $this->_dispatcher->getDefaultAction());
  106. $this->_dispatcher->setDefaultAction('bar');
  107. $this->assertEquals('bar', $this->_dispatcher->getDefaultAction());
  108. }
  109. public function testDispatchValidControllerDefaultAction()
  110. {
  111. $request = new Zend_Controller_Request_Http();
  112. $request->setControllerName('index');
  113. $response = new Zend_Controller_Response_Cli();
  114. $this->_dispatcher->dispatch($request, $response);
  115. $this->assertContains('Index action called', $this->_dispatcher->getResponse()->getBody());
  116. }
  117. public function testDispatchValidControllerAndAction()
  118. {
  119. $request = new Zend_Controller_Request_Http();
  120. $request->setControllerName('index');
  121. $request->setActionName('index');
  122. $response = new Zend_Controller_Response_Cli();
  123. $this->_dispatcher->dispatch($request, $response);
  124. $this->assertContains('Index action called', $this->_dispatcher->getResponse()->getBody());
  125. }
  126. public function testDispatchValidControllerWithInvalidAction()
  127. {
  128. $request = new Zend_Controller_Request_Http();
  129. $request->setControllerName('index');
  130. $request->setActionName('foo');
  131. $response = new Zend_Controller_Response_Cli();
  132. try {
  133. $this->_dispatcher->dispatch($request, $response);
  134. $this->fail('Exception should be raised by __call');
  135. } catch (Exception $e) {
  136. // success
  137. }
  138. }
  139. public function testDispatchInvalidController()
  140. {
  141. $request = new Zend_Controller_Request_Http();
  142. $request->setControllerName('bogus');
  143. $response = new Zend_Controller_Response_Cli();
  144. try {
  145. $this->_dispatcher->dispatch($request, $response);
  146. $this->fail('Exception should be raised; no such controller');
  147. } catch (Exception $e) {
  148. // success
  149. }
  150. }
  151. public function testDispatchInvalidControllerUsingDefaults()
  152. {
  153. $request = new Zend_Controller_Request_Http();
  154. $request->setControllerName('bogus');
  155. $response = new Zend_Controller_Response_Cli();
  156. $this->_dispatcher->setParam('useDefaultControllerAlways', true);
  157. try {
  158. $this->_dispatcher->dispatch($request, $response);
  159. $this->assertEquals('index', $request->getControllerName());
  160. $this->assertEquals('index', $request->getActionName());
  161. } catch (Exception $e) {
  162. $this->fail('Exception should not be raised when useDefaultControllerAlways set; message: ' . $e->getMessage());
  163. }
  164. }
  165. /**
  166. * @group ZF-3465
  167. */
  168. public function testUsingDefaultControllerAlwaysShouldRewriteActionNameToDefault()
  169. {
  170. $request = new Zend_Controller_Request_Http();
  171. $request->setControllerName('bogus');
  172. $request->setActionName('really');
  173. $request->setParam('action', 'really'); // router sets action as a param
  174. $response = new Zend_Controller_Response_Cli();
  175. $this->_dispatcher->setParam('useDefaultControllerAlways', true);
  176. try {
  177. $this->_dispatcher->dispatch($request, $response);
  178. } catch (Zend_Controller_Dispatcher_Exception $e) {
  179. $this->fail('Exception should not be raised when useDefaultControllerAlways set; message: ' . $e->getMessage());
  180. }
  181. $this->assertEquals('index', $request->getControllerName());
  182. $this->assertEquals('index', $request->getActionName());
  183. }
  184. public function testDispatchInvalidControllerUsingDefaultsWithDefaultModule()
  185. {
  186. $request = new Zend_Controller_Request_Http();
  187. $request->setControllerName('bogus')
  188. ->setModuleName('default');
  189. $response = new Zend_Controller_Response_Cli();
  190. $this->_dispatcher->setParam('useDefaultControllerAlways', true);
  191. try {
  192. $this->_dispatcher->dispatch($request, $response);
  193. $this->assertSame('default', $request->getModuleName());
  194. $this->assertSame('index', $request->getControllerName());
  195. $this->assertSame('index', $request->getActionName());
  196. } catch (Exception $e) {
  197. $this->fail('Exception should not be raised when useDefaultControllerAlways set; exception: ' . $e->getMessage());
  198. }
  199. }
  200. public function testDispatchValidControllerWithPrePostDispatch()
  201. {
  202. $request = new Zend_Controller_Request_Http();
  203. $request->setControllerName('foo');
  204. $request->setActionName('bar');
  205. $response = new Zend_Controller_Response_Cli();
  206. $this->_dispatcher->dispatch($request, $response);
  207. $body = $this->_dispatcher->getResponse()->getBody();
  208. $this->assertContains('Bar action called', $body);
  209. $this->assertContains('preDispatch called', $body);
  210. $this->assertContains('postDispatch called', $body);
  211. }
  212. public function testDispatchNoControllerUsesDefaults()
  213. {
  214. $request = new Zend_Controller_Request_Http();
  215. $response = new Zend_Controller_Response_Cli();
  216. $this->_dispatcher->dispatch($request, $response);
  217. $this->assertEquals('index', $request->getControllerName());
  218. $this->assertEquals('index', $request->getActionName());
  219. }
  220. /**
  221. * Tests ZF-637 -- action names with underscores not being correctly changed to camelCase
  222. */
  223. public function testZf637()
  224. {
  225. $test = $this->_dispatcher->formatActionName('view_entry');
  226. $this->assertEquals('viewentryAction', $test);
  227. }
  228. public function testWordDelimiter()
  229. {
  230. $this->assertEquals(array('-', '.'), $this->_dispatcher->getWordDelimiter());
  231. $this->_dispatcher->setWordDelimiter(':');
  232. $this->assertEquals(array(':'), $this->_dispatcher->getWordDelimiter());
  233. }
  234. public function testPathDelimiter()
  235. {
  236. $this->assertEquals('_', $this->_dispatcher->getPathDelimiter());
  237. $this->_dispatcher->setPathDelimiter(':');
  238. $this->assertEquals(':', $this->_dispatcher->getPathDelimiter());
  239. }
  240. /**
  241. * Test that classes are found in modules, using a prefix
  242. */
  243. public function testModules()
  244. {
  245. $request = new Zend_Controller_Request_Http();
  246. $request->setModuleName('admin');
  247. $request->setControllerName('foo');
  248. $request->setActionName('bar');
  249. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  250. $response = new Zend_Controller_Response_Cli();
  251. $this->_dispatcher->dispatch($request, $response);
  252. $body = $this->_dispatcher->getResponse()->getBody();
  253. $this->assertContains("Admin_Foo::bar action called", $body, $body);
  254. }
  255. public function testModuleControllerInSubdirWithCamelCaseAction()
  256. {
  257. $request = new Zend_Controller_Request_Http();
  258. $request->setModuleName('admin');
  259. $request->setControllerName('foo-bar');
  260. $request->setActionName('baz.bat');
  261. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  262. $response = new Zend_Controller_Response_Cli();
  263. $this->_dispatcher->dispatch($request, $response);
  264. $body = $this->_dispatcher->getResponse()->getBody();
  265. $this->assertContains("Admin_FooBar::bazBat action called", $body, $body);
  266. }
  267. public function testUseModuleDefaultController()
  268. {
  269. $this->_dispatcher->setDefaultControllerName('foo')
  270. ->setParam('useDefaultControllerAlways', true);
  271. $request = new Zend_Controller_Request_Http();
  272. $request->setModuleName('admin');
  273. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  274. $response = new Zend_Controller_Response_Cli();
  275. $this->_dispatcher->dispatch($request, $response);
  276. $body = $this->_dispatcher->getResponse()->getBody();
  277. $this->assertContains("Admin_Foo::index action called", $body, $body);
  278. }
  279. public function testNoModuleOrControllerDefaultsCorrectly()
  280. {
  281. $request = new Zend_Controller_Request_Http('http://example.com/');
  282. $this->assertFalse($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  283. $response = new Zend_Controller_Response_Cli();
  284. $this->_dispatcher->dispatch($request, $response);
  285. $body = $this->_dispatcher->getResponse()->getBody();
  286. $this->assertContains("Index action called", $body, $body);
  287. }
  288. public function testOutputBuffering()
  289. {
  290. $request = new Zend_Controller_Request_Http();
  291. $request->setControllerName('ob');
  292. $request->setActionName('index');
  293. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  294. $response = new Zend_Controller_Response_Cli();
  295. $this->_dispatcher->dispatch($request, $response);
  296. $body = $this->_dispatcher->getResponse()->getBody();
  297. $this->assertContains("OB index action called", $body, $body);
  298. }
  299. public function testDisableOutputBuffering()
  300. {
  301. if (!defined('TESTS_ZEND_CONTROLLER_DISPATCHER_OB') || !TESTS_ZEND_CONTROLLER_DISPATCHER_OB) {
  302. $this->markTestSkipped('Skipping output buffer disabling in Zend_Controller_Dispatcher_Standard');
  303. }
  304. $request = new Zend_Controller_Request_Http();
  305. $request->setControllerName('ob');
  306. $request->setActionName('index');
  307. $this->_dispatcher->setParam('disableOutputBuffering', true);
  308. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  309. $response = new Zend_Controller_Response_Cli();
  310. $this->_dispatcher->dispatch($request, $response);
  311. $body = $this->_dispatcher->getResponse()->getBody();
  312. $this->assertEquals('', $body, $body);
  313. }
  314. public function testModuleSubdirControllerFound()
  315. {
  316. Zend_Controller_Front::getInstance()
  317. ->setDispatcher($this->_dispatcher)
  318. ->addControllerDirectory(
  319. dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'controllers',
  320. 'foo'
  321. );
  322. $request = new Zend_Controller_Request_Http();
  323. $request->setModuleName('foo');
  324. $request->setControllerName('admin_index');
  325. $request->setActionName('index');
  326. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  327. $response = new Zend_Controller_Response_Cli();
  328. $this->_dispatcher->dispatch($request, $response);
  329. $body = $this->_dispatcher->getResponse()->getBody();
  330. $this->assertContains("Foo_Admin_IndexController::indexAction() called", $body, $body);
  331. }
  332. public function testDefaultModule()
  333. {
  334. $this->assertEquals('default', $this->_dispatcher->getDefaultModule());
  335. $this->_dispatcher->setDefaultModule('foobar');
  336. $this->assertEquals('foobar', $this->_dispatcher->getDefaultModule());
  337. }
  338. public function testModuleValid()
  339. {
  340. $this->assertTrue($this->_dispatcher->isValidModule('default'));
  341. $this->assertTrue($this->_dispatcher->isValidModule('admin'));
  342. $this->assertFalse($this->_dispatcher->isValidModule('bogus'));
  343. $this->assertFalse($this->_dispatcher->isValidModule(null));
  344. $this->assertFalse($this->_dispatcher->isValidModule($this));
  345. $this->assertFalse($this->_dispatcher->isValidModule(array()));
  346. }
  347. /**
  348. * @see ZF-3034
  349. */
  350. public function testIsValidModuleShouldNormalizeModuleName()
  351. {
  352. $this->assertTrue($this->_dispatcher->isValidModule('Admin'));
  353. }
  354. public function testSanelyDiscardOutputBufferOnException()
  355. {
  356. $request = new Zend_Controller_Request_Http();
  357. $request->setControllerName('ob');
  358. $request->setActionName('exception');
  359. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  360. $response = new Zend_Controller_Response_Cli();
  361. try {
  362. $this->_dispatcher->dispatch($request, $response);
  363. $this->fail('Exception should have been rethrown');
  364. } catch (Exception $e) {
  365. }
  366. $body = $this->_dispatcher->getResponse()->getBody();
  367. $this->assertNotContains("In exception action", $body, $body);
  368. $this->assertNotContains("Foo", $body, $body);
  369. }
  370. public function testGetDefaultControllerClassResetsRequestObject()
  371. {
  372. $request = new Zend_Controller_Request_Http();
  373. $request->setModuleName('foobar')
  374. ->setControllerName('bazbatbegone')
  375. ->setActionName('bebop');
  376. $this->_dispatcher->getDefaultControllerClass($request);
  377. $this->assertEquals($this->_dispatcher->getDefaultModule(), $request->getModuleName());
  378. $this->assertEquals($this->_dispatcher->getDefaultControllerName(), $request->getControllerName());
  379. $this->assertNull($request->getActionName());
  380. }
  381. public function testLoadClassLoadsControllerInDefaultModuleWithoutModulePrefix()
  382. {
  383. $request = new Zend_Controller_Request_Simple();
  384. $request->setControllerName('empty');
  385. $class = $this->_dispatcher->getControllerClass($request);
  386. $this->assertEquals('EmptyController', $class);
  387. $test = $this->_dispatcher->loadClass($class);
  388. $this->assertEquals($class, $test);
  389. $this->assertTrue(class_exists($class));
  390. }
  391. public function testLoadClassLoadsControllerInSpecifiedModuleWithModulePrefix()
  392. {
  393. Zend_Controller_Front::getInstance()
  394. ->setDispatcher($this->_dispatcher)
  395. ->addModuleDirectory(dirname(__FILE__) . '/../_files/modules');
  396. $request = new Zend_Controller_Request_Simple();
  397. $request->setControllerName('index')
  398. ->setModuleName('bar');
  399. $class = $this->_dispatcher->getControllerClass($request);
  400. $this->assertEquals('IndexController', $class);
  401. $test = $this->_dispatcher->loadClass($class);
  402. $this->assertEquals('Bar_IndexController', $test);
  403. $this->assertTrue(class_exists($test));
  404. }
  405. public function testLoadClassLoadsControllerInDefaultModuleWithModulePrefixWhenRequested()
  406. {
  407. Zend_Controller_Front::getInstance()
  408. ->setDispatcher($this->_dispatcher)
  409. ->addModuleDirectory(dirname(__FILE__) . '/../_files/modules');
  410. $this->_dispatcher->setDefaultModule('foo')
  411. ->setParam('prefixDefaultModule', true);
  412. $request = new Zend_Controller_Request_Simple();
  413. $request->setControllerName('index');
  414. $class = $this->_dispatcher->getControllerClass($request);
  415. $this->assertEquals('IndexController', $class);
  416. $test = $this->_dispatcher->loadClass($class);
  417. $this->assertEquals('Foo_IndexController', $test);
  418. $this->assertTrue(class_exists($test));
  419. }
  420. /**
  421. * ZF-2435
  422. */
  423. public function testCanRemoveControllerDirectory()
  424. {
  425. Zend_Controller_Front::getInstance()
  426. ->setDispatcher($this->_dispatcher)
  427. ->addModuleDirectory(dirname(__FILE__) . '/../_files/modules');
  428. $dirs = $this->_dispatcher->getControllerDirectory();
  429. $this->_dispatcher->removeControllerDirectory('foo');
  430. $test = $this->_dispatcher->getControllerDirectory();
  431. $this->assertNotEquals($dirs, $test);
  432. $this->assertFalse(array_key_exists('foo', $test));
  433. }
  434. /**
  435. * ZF-2693
  436. */
  437. public function testCamelCasedActionsNotRequestedWithWordSeparatorsShouldNotResolve()
  438. {
  439. $request = new Zend_Controller_Request_Http();
  440. $request->setModuleName('admin');
  441. $request->setControllerName('foo-bar');
  442. $request->setActionName('bazBat');
  443. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  444. $response = new Zend_Controller_Response_Cli();
  445. try {
  446. $this->_dispatcher->dispatch($request, $response);
  447. $this->fail('Invalid camelCased action should raise exception');
  448. } catch (Zend_Controller_Exception $e) {
  449. $this->assertContains('does not exist', $e->getMessage());
  450. }
  451. }
  452. /**
  453. * ZF-2693
  454. */
  455. public function testCamelCasedActionsNotRequestedWithWordSeparatorsShouldResolveIfForced()
  456. {
  457. $this->_dispatcher->setParam('useCaseSensitiveActions', true);
  458. $request = new Zend_Controller_Request_Http();
  459. $request->setModuleName('admin');
  460. $request->setControllerName('foo-bar');
  461. $request->setActionName('bazBat');
  462. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  463. $response = new Zend_Controller_Response_Cli();
  464. $oldLevel = error_reporting(0);
  465. try {
  466. $this->_dispatcher->dispatch($request, $response);
  467. $body = $this->_dispatcher->getResponse()->getBody();
  468. error_reporting($oldLevel);
  469. $this->assertContains("Admin_FooBar::bazBat action called", $body, $body);
  470. } catch (Zend_Controller_Exception $e) {
  471. error_reporting($oldLevel);
  472. $this->fail('camelCased actions should succeed when forced');
  473. }
  474. }
  475. public function handleErrors($errno, $errstr)
  476. {
  477. $this->error = $errstr;
  478. }
  479. /**
  480. * @see ZF-2693
  481. */
  482. public function testForcingCamelCasedActionsNotRequestedWithWordSeparatorsShouldRaiseNotices()
  483. {
  484. $this->_dispatcher->setParam('useCaseSensitiveActions', true);
  485. $request = new Zend_Controller_Request_Http();
  486. $request->setModuleName('admin');
  487. $request->setControllerName('foo-bar');
  488. $request->setActionName('bazBat');
  489. $this->assertTrue($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
  490. $response = new Zend_Controller_Response_Cli();
  491. set_error_handler(array($this, 'handleErrors'));
  492. try {
  493. $this->_dispatcher->dispatch($request, $response);
  494. $body = $this->_dispatcher->getResponse()->getBody();
  495. restore_error_handler();
  496. $this->assertTrue(isset($this->error));
  497. $this->assertContains('deprecated', $this->error);
  498. } catch (Zend_Controller_Exception $e) {
  499. restore_error_handler();
  500. $this->fail('camelCased actions should succeed when forced');
  501. }
  502. }
  503. /**
  504. * @see ZF-2887
  505. */
  506. public function testGetControllerClassThrowsExceptionIfNoDefaultModuleDefined()
  507. {
  508. $this->_dispatcher->setControllerDirectory(array());
  509. $request = new Zend_Controller_Request_Simple();
  510. $request->setControllerName('empty');
  511. try {
  512. $class = $this->_dispatcher->getControllerClass($request);
  513. } catch (Zend_Controller_Exception $e) {
  514. $this->assertContains('No default module', $e->getMessage());
  515. }
  516. }
  517. }
  518. // Call Zend_Controller_Dispatcher_StandardTest::main() if this source file is executed directly.
  519. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Dispatcher_StandardTest::main") {
  520. Zend_Controller_Dispatcher_StandardTest::main();
  521. }