-
Notifications
You must be signed in to change notification settings - Fork 178
/
URITest.php
109 lines (88 loc) · 2.93 KB
/
URITest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
namespace League\Plates\Tests\Extension;
use League\Plates\Engine;
use League\Plates\Extension\URI;
use PHPUnit\Framework\TestCase;
class URITest extends TestCase
{
private $extension;
protected function setUp(): void
{
$this->extension = new URI('/green/red/blue');
}
public function testCanCreateInstance()
{
$this->assertInstanceOf('League\Plates\Extension\URI', $this->extension);
}
public function testRegister()
{
$engine = new Engine();
$extension = new URI('/green/red/blue');
$extension->register($engine);
$this->assertTrue($engine->doesFunctionExist('uri'));
}
public function testGetUrl()
{
$this->assertTrue($this->extension->runUri() === '/green/red/blue');
}
public function testGetSpecifiedSegment()
{
$this->assertTrue($this->extension->runUri(1) === 'green');
$this->assertTrue($this->extension->runUri(2) === 'red');
$this->assertTrue($this->extension->runUri(3) === 'blue');
}
public function testSegmentMatch()
{
$this->assertTrue($this->extension->runUri(1, 'green'));
$this->assertFalse($this->extension->runUri(1, 'red'));
}
public function testSegmentMatchSuccessResponse()
{
$this->assertTrue($this->extension->runUri(1, 'green', 'success') === 'success');
}
public function testSegmentMatchFailureResponse()
{
$this->assertFalse($this->extension->runUri(1, 'red', 'success'));
}
public function testSegmentMatchFailureCustomResponse()
{
$this->assertTrue($this->extension->runUri(1, 'red', 'success', 'fail') === 'fail');
}
public function testRegexMatch()
{
$this->assertTrue($this->extension->runUri('/[a-z]+/red/blue'));
}
public function testRegexMatchSuccessResponse()
{
$this->assertTrue($this->extension->runUri('/[a-z]+/red/blue', 'success') === 'success');
}
public function testRegexMatchFailureResponse()
{
$this->assertFalse($this->extension->runUri('/[0-9]+/red/blue', 'success'));
}
public function testRegexMatchFailureCustomResponse()
{
$this->assertTrue($this->extension->runUri('/[0-9]+/red/blue', 'success', 'fail') === 'fail');
}
public function testInvalidCall()
{
// Invalid use of the uri function.
$this->expectException(\LogicException::class);
$this->extension->runUri(array());
}
public function testFetchNonExistingUriIndex()
{
$engine = new Engine();
$extension = new URI('/');
$extension->register($engine);
$this->assertTrue(is_null($extension->runUri(2)));
}
public function testComparehNonExistingUriIndex()
{
$engine = new Engine();
$extension = new URI('/hello');
$extension->register($engine);
$this->assertFalse($extension->runUri(2, 'hello'));
}
}