| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- /**
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://cakephp.org CakePHP(tm) Project
- * @since 3.0.0
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Routing;
- use Cake\Event\Event;
- use Cake\Network\Request;
- use Cake\Network\Response;
- use Cake\Routing\DispatcherFilter;
- use Cake\TestSuite\TestCase;
- /**
- * Dispatcher filter test.
- */
- class DispatcherFilterTest extends TestCase {
- /**
- * Test that the constructor takes config.
- *
- * @return void
- */
- public function testConstructConfig() {
- $filter = new DispatcherFilter(['one' => 'value', 'on' => '/blog']);
- $this->assertEquals('value', $filter->config('one'));
- }
- /**
- * Test constructor error invalid when
- *
- * @expectedException Cake\Error\Exception
- * @expectedExceptionMessage "when" conditions must be a callable.
- * @return void
- */
- public function testConstructorInvalidWhen() {
- new DispatcherFilter(['when' => 'nope']);
- }
- /**
- * Test basic matching with for option.
- *
- * @return void
- */
- public function testMatchesWithFor() {
- $request = new Request(['url' => '/articles/view']);
- $event = new Event('Dispatcher.beforeDispatch', $this, compact('request'));
- $filter = new DispatcherFilter(['for' => '/articles']);
- $this->assertTrue($filter->matches($event));
- $request = new Request(['url' => '/blog/articles']);
- $event = new Event('Dispatcher.beforeDispatch', $this, compact('request'));
- $this->assertFalse($filter->matches($event), 'Does not start with /articles');
- }
- /**
- * Test matching with when option.
- *
- * @return void
- */
- public function testMatchesWithWhen() {
- $matcher = function ($request, $response) {
- $this->assertInstanceOf('Cake\Network\Request', $request);
- $this->assertInstanceOf('Cake\Network\Response', $response);
- return true;
- };
- $request = new Request(['url' => '/articles/view']);
- $response = new Response();
- $event = new Event('Dispatcher.beforeDispatch', $this, compact('response', 'request'));
- $filter = new DispatcherFilter(['when' => $matcher]);
- $this->assertTrue($filter->matches($event));
- $matcher = function() {
- return false;
- };
- $filter = new DispatcherFilter(['when' => $matcher]);
- $this->assertFalse($filter->matches($event));
- }
- /**
- * Test matching with for & when option.
- *
- * @return void
- */
- public function testMatchesWithForAndWhen() {
- $request = new Request(['url' => '/articles/view']);
- $response = new Response();
- $matcher = function () {
- return true;
- };
- $event = new Event('Dispatcher.beforeDispatch', $this, compact('response', 'request'));
- $filter = new DispatcherFilter(['for' => '/admin', 'when' => $matcher]);
- $this->assertFalse($filter->matches($event));
- $filter = new DispatcherFilter(['for' => '/articles', 'when' => $matcher]);
- $this->assertTrue($filter->matches($event));
- $matcher = function() {
- return false;
- };
- $filter = new DispatcherFilter(['for' => '/admin', 'when' => $matcher]);
- $this->assertFalse($filter->matches($event));
- $filter = new DispatcherFilter(['for' => '/articles', 'when' => $matcher]);
- $this->assertFalse($filter->matches($event));
- }
- /**
- * Test matching with when option.
- *
- * @expectedException \RuntimeException
- * @expectedExceptionMessage 'when' conditions must be a callable.
- * @return void
- */
- public function testMatchesWithWhenInvalid() {
- $this->markTestIncomplete('not done');
- }
- /**
- * Test event bindings have use condition checker
- *
- * @return void
- */
- public function testImplementedEventsMethodName() {
- $this->markTestIncomplete('not done');
- }
- /**
- * Test handle applies for conditions
- *
- * @return void
- */
- public function testHandleAppliesFor() {
- $this->markTestIncomplete('not done');
- }
- /**
- * Test handle applies when conditions
- *
- * @return void
- */
- public function testHandleAppliesWhen() {
- $this->markTestIncomplete('not done');
- }
- }
|