1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* micrometa |
5
|
|
|
* |
6
|
|
|
* @category Jkphl |
7
|
|
|
* @package Jkphl\Micrometa |
8
|
|
|
* @subpackage Jkphl\Micrometa\Tests |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2017 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 © 2017 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 Jkphl\Micrometa\Tests\Ports; |
38
|
|
|
|
39
|
|
|
use Jkphl\Micrometa\Application\Factory\PropertyListFactory; |
40
|
|
|
use Jkphl\Micrometa\Application\Item\Item as ApplicationItem; |
41
|
|
|
use Jkphl\Micrometa\Application\Value\StringValue; |
42
|
|
|
use Jkphl\Micrometa\Infrastructure\Factory\ItemFactory; |
43
|
|
|
use Jkphl\Micrometa\Infrastructure\Parser\LinkRel; |
44
|
|
|
use Jkphl\Micrometa\Ports\Item\Item; |
45
|
|
|
use Jkphl\Micrometa\Ports\Item\ItemInterface; |
46
|
|
|
use Jkphl\Micrometa\Ports\Item\ItemObjectModel; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Item object model tests |
50
|
|
|
* |
51
|
|
|
* @package Jkphl\Micrometa |
52
|
|
|
* @subpackage Jkphl\Micrometa\Tests |
53
|
|
|
*/ |
54
|
|
|
class ItemObjectModelTest extends AbstractItemListTest |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Test the item object model |
58
|
|
|
* |
59
|
|
|
* @expectedException \Jkphl\Micrometa\Ports\Exceptions\OutOfBoundsException |
60
|
|
|
* @expectedExceptionCode 1489268571 |
61
|
|
|
*/ |
62
|
|
|
public function testItemObjectModel() |
63
|
|
|
{ |
64
|
|
|
$itemObjectModel = new ItemObjectModel($this->getItems()); |
65
|
|
|
$this->assertInstanceOf(ItemObjectModel::class, $itemObjectModel); |
66
|
|
|
|
67
|
|
|
// Test all LinkRel items |
68
|
|
|
$rels = $itemObjectModel->rel(); |
69
|
|
|
$this->assertEquals(2, count($rels)); |
70
|
|
|
foreach ($rels as $rel) { |
71
|
|
|
$this->assertInstanceOf(ItemInterface::class, $rel); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Test the second LinkRel item |
75
|
|
|
$secondRel = $itemObjectModel->rel(null, 1); |
76
|
|
|
$this->assertInstanceOf(Item::class, $secondRel); |
77
|
|
|
$this->assertEquals( |
78
|
|
|
[ |
79
|
|
|
(object)[ |
80
|
|
|
'name' => 'alternate', |
81
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI |
82
|
|
|
] |
83
|
|
|
], |
84
|
|
|
$secondRel->getType() |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
// Test all stylesheet LinkRel items |
88
|
|
|
$stylesheetRels = $itemObjectModel->rel('stylesheet'); |
89
|
|
|
$this->assertTrue(is_array($stylesheetRels)); |
90
|
|
|
$this->assertEquals(1, count($stylesheetRels)); |
91
|
|
|
$this->assertInstanceOf(Item::class, $stylesheetRels[0]); |
92
|
|
|
$this->assertEquals( |
93
|
|
|
[ |
94
|
|
|
(object)[ |
95
|
|
|
'name' => 'stylesheet', |
96
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI |
97
|
|
|
] |
98
|
|
|
], |
99
|
|
|
$stylesheetRels[0]->getType() |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
// Test the first stylesheet LinkRel item |
103
|
|
|
$firstStylesheetRel = $itemObjectModel->rel('stylesheet', 0); |
104
|
|
|
$this->assertInstanceOf(Item::class, $firstStylesheetRel); |
105
|
|
|
$this->assertEquals( |
106
|
|
|
[ |
107
|
|
|
(object)[ |
108
|
|
|
'name' => 'stylesheet', |
109
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI |
110
|
|
|
] |
111
|
|
|
], |
112
|
|
|
$firstStylesheetRel->getType() |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
// Test an invalid item index |
116
|
|
|
$itemObjectModel->rel('stylesheet', 1); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return a list of 3 items |
121
|
|
|
* |
122
|
|
|
* @return Item[] Items |
123
|
|
|
*/ |
124
|
|
|
protected function getItems() |
125
|
|
|
{ |
126
|
|
|
$items = ItemFactory::createFromApplicationItems( |
127
|
|
|
[ |
128
|
|
|
// Stylesheet rel item |
129
|
|
|
new ApplicationItem( |
130
|
|
|
LinkRel::FORMAT, |
131
|
|
|
new PropertyListFactory(), |
132
|
|
|
(object)['profile' => LinkRel::HTML_PROFILE_URI, 'name' => 'stylesheet'], |
133
|
|
|
[ |
134
|
|
|
(object)[ |
135
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI, |
136
|
|
|
'name' => 'type', |
137
|
|
|
'values' => [ |
138
|
|
|
new StringValue('text/css') |
139
|
|
|
] |
140
|
|
|
], |
141
|
|
|
(object)[ |
142
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI, |
143
|
|
|
'name' => 'href', |
144
|
|
|
'values' => [ |
145
|
|
|
new StringValue('style.css') |
146
|
|
|
] |
147
|
|
|
] |
148
|
|
|
], |
149
|
|
|
[], |
150
|
|
|
'main-stylesheet' |
151
|
|
|
), |
152
|
|
|
|
153
|
|
|
// Atom feed rel item |
154
|
|
|
new ApplicationItem( |
155
|
|
|
LinkRel::FORMAT, |
156
|
|
|
new PropertyListFactory(), |
157
|
|
|
(object)['profile' => LinkRel::HTML_PROFILE_URI, 'name' => 'alternate'], |
158
|
|
|
[ |
159
|
|
|
(object)[ |
160
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI, |
161
|
|
|
'name' => 'type', |
162
|
|
|
'values' => [ |
163
|
|
|
new StringValue('application/atom+xml') |
164
|
|
|
] |
165
|
|
|
], |
166
|
|
|
(object)[ |
167
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI, |
168
|
|
|
'name' => 'href', |
169
|
|
|
'values' => [ |
170
|
|
|
new StringValue('http://example.com/blog.atom') |
171
|
|
|
] |
172
|
|
|
], |
173
|
|
|
(object)[ |
174
|
|
|
'profile' => LinkRel::HTML_PROFILE_URI, |
175
|
|
|
'name' => 'title', |
176
|
|
|
'values' => [ |
177
|
|
|
new StringValue('Atom feed') |
178
|
|
|
] |
179
|
|
|
], |
180
|
|
|
(object)[ |
181
|
|
|
'profile' => 'http://example.com/test-ns', |
182
|
|
|
'name' => 'prop', |
183
|
|
|
'values' => [ |
184
|
|
|
new StringValue('arbitrary') |
185
|
|
|
] |
186
|
|
|
] |
187
|
|
|
], |
188
|
|
|
[], |
189
|
|
|
'main-stylesheet' |
190
|
|
|
), |
191
|
|
|
] |
192
|
|
|
); |
193
|
|
|
|
194
|
|
|
$items[] = $this->getFeedItem(); |
195
|
|
|
|
196
|
|
|
return $items; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|