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