DispatcherFactoryTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Routing;
  16. use Cake\Routing\DispatcherFactory;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * Dispatcher factory test case.
  20. */
  21. class DispatcherFactoryTest extends TestCase {
  22. /**
  23. * setup function
  24. *
  25. * @return void
  26. */
  27. public function setUp() {
  28. parent::setUp();
  29. DispatcherFactory::clear();
  30. }
  31. /**
  32. * Test add filter
  33. *
  34. * @return void
  35. */
  36. public function testAddFilter() {
  37. $mw = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch']);
  38. $result = DispatcherFactory::add($mw);
  39. $this->assertSame($mw, $result);
  40. }
  41. /**
  42. * Test add filter as a string
  43. *
  44. * @return void
  45. */
  46. public function testAddFilterString() {
  47. $result = DispatcherFactory::add('Routing');
  48. $this->assertInstanceOf('Cake\Routing\Filter\RoutingFilter', $result);
  49. }
  50. /**
  51. * Test add filter missing
  52. *
  53. * @expectedException Cake\Routing\Error\MissingDispatcherFilterException
  54. * @return void
  55. */
  56. public function testAddFilterMissing() {
  57. DispatcherFactory::add('NopeSauce');
  58. }
  59. /**
  60. * Test add filter
  61. *
  62. * @return void
  63. */
  64. public function testAddFilterWithOptions() {
  65. $config = ['config' => 'value', 'priority' => 999];
  66. $result = DispatcherFactory::add('Routing', $config);
  67. $this->assertInstanceOf('Cake\Routing\Filter\RoutingFilter', $result);
  68. $this->assertEquals($config['config'], $result->config('config'));
  69. $this->assertEquals($config['priority'], $result->config('priority'));
  70. }
  71. /**
  72. * Test creating a dispatcher with the factory
  73. *
  74. * @return void
  75. */
  76. public function testCreate() {
  77. $mw = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch']);
  78. DispatcherFactory::add($mw);
  79. $result = DispatcherFactory::create();
  80. $this->assertInstanceOf('Cake\Routing\Dispatcher', $result);
  81. $this->assertCount(1, $result->filters());
  82. }
  83. }