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