1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-object |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Object |
8
|
|
|
* @subpackage Apparat\Object\Framwork |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Apparat\Object\Tests; |
38
|
|
|
|
39
|
|
|
use Apparat\Object\Domain\Factory\SelectorFactory; |
40
|
|
|
use Apparat\Object\Domain\Model\Object\Revision; |
41
|
|
|
use Apparat\Object\Domain\Repository\Selector as RepositorySelector; |
42
|
|
|
use Apparat\Object\Domain\Repository\SelectorInterface; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Selector tests |
46
|
|
|
* |
47
|
|
|
* @package Apparat\Object |
48
|
|
|
* @subpackage ApparatTest |
49
|
|
|
*/ |
50
|
|
|
class SelectorTest extends AbstractDisabledAutoconnectorTest |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* Example selector |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
const SELECTOR = '/2015/10/01/36704.event/36704-1'; |
58
|
|
|
/** |
59
|
|
|
* Example selector with hidden object |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
const HIDDEN_SELECTOR = '/2015/10/01/.36704.event/36704-1'; |
64
|
|
|
/** |
65
|
|
|
* Example selector with optionally hidden object |
66
|
|
|
* |
67
|
|
|
* @var string |
68
|
|
|
*/ |
69
|
|
|
const OPTIONAL_HIDDEN_SELECTOR = '/2015/10/01/{.,}36704.event/36704-1'; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test a valid full-fledged selector |
73
|
|
|
*/ |
74
|
|
|
public function testFactoryValidSelector() |
75
|
|
|
{ |
76
|
|
|
$selector = SelectorFactory::createFromString(self::SELECTOR); |
77
|
|
|
$this->assertInstanceOf(RepositorySelector::class, $selector); |
78
|
|
|
$this->assertEquals(2015, $selector->getYear()); |
79
|
|
|
$this->assertEquals(10, $selector->getMonth()); |
80
|
|
|
$this->assertEquals(1, $selector->getDay()); |
81
|
|
|
$this->assertEquals(null, $selector->getHour()); |
82
|
|
|
$this->assertEquals(null, $selector->getMinute()); |
83
|
|
|
$this->assertEquals(null, $selector->getSecond()); |
84
|
|
|
$this->assertEquals(36704, $selector->getId()); |
85
|
|
|
$this->assertEquals('event', $selector->getType()); |
86
|
|
|
$this->assertEquals(1, $selector->getRevision()); |
87
|
|
|
$this->assertEquals(SelectorInterface::VISIBLE, $selector->getVisibility()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Test a valid selector with hidden object |
92
|
|
|
*/ |
93
|
|
|
public function testFactoryHiddenSelector() |
94
|
|
|
{ |
95
|
|
|
$selector = SelectorFactory::createFromString(self::HIDDEN_SELECTOR); |
96
|
|
|
$this->assertEquals(SelectorInterface::HIDDEN, $selector->getVisibility()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Test a valid selector with optionally hidden object |
101
|
|
|
*/ |
102
|
|
|
public function testFactoryOptionallyHiddenSelector() |
103
|
|
|
{ |
104
|
|
|
$selector = SelectorFactory::createFromString(self::OPTIONAL_HIDDEN_SELECTOR); |
105
|
|
|
$this->assertEquals(SelectorInterface::ALL, $selector->getVisibility()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Test a valid full-fledged selector with wildcards |
110
|
|
|
*/ |
111
|
|
|
public function testFactoryValidSelectorWildcards() |
112
|
|
|
{ |
113
|
|
|
$datePrecision = getenv('OBJECT_DATE_PRECISION'); |
114
|
|
|
putenv('OBJECT_DATE_PRECISION=6'); |
115
|
|
|
$selector = SelectorFactory::createFromString('/*/*/*/*/*/*/*.*/*'); |
116
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getYear()); |
117
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getMonth()); |
118
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getDay()); |
119
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getHour()); |
120
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getMinute()); |
121
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getSecond()); |
122
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getId()); |
123
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getType()); |
124
|
|
|
$this->assertEquals(Revision::CURRENT, $selector->getRevision()); |
125
|
|
|
putenv('OBJECT_DATE_PRECISION='.$datePrecision); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Test minimal selector |
130
|
|
|
*/ |
131
|
|
|
public function testFactoryMinimalSelector() |
132
|
|
|
{ |
133
|
|
|
$selector = SelectorFactory::createFromString('/*'); |
134
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getYear()); |
135
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getMonth()); |
136
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getDay()); |
137
|
|
|
$this->assertEquals(null, $selector->getHour()); |
138
|
|
|
$this->assertEquals(null, $selector->getMinute()); |
139
|
|
|
$this->assertEquals(null, $selector->getSecond()); |
140
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getId()); |
141
|
|
|
$this->assertEquals(SelectorInterface::WILDCARD, $selector->getType()); |
142
|
|
|
$this->assertEquals(Revision::CURRENT, $selector->getRevision()); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Test an invalid selector |
147
|
|
|
* |
148
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
149
|
|
|
* @expectedExceptionCode 1449961609 |
150
|
|
|
*/ |
151
|
|
|
public function testFactoryInvalidSelector() |
152
|
|
|
{ |
153
|
|
|
SelectorFactory::createFromString('invalid'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Test an invalid date component |
158
|
|
|
* |
159
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
160
|
|
|
* @expectedExceptionCode 1449999646 |
161
|
|
|
* @expectedExceptionMessageRegExp %year% |
162
|
|
|
*/ |
163
|
|
|
public function testInvalidDateComponent() |
164
|
|
|
{ |
165
|
|
|
new RepositorySelector('invalid'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Test an invalid ID component |
170
|
|
|
* |
171
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
172
|
|
|
* @expectedExceptionCode 1449999646 |
173
|
|
|
* @expectedExceptionMessageRegExp %id% |
174
|
|
|
*/ |
175
|
|
|
public function testInvalidIdComponent() |
176
|
|
|
{ |
177
|
|
|
new RepositorySelector(2015, 1, 1, null, null, null, 'invalid'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Test an invalid type component |
182
|
|
|
* |
183
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
184
|
|
|
* @expectedExceptionCode 1449999646 |
185
|
|
|
* @expectedExceptionMessageRegExp %type% |
186
|
|
|
*/ |
187
|
|
|
public function testInvalidTypeComponent() |
188
|
|
|
{ |
189
|
|
|
new RepositorySelector(2015, 1, 1, null, null, null, 1, 'invalid'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Test an invalid revision component |
194
|
|
|
* |
195
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
196
|
|
|
* @expectedExceptionCode 1449999646 |
197
|
|
|
* @expectedExceptionMessageRegExp %revision% |
198
|
|
|
*/ |
199
|
|
|
public function testInvalidRevisionComponent() |
200
|
|
|
{ |
201
|
|
|
new RepositorySelector(2015, 1, 1, null, null, null, 1, 'event', 'invalid'); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|