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\Kernel\Ports\Kernel; |
40
|
|
|
use Apparat\Object\Domain\Factory\SelectorFactory; |
41
|
|
|
use Apparat\Object\Domain\Model\Object\Revision; |
42
|
|
|
use Apparat\Object\Domain\Repository\Selector; |
43
|
|
|
use Apparat\Object\Domain\Repository\Selector as RepositorySelector; |
44
|
|
|
use Apparat\Object\Domain\Repository\SelectorInterface; |
45
|
|
|
use Apparat\Object\Ports\Types\Object as ObjectTypes; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Selector tests |
49
|
|
|
* |
50
|
|
|
* @package Apparat\Object |
51
|
|
|
* @subpackage Apparat\Object\Test |
52
|
|
|
*/ |
53
|
|
|
class SelectorTest extends AbstractDisabledAutoconnectorTest |
54
|
|
|
{ |
55
|
|
|
/** |
56
|
|
|
* Test repository selectors |
57
|
|
|
* |
58
|
|
|
* @dataProvider getSelector |
59
|
|
|
* @param string $selector Selector |
60
|
|
|
* @param array $data Data |
61
|
|
|
*/ |
62
|
|
|
public function testFactorySelectors($selector, array $data) |
63
|
|
|
{ |
64
|
|
|
$selector = SelectorFactory::createFromString($selector); |
65
|
|
|
$this->assertInstanceOf(Selector::class, $selector); |
66
|
|
|
$this->assertEquals($data[0], $selector->getYear()); |
67
|
|
|
$this->assertEquals($data[1], $selector->getMonth()); |
68
|
|
|
$this->assertEquals($data[2], $selector->getDay()); |
69
|
|
|
$this->assertEquals($data[3], $selector->getVisibility()); |
70
|
|
|
$this->assertEquals($data[4], $selector->getId()); |
71
|
|
|
$this->assertEquals($data[5], $selector->getType()); |
72
|
|
|
$this->assertEquals($data[6], $selector->getDraft()); |
73
|
|
|
$this->assertEquals($data[7], $selector->getRevision()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Provide selectors |
78
|
|
|
*/ |
79
|
|
|
public function getSelector() |
80
|
|
|
{ |
81
|
|
|
$w = SelectorInterface::WILDCARD; |
82
|
|
|
$v = SelectorInterface::VISIBLE; |
83
|
|
|
$p = SelectorInterface::PUBLISHED; |
84
|
|
|
$a = SelectorInterface::ALL; |
85
|
|
|
$h = SelectorInterface::HIDDEN; |
86
|
|
|
$d = SelectorInterface::DRAFT; |
87
|
|
|
$c = Revision::CURRENT; |
88
|
|
|
return [ |
89
|
|
|
['/2016', ['2016', $w, $w, $v, $w, $w, $p, $c]], |
90
|
|
|
['/*', [$w, $w, $w, $v, $w, $w, $p, $c]], |
91
|
|
|
['/2016/06', ['2016', '06', $w, $v, $w, $w, $p, $c]], |
92
|
|
|
['/2016/*', ['2016', $w, $w, $v, $w, $w, $p, $c]], |
93
|
|
|
['/2016/06/16', ['2016', '06', '16', $v, $w, $w, $p, $c]], |
94
|
|
|
['/2016/06/*', ['2016', '06', $w, $v, $w, $w, $p, $c]], |
95
|
|
|
['/2016/06/16/123', ['2016', '06', '16', $v, 123, $w, $p, $c]], |
96
|
|
|
['/2016/06/16/.123', ['2016', '06', '16', $h, 123, $w, $p, $c]], |
97
|
|
|
['/2016/06/16/~123', ['2016', '06', '16', $a, 123, $w, $p, $c]], |
98
|
|
|
['/2016/06/16/*', ['2016', '06', '16', $v, $w, $w, $p, $c]], |
99
|
|
|
['/2016/06/16/.*', ['2016', '06', '16', $h, $w, $w, $p, $c]], |
100
|
|
|
['/2016/06/16/~*', ['2016', '06', '16', $a, $w, $w, $p, $c]], |
101
|
|
|
['/2016/06/16/123-article', ['2016', '06', '16', $v, 123, 'article', $p, $c]], |
102
|
|
|
['/2016/06/16/123-*', ['2016', '06', '16', $v, 123, $w, $p, $c]], |
103
|
|
|
['/2016/06/16/123-article/123', ['2016', '06', '16', $v, 123, 'article', $p, $c]], |
104
|
|
|
['/2016/06/16/123-article/*', ['2016', '06', '16', $v, 123, 'article', $p, $c]], |
105
|
|
|
['/2016/06/16/123-article/.123', ['2016', '06', '16', $v, 123, 'article', $d, $c]], |
106
|
|
|
['/2016/06/16/123-article/~123', ['2016', '06', '16', $v, 123, 'article', $a, $c]], |
107
|
|
|
['/2016/06/16/123-article/.*', ['2016', '06', '16', $v, 123, 'article', $d, $c]], |
108
|
|
|
['/2016/06/16/123-article/~*', ['2016', '06', '16', $v, 123, 'article', $a, $c]], |
109
|
|
|
['/2016/06/16/123-article/123-99', ['2016', '06', '16', $v, 123, 'article', $p, 99]], |
110
|
|
|
['/2016/06/16/123-article/123-*', ['2016', '06', '16', $v, 123, 'article', $p, $w]], |
111
|
|
|
['/2016/06/16/123-article/.123-99', ['2016', '06', '16', $v, 123, 'article', $h, 99]], |
112
|
|
|
['/2016/06/16/123-article/.123-*', ['2016', '06', '16', $v, 123, 'article', $h, $w]], |
113
|
|
|
['/2016/06/16/123-article/~123-99', ['2016', '06', '16', $v, 123, 'article', $a, 99]], |
114
|
|
|
['/2016/06/16/123-article/~123-*', ['2016', '06', '16', $v, 123, 'article', $a, $w]], |
115
|
|
|
['/*/06/16/123-article/123-99', [$w, '06', '16', $v, 123, 'article', $p, 99]], |
116
|
|
|
['/2016/*/16/123-article/123-99', ['2016', $w, '16', $v, 123, 'article', $p, 99]], |
117
|
|
|
['/2016/06/*/123-article/123-99', ['2016', '06', $w, $v, 123, 'article', $p, 99]], |
118
|
|
|
['/2016/06/16/*-article/*-99', ['2016', '06', '16', $v, $w, 'article', $p, 99]], |
119
|
|
|
['/2016/06/16/123-*/123-99', ['2016', '06', '16', $v, 123, $w, $p, 99]], |
120
|
|
|
['/2016/06/16/123-article/*-99', ['2016', '06', '16', $v, 123, 'article', $p, 99]], |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Test an invalid selector |
126
|
|
|
* |
127
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
128
|
|
|
* @expectedExceptionCode 1449961609 |
129
|
|
|
*/ |
130
|
|
|
public function testFactoryInvalidSelector() |
131
|
|
|
{ |
132
|
|
|
SelectorFactory::createFromString('invalid'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Test an invalid date component |
137
|
|
|
* |
138
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
139
|
|
|
* @expectedExceptionCode 1449999646 |
140
|
|
|
* @expectedExceptionMessageRegExp %year% |
141
|
|
|
*/ |
142
|
|
|
public function testInvalidDateComponent() |
143
|
|
|
{ |
144
|
|
|
Kernel::create(RepositorySelector::class, ['invalid']); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Test an invalid ID component |
149
|
|
|
* |
150
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
151
|
|
|
* @expectedExceptionCode 1449999646 |
152
|
|
|
* @expectedExceptionMessageRegExp %id% |
153
|
|
|
*/ |
154
|
|
|
public function testInvalidIdComponent() |
155
|
|
|
{ |
156
|
|
|
Kernel::create(RepositorySelector::class, [2015, 1, 1, null, null, null, 'invalid']); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Test an invalid type component |
161
|
|
|
* |
162
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
163
|
|
|
* @expectedExceptionCode 1449999646 |
164
|
|
|
* @expectedExceptionMessageRegExp %type% |
165
|
|
|
*/ |
166
|
|
|
public function testInvalidTypeComponent() |
167
|
|
|
{ |
168
|
|
|
Kernel::create( |
169
|
|
|
RepositorySelector::class, |
170
|
|
|
[2015, 1, 1, null, null, null, 1, 'invalid', SelectorInterface::PUBLISHED] |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Test an invalid revision component |
176
|
|
|
* |
177
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
178
|
|
|
* @expectedExceptionCode 1449999646 |
179
|
|
|
* @expectedExceptionMessageRegExp %revision% |
180
|
|
|
*/ |
181
|
|
|
public function testInvalidRevisionComponent() |
182
|
|
|
{ |
183
|
|
|
Kernel::create( |
184
|
|
|
RepositorySelector::class, |
185
|
|
|
[2015, 1, 1, null, null, null, 1, ObjectTypes::ARTICLE, 'invalid', SelectorInterface::PUBLISHED] |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Test an invalid object visibility |
191
|
|
|
* |
192
|
|
|
* @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException |
193
|
|
|
* @expectedExceptionCode 1449999646 |
194
|
|
|
* @expectedExceptionMessageRegExp %visibility% |
195
|
|
|
*/ |
196
|
|
|
public function testInvalidVisibilityComponent() |
197
|
|
|
{ |
198
|
|
|
Kernel::create( |
199
|
|
|
RepositorySelector::class, |
200
|
|
|
[2015, 1, 1, null, null, null, 1, ObjectTypes::ARTICLE, Revision::CURRENT, 0, SelectorInterface::PUBLISHED] |
201
|
|
|
); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|