@@ 135-224 (lines=90) @@ | ||
132 | ; |
|
133 | } |
|
134 | ||
135 | public function testGenerateAbsoluteURIs() |
|
136 | { |
|
137 | $collection = new OffsetRepresentation( |
|
138 | new CollectionRepresentation( |
|
139 | array( |
|
140 | 'Adrien', |
|
141 | 'William', |
|
142 | ), |
|
143 | 'authors', |
|
144 | 'users' |
|
145 | ), |
|
146 | '/authors', |
|
147 | array( |
|
148 | 'query' => 'willdurand/Hateoas', |
|
149 | ), |
|
150 | 44, |
|
151 | 20, |
|
152 | 95, |
|
153 | null, |
|
154 | null, |
|
155 | true // force absolute URIs |
|
156 | ); |
|
157 | ||
158 | $this |
|
159 | ->string($this->hateoas->serialize($collection, 'xml')) |
|
160 | ->isEqualTo( |
|
161 | <<<XML |
|
162 | <?xml version="1.0" encoding="UTF-8"?> |
|
163 | <collection offset="44" limit="20" total="95"> |
|
164 | <users rel="authors"> |
|
165 | <entry><![CDATA[Adrien]]></entry> |
|
166 | <entry><![CDATA[William]]></entry> |
|
167 | </users> |
|
168 | <link rel="self" href="http://example.com/authors?query=willdurand%2FHateoas&offset=44&limit=20"/> |
|
169 | <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&limit=20"/> |
|
170 | <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&offset=80&limit=20"/> |
|
171 | <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&offset=64&limit=20"/> |
|
172 | <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&offset=24&limit=20"/> |
|
173 | </collection> |
|
174 | ||
175 | XML |
|
176 | ) |
|
177 | ->string($this->halHateoas->serialize($collection, 'xml')) |
|
178 | ->isEqualTo( |
|
179 | <<<XML |
|
180 | <?xml version="1.0" encoding="UTF-8"?> |
|
181 | <collection offset="44" limit="20" total="95" href="http://example.com/authors?query=willdurand%2FHateoas&offset=44&limit=20"> |
|
182 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
|
183 | <resource rel="authors"><![CDATA[William]]></resource> |
|
184 | <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&limit=20"/> |
|
185 | <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&offset=80&limit=20"/> |
|
186 | <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&offset=64&limit=20"/> |
|
187 | <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&offset=24&limit=20"/> |
|
188 | </collection> |
|
189 | ||
190 | XML |
|
191 | ) |
|
192 | ->string($this->halHateoas->serialize($collection, 'json')) |
|
193 | ->isEqualTo( |
|
194 | '{' |
|
195 | .'"offset":44,' |
|
196 | .'"limit":20,' |
|
197 | .'"total":95,' |
|
198 | .'"_links":{' |
|
199 | .'"self":{' |
|
200 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=44&limit=20"' |
|
201 | .'},' |
|
202 | .'"first":{' |
|
203 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&limit=20"' |
|
204 | .'},' |
|
205 | .'"last":{' |
|
206 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=80&limit=20"' |
|
207 | .'},' |
|
208 | .'"next":{' |
|
209 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=64&limit=20"' |
|
210 | .'},' |
|
211 | .'"previous":{' |
|
212 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=24&limit=20"' |
|
213 | .'}' |
|
214 | .'},' |
|
215 | .'"_embedded":{' |
|
216 | .'"authors":[' |
|
217 | .'"Adrien",' |
|
218 | .'"William"' |
|
219 | .']' |
|
220 | .'}' |
|
221 | .'}' |
|
222 | ) |
|
223 | ; |
|
224 | } |
|
225 | ||
226 | public function testExclusion() |
|
227 | { |
@@ 137-226 (lines=90) @@ | ||
134 | ; |
|
135 | } |
|
136 | ||
137 | public function testGenerateAbsoluteURIs() |
|
138 | { |
|
139 | $collection = new PaginatedRepresentation( |
|
140 | new CollectionRepresentation( |
|
141 | array( |
|
142 | 'Adrien', |
|
143 | 'William', |
|
144 | ), |
|
145 | 'authors', |
|
146 | 'users' |
|
147 | ), |
|
148 | '/authors', |
|
149 | array( |
|
150 | 'query' => 'willdurand/Hateoas', |
|
151 | ), |
|
152 | 3, |
|
153 | 20, |
|
154 | 17, |
|
155 | null, |
|
156 | null, |
|
157 | true // force absolute URIs |
|
158 | ); |
|
159 | ||
160 | $this |
|
161 | ->string($this->hateoas->serialize($collection, 'xml')) |
|
162 | ->isEqualTo( |
|
163 | <<<XML |
|
164 | <?xml version="1.0" encoding="UTF-8"?> |
|
165 | <collection page="3" limit="20" pages="17"> |
|
166 | <users rel="authors"> |
|
167 | <entry><![CDATA[Adrien]]></entry> |
|
168 | <entry><![CDATA[William]]></entry> |
|
169 | </users> |
|
170 | <link rel="self" href="http://example.com/authors?query=willdurand%2FHateoas&page=3&limit=20"/> |
|
171 | <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
|
172 | <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
|
173 | <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
|
174 | <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
|
175 | </collection> |
|
176 | ||
177 | XML |
|
178 | ) |
|
179 | ->string($this->halHateoas->serialize($collection, 'xml')) |
|
180 | ->isEqualTo( |
|
181 | <<<XML |
|
182 | <?xml version="1.0" encoding="UTF-8"?> |
|
183 | <collection page="3" limit="20" pages="17" href="http://example.com/authors?query=willdurand%2FHateoas&page=3&limit=20"> |
|
184 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
|
185 | <resource rel="authors"><![CDATA[William]]></resource> |
|
186 | <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
|
187 | <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
|
188 | <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
|
189 | <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
|
190 | </collection> |
|
191 | ||
192 | XML |
|
193 | ) |
|
194 | ->string($this->halHateoas->serialize($collection, 'json')) |
|
195 | ->isEqualTo( |
|
196 | '{' |
|
197 | .'"page":3,' |
|
198 | .'"limit":20,' |
|
199 | .'"pages":17,' |
|
200 | .'"_links":{' |
|
201 | .'"self":{' |
|
202 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=3&limit=20"' |
|
203 | .'},' |
|
204 | .'"first":{' |
|
205 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=1&limit=20"' |
|
206 | .'},' |
|
207 | .'"last":{' |
|
208 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=17&limit=20"' |
|
209 | .'},' |
|
210 | .'"next":{' |
|
211 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=4&limit=20"' |
|
212 | .'},' |
|
213 | .'"previous":{' |
|
214 | .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&page=2&limit=20"' |
|
215 | .'}' |
|
216 | .'},' |
|
217 | .'"_embedded":{' |
|
218 | .'"authors":[' |
|
219 | .'"Adrien",' |
|
220 | .'"William"' |
|
221 | .']' |
|
222 | .'}' |
|
223 | .'}' |
|
224 | ) |
|
225 | ; |
|
226 | } |
|
227 | } |
|
228 |