|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Purl\Test; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Purl\Fragment; |
|
9
|
|
|
use Purl\Path; |
|
10
|
|
|
use Purl\Query; |
|
11
|
|
|
|
|
12
|
|
|
class FragmentTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testConstruct() : void |
|
15
|
|
|
{ |
|
16
|
|
|
$fragment = new Fragment('test?param=value'); |
|
17
|
|
|
$this->assertInstanceOf('Purl\Path', $fragment->path); |
|
18
|
|
|
$this->assertInstanceOf('Purl\Query', $fragment->query); |
|
19
|
|
|
$this->assertEquals('test', (string) $fragment->path); |
|
20
|
|
|
$this->assertEquals('param=value', (string) $fragment->query); |
|
21
|
|
|
|
|
22
|
|
|
$path = new Path('test'); |
|
23
|
|
|
$query = new Query('param=value'); |
|
24
|
|
|
$fragment = new Fragment($path, $query); |
|
25
|
|
|
$this->assertEquals('test', (string) $fragment->path); |
|
26
|
|
|
$this->assertEquals('param=value', (string) $fragment->query); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetFragment() : void |
|
30
|
|
|
{ |
|
31
|
|
|
$fragment = new Fragment('test?param=value'); |
|
32
|
|
|
$this->assertEquals('test?param=value', $fragment->getFragment()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testSetFragment() : void |
|
36
|
|
|
{ |
|
37
|
|
|
$fragment = new Fragment('test?param=value'); |
|
38
|
|
|
$this->assertEquals('test?param=value', $fragment->getFragment()); |
|
39
|
|
|
$fragment->setFragment('changed?param=value'); |
|
40
|
|
|
$this->assertEquals('changed?param=value', $fragment->getFragment()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testGetSetPath() : void |
|
44
|
|
|
{ |
|
45
|
|
|
$fragment = new Fragment(); |
|
46
|
|
|
$path = new Path('test'); |
|
47
|
|
|
$fragment->setPath($path); |
|
48
|
|
|
$this->assertSame($path, $fragment->getPath()); |
|
49
|
|
|
$this->assertEquals('test', (string) $fragment); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testGetSetQuery() : void |
|
53
|
|
|
{ |
|
54
|
|
|
$fragment = new Fragment(); |
|
55
|
|
|
$query = new Query('param=value'); |
|
56
|
|
|
$fragment->setQuery($query); |
|
57
|
|
|
$this->assertSame($query, $fragment->getQuery()); |
|
58
|
|
|
$this->assertEquals('?param=value', (string) $fragment); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testToString() : void |
|
62
|
|
|
{ |
|
63
|
|
|
$fragment = new Fragment('test?param=value'); |
|
64
|
|
|
$this->assertEquals('test?param=value', (string) $fragment); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testIsInitialized() : void |
|
68
|
|
|
{ |
|
69
|
|
|
$fragment = new Fragment('test?param=value'); |
|
70
|
|
|
$this->assertFalse($fragment->isInitialized()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testHas() : void |
|
74
|
|
|
{ |
|
75
|
|
|
$fragment = new Fragment('test?param=value'); |
|
76
|
|
|
$fragment->setData(['param' => 'value']); |
|
77
|
|
|
$this->assertTrue($fragment->has('param')); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testRemove() : void |
|
81
|
|
|
{ |
|
82
|
|
|
$fragment = new Fragment('test?param=value'); |
|
83
|
|
|
$fragment->setData(['param' => 'value']); |
|
84
|
|
|
$fragment->remove('param'); |
|
85
|
|
|
$this->assertFalse($fragment->has('param')); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testIsset() : void |
|
89
|
|
|
{ |
|
90
|
|
|
$fragment = new Fragment('test?param=value'); |
|
91
|
|
|
$fragment->setData(['param' => 'value']); |
|
92
|
|
|
$fragment->remove('param'); |
|
93
|
|
|
$this->assertFalse($fragment->has('param')); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testOffsetExists() : void |
|
97
|
|
|
{ |
|
98
|
|
|
$fragment = new Fragment('test?param=value'); |
|
99
|
|
|
$fragment->setData(['param' => 'value']); |
|
100
|
|
|
$this->assertTrue($fragment->offsetExists('param')); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testOffsetGet() : void |
|
104
|
|
|
{ |
|
105
|
|
|
$fragment = new Fragment('test?param=value'); |
|
106
|
|
|
$fragment->setData(['param' => 'value']); |
|
107
|
|
|
$this->assertEquals('value', $fragment->offsetGet('param')); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testOffsetUnset() : void |
|
111
|
|
|
{ |
|
112
|
|
|
$fragment = new Fragment('test?param=value'); |
|
113
|
|
|
$fragment->setData(['param' => 'value']); |
|
114
|
|
|
$fragment->offsetUnset('param'); |
|
115
|
|
|
$this->assertFalse($fragment->offsetExists('param')); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|