DispatcherFactoryTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /**
  24. * setup function
  25. *
  26. * @return void
  27. */
  28. public function setUp()
  29. {
  30. parent::setUp();
  31. DispatcherFactory::clear();
  32. }
  33. /**
  34. * Test add filter
  35. *
  36. * @return void
  37. */
  38. public function testAddFilter()
  39. {
  40. $mw = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch']);
  41. $result = DispatcherFactory::add($mw);
  42. $this->assertSame($mw, $result);
  43. }
  44. /**
  45. * Test add filter as a string
  46. *
  47. * @return void
  48. */
  49. public function testAddFilterString()
  50. {
  51. $result = DispatcherFactory::add('Routing');
  52. $this->assertInstanceOf('Cake\Routing\Filter\RoutingFilter', $result);
  53. }
  54. /**
  55. * Test add filter missing
  56. *
  57. * @expectedException \Cake\Routing\Exception\MissingDispatcherFilterException
  58. * @return void
  59. */
  60. public function testAddFilterMissing()
  61. {
  62. DispatcherFactory::add('NopeSauce');
  63. }
  64. /**
  65. * Test add filter
  66. *
  67. * @return void
  68. */
  69. public function testAddFilterWithOptions()
  70. {
  71. $config = ['config' => 'value', 'priority' => 999];
  72. $result = DispatcherFactory::add('Routing', $config);
  73. $this->assertInstanceOf('Cake\Routing\Filter\RoutingFilter', $result);
  74. $this->assertEquals($config['config'], $result->config('config'));
  75. $this->assertEquals($config['priority'], $result->config('priority'));
  76. }
  77. /**
  78. * Test creating a dispatcher with the factory
  79. *
  80. * @return void
  81. */
  82. public function testCreate()
  83. {
  84. $mw = $this->getMock('Cake\Routing\DispatcherFilter', ['beforeDispatch']);
  85. DispatcherFactory::add($mw);
  86. $result = DispatcherFactory::create();
  87. $this->assertInstanceOf('Cake\Routing\Dispatcher', $result);
  88. $this->assertCount(1, $result->filters());
  89. }
  90. }