1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Effortless maintenance management (http://juliangut.com/janitor) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/juliangut/janitor for the canonical source repository |
6
|
|
|
* |
7
|
|
|
* @license https://github.com/juliangut/janitor/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Janitor\Test\Excluder; |
11
|
|
|
|
12
|
|
|
use Janitor\Excluder\Path; |
13
|
|
|
use Zend\Diactoros\ServerRequestFactory; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \Janitor\Excluder\Path |
17
|
|
|
*/ |
18
|
|
|
class PathTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
protected $excludedPaths = [ |
21
|
|
|
'/user', |
22
|
|
|
'/^\/blog\/.+/', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @covers \Janitor\Excluder\Path::__construct |
27
|
|
|
* @covers \Janitor\Excluder\Path::addPath |
28
|
|
|
* @covers \Janitor\Excluder\Path::isExcluded |
29
|
|
|
*/ |
30
|
|
|
public function testIsExcludedByString() |
31
|
|
|
{ |
32
|
|
|
$request = ServerRequestFactory::fromGlobals(); |
33
|
|
|
$excluder = new Path($this->excludedPaths); |
34
|
|
|
|
35
|
|
|
$this->assertTrue($excluder->isExcluded($request->withUri($request->getUri()->withPath('/user')))); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers \Janitor\Excluder\Path::__construct |
40
|
|
|
* @covers \Janitor\Excluder\Path::addPath |
41
|
|
|
* @covers \Janitor\Excluder\Path::isExcluded |
42
|
|
|
*/ |
43
|
|
|
public function testIsExcludedByRegex() |
44
|
|
|
{ |
45
|
|
|
$request = ServerRequestFactory::fromGlobals(); |
46
|
|
|
$excluder = new Path($this->excludedPaths); |
47
|
|
|
|
48
|
|
|
$this->assertTrue($excluder->isExcluded($request->withUri($request->getUri()->withPath('/blog/post')))); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers \Janitor\Excluder\Path::isExcluded |
53
|
|
|
*/ |
54
|
|
|
public function testIsNotExcluded() |
55
|
|
|
{ |
56
|
|
|
$request = ServerRequestFactory::fromGlobals(); |
57
|
|
|
$excluder = new Path($this->excludedPaths); |
58
|
|
|
|
59
|
|
|
$this->assertFalse($excluder->isExcluded($request->withUri($request->getUri()->withPath('/home')))); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|