Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement matches() and add in progress test cases.
- Loading branch information
Showing
2 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?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'); | ||
|
||
} | ||
|
||
} |