| @@ 11-138 (lines=128) @@ | ||
| 8 | ||
| 9 | class OffsetRepresentationTest extends RepresentationTestCase |
|
| 10 | { |
|
| 11 | public function testSerialize() |
|
| 12 | { |
|
| 13 | $collection = new OffsetRepresentation( |
|
| 14 | new CollectionRepresentation( |
|
| 15 | array( |
|
| 16 | 'Adrien', |
|
| 17 | 'William', |
|
| 18 | ), |
|
| 19 | 'authors', |
|
| 20 | 'users' |
|
| 21 | ), |
|
| 22 | '/authors', |
|
| 23 | array( |
|
| 24 | 'query' => 'willdurand/Hateoas', |
|
| 25 | ), |
|
| 26 | 44, |
|
| 27 | 20, |
|
| 28 | 95, |
|
| 29 | null, |
|
| 30 | null, |
|
| 31 | false |
|
| 32 | ); |
|
| 33 | ||
| 34 | $this->assertSame( |
|
| 35 | <<<XML |
|
| 36 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 37 | <collection offset="44" limit="20" total="95"> |
|
| 38 | <users rel="authors"> |
|
| 39 | <entry><![CDATA[Adrien]]></entry> |
|
| 40 | <entry><![CDATA[William]]></entry> |
|
| 41 | </users> |
|
| 42 | <link rel="self" href="/authors?query=willdurand%2FHateoas&offset=44&limit=20"/> |
|
| 43 | <link rel="first" href="/authors?query=willdurand%2FHateoas&limit=20"/> |
|
| 44 | <link rel="last" href="/authors?query=willdurand%2FHateoas&offset=80&limit=20"/> |
|
| 45 | <link rel="next" href="/authors?query=willdurand%2FHateoas&offset=64&limit=20"/> |
|
| 46 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&offset=24&limit=20"/> |
|
| 47 | </collection> |
|
| 48 | ||
| 49 | XML |
|
| 50 | , |
|
| 51 | $this->hateoas->serialize($collection, 'xml') |
|
| 52 | ); |
|
| 53 | ||
| 54 | $this->assertSame( |
|
| 55 | <<<XML |
|
| 56 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 57 | <collection offset="44" limit="20" total="95" href="/authors?query=willdurand%2FHateoas&offset=44&limit=20"> |
|
| 58 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
|
| 59 | <resource rel="authors"><![CDATA[William]]></resource> |
|
| 60 | <link rel="first" href="/authors?query=willdurand%2FHateoas&limit=20"/> |
|
| 61 | <link rel="last" href="/authors?query=willdurand%2FHateoas&offset=80&limit=20"/> |
|
| 62 | <link rel="next" href="/authors?query=willdurand%2FHateoas&offset=64&limit=20"/> |
|
| 63 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&offset=24&limit=20"/> |
|
| 64 | </collection> |
|
| 65 | ||
| 66 | XML |
|
| 67 | , |
|
| 68 | $this->halHateoas->serialize($collection, 'xml') |
|
| 69 | ); |
|
| 70 | $this->assertSame( |
|
| 71 | <<<XML |
|
| 72 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 73 | <users offset="44" limit="20" total="95"> |
|
| 74 | <users rel="authors"> |
|
| 75 | <entry><![CDATA[Adrien]]></entry> |
|
| 76 | <entry><![CDATA[William]]></entry> |
|
| 77 | </users> |
|
| 78 | <link rel="self" href="/authors?query=willdurand%2FHateoas&offset=44&limit=20"/> |
|
| 79 | <link rel="first" href="/authors?query=willdurand%2FHateoas&limit=20"/> |
|
| 80 | <link rel="last" href="/authors?query=willdurand%2FHateoas&offset=80&limit=20"/> |
|
| 81 | <link rel="next" href="/authors?query=willdurand%2FHateoas&offset=64&limit=20"/> |
|
| 82 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&offset=24&limit=20"/> |
|
| 83 | </users> |
|
| 84 | ||
| 85 | XML |
|
| 86 | , |
|
| 87 | $this->hateoas->serialize(new UsersRepresentation($collection), 'xml') |
|
| 88 | ); |
|
| 89 | ||
| 90 | $this->assertSame( |
|
| 91 | <<<XML |
|
| 92 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 93 | <users offset="44" limit="20" total="95" href="/authors?query=willdurand%2FHateoas&offset=44&limit=20"> |
|
| 94 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
|
| 95 | <resource rel="authors"><![CDATA[William]]></resource> |
|
| 96 | <link rel="first" href="/authors?query=willdurand%2FHateoas&limit=20"/> |
|
| 97 | <link rel="last" href="/authors?query=willdurand%2FHateoas&offset=80&limit=20"/> |
|
| 98 | <link rel="next" href="/authors?query=willdurand%2FHateoas&offset=64&limit=20"/> |
|
| 99 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&offset=24&limit=20"/> |
|
| 100 | </users> |
|
| 101 | ||
| 102 | XML |
|
| 103 | , |
|
| 104 | $this->halHateoas->serialize(new UsersRepresentation($collection), 'xml') |
|
| 105 | ); |
|
| 106 | ||
| 107 | $this->assertSame( |
|
| 108 | '{' |
|
| 109 | .'"offset":44,' |
|
| 110 | .'"limit":20,' |
|
| 111 | .'"total":95,' |
|
| 112 | .'"_links":{' |
|
| 113 | .'"self":{' |
|
| 114 | .'"href":"\/authors?query=willdurand%2FHateoas&offset=44&limit=20"' |
|
| 115 | .'},' |
|
| 116 | .'"first":{' |
|
| 117 | .'"href":"\/authors?query=willdurand%2FHateoas&limit=20"' |
|
| 118 | .'},' |
|
| 119 | .'"last":{' |
|
| 120 | .'"href":"\/authors?query=willdurand%2FHateoas&offset=80&limit=20"' |
|
| 121 | .'},' |
|
| 122 | .'"next":{' |
|
| 123 | .'"href":"\/authors?query=willdurand%2FHateoas&offset=64&limit=20"' |
|
| 124 | .'},' |
|
| 125 | .'"previous":{' |
|
| 126 | .'"href":"\/authors?query=willdurand%2FHateoas&offset=24&limit=20"' |
|
| 127 | .'}' |
|
| 128 | .'},' |
|
| 129 | .'"_embedded":{' |
|
| 130 | .'"authors":[' |
|
| 131 | .'"Adrien",' |
|
| 132 | .'"William"' |
|
| 133 | .']' |
|
| 134 | .'}' |
|
| 135 | .'}', |
|
| 136 | $this->halHateoas->serialize($collection, 'json') |
|
| 137 | ); |
|
| 138 | } |
|
| 139 | ||
| 140 | public function testGenerateAbsoluteURIs() |
|
| 141 | { |
|
| @@ 11-137 (lines=127) @@ | ||
| 8 | ||
| 9 | class PaginatedRepresentationTest extends RepresentationTestCase |
|
| 10 | { |
|
| 11 | public function testSerialize() |
|
| 12 | { |
|
| 13 | $collection = new PaginatedRepresentation( |
|
| 14 | new CollectionRepresentation( |
|
| 15 | array( |
|
| 16 | 'Adrien', |
|
| 17 | 'William', |
|
| 18 | ), |
|
| 19 | 'authors', |
|
| 20 | 'users' |
|
| 21 | ), |
|
| 22 | '/authors', |
|
| 23 | array( |
|
| 24 | 'query' => 'willdurand/Hateoas', |
|
| 25 | ), |
|
| 26 | 3, |
|
| 27 | 20, |
|
| 28 | 17, |
|
| 29 | null, |
|
| 30 | null, |
|
| 31 | false, |
|
| 32 | 100 |
|
| 33 | ); |
|
| 34 | ||
| 35 | $this->assertSame( |
|
| 36 | <<<XML |
|
| 37 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 38 | <collection page="3" limit="20" pages="17" total="100"> |
|
| 39 | <users rel="authors"> |
|
| 40 | <entry><![CDATA[Adrien]]></entry> |
|
| 41 | <entry><![CDATA[William]]></entry> |
|
| 42 | </users> |
|
| 43 | <link rel="self" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"/> |
|
| 44 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
|
| 45 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
|
| 46 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
|
| 47 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
|
| 48 | </collection> |
|
| 49 | ||
| 50 | XML |
|
| 51 | , |
|
| 52 | $this->hateoas->serialize($collection, 'xml') |
|
| 53 | ); |
|
| 54 | $this->assertSame( |
|
| 55 | <<<XML |
|
| 56 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 57 | <collection page="3" limit="20" pages="17" total="100" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"> |
|
| 58 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
|
| 59 | <resource rel="authors"><![CDATA[William]]></resource> |
|
| 60 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
|
| 61 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
|
| 62 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
|
| 63 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
|
| 64 | </collection> |
|
| 65 | ||
| 66 | XML |
|
| 67 | , |
|
| 68 | $this->halHateoas->serialize($collection, 'xml') |
|
| 69 | ); |
|
| 70 | $this->assertSame( |
|
| 71 | <<<XML |
|
| 72 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 73 | <users page="3" limit="20" pages="17" total="100"> |
|
| 74 | <users rel="authors"> |
|
| 75 | <entry><![CDATA[Adrien]]></entry> |
|
| 76 | <entry><![CDATA[William]]></entry> |
|
| 77 | </users> |
|
| 78 | <link rel="self" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"/> |
|
| 79 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
|
| 80 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
|
| 81 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
|
| 82 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
|
| 83 | </users> |
|
| 84 | ||
| 85 | XML |
|
| 86 | , |
|
| 87 | $this->hateoas->serialize(new UsersRepresentation($collection), 'xml') |
|
| 88 | ); |
|
| 89 | $this->assertSame( |
|
| 90 | <<<XML |
|
| 91 | <?xml version="1.0" encoding="UTF-8"?> |
|
| 92 | <users page="3" limit="20" pages="17" total="100" href="/authors?query=willdurand%2FHateoas&page=3&limit=20"> |
|
| 93 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
|
| 94 | <resource rel="authors"><![CDATA[William]]></resource> |
|
| 95 | <link rel="first" href="/authors?query=willdurand%2FHateoas&page=1&limit=20"/> |
|
| 96 | <link rel="last" href="/authors?query=willdurand%2FHateoas&page=17&limit=20"/> |
|
| 97 | <link rel="next" href="/authors?query=willdurand%2FHateoas&page=4&limit=20"/> |
|
| 98 | <link rel="previous" href="/authors?query=willdurand%2FHateoas&page=2&limit=20"/> |
|
| 99 | </users> |
|
| 100 | ||
| 101 | XML |
|
| 102 | , |
|
| 103 | $this->halHateoas->serialize(new UsersRepresentation($collection), 'xml') |
|
| 104 | ); |
|
| 105 | $this->assertSame( |
|
| 106 | '{' |
|
| 107 | .'"page":3,' |
|
| 108 | .'"limit":20,' |
|
| 109 | .'"pages":17,' |
|
| 110 | .'"total":100,' |
|
| 111 | .'"_links":{' |
|
| 112 | .'"self":{' |
|
| 113 | .'"href":"\/authors?query=willdurand%2FHateoas&page=3&limit=20"' |
|
| 114 | .'},' |
|
| 115 | .'"first":{' |
|
| 116 | .'"href":"\/authors?query=willdurand%2FHateoas&page=1&limit=20"' |
|
| 117 | .'},' |
|
| 118 | .'"last":{' |
|
| 119 | .'"href":"\/authors?query=willdurand%2FHateoas&page=17&limit=20"' |
|
| 120 | .'},' |
|
| 121 | .'"next":{' |
|
| 122 | .'"href":"\/authors?query=willdurand%2FHateoas&page=4&limit=20"' |
|
| 123 | .'},' |
|
| 124 | .'"previous":{' |
|
| 125 | .'"href":"\/authors?query=willdurand%2FHateoas&page=2&limit=20"' |
|
| 126 | .'}' |
|
| 127 | .'},' |
|
| 128 | .'"_embedded":{' |
|
| 129 | .'"authors":[' |
|
| 130 | .'"Adrien",' |
|
| 131 | .'"William"' |
|
| 132 | .']' |
|
| 133 | .'}' |
|
| 134 | .'}', |
|
| 135 | $this->halHateoas->serialize($collection, 'json') |
|
| 136 | ); |
|
| 137 | } |
|
| 138 | ||
| 139 | public function testGenerateAbsoluteURIs() |
|
| 140 | { |
|