aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-10-02 17:48:16 +0200
committerGitHub <noreply@github.com>2016-10-02 17:48:16 +0200
commitdfbbf0e18ad585e318c2609e46963e4b9fd198ef (patch)
treea415df1d2e51a35e1501a15d27dbcc2fad971e10 /tests/Wallabag
parent77557d289bafc088baf806e4744f110dfd959300 (diff)
parentc3f8b428dd50578a6eba5f4673ea1c9edabd2512 (diff)
downloadwallabag-dfbbf0e18ad585e318c2609e46963e4b9fd198ef.tar.gz
wallabag-dfbbf0e18ad585e318c2609e46963e4b9fd198ef.tar.zst
wallabag-dfbbf0e18ad585e318c2609e46963e4b9fd198ef.zip
Merge pull request #2331 from wallabag/api-links
Fix parameters in API _links
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php100
1 files changed, 99 insertions, 1 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 9b5760bc..fd72b8f2 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -78,6 +78,53 @@ class WallabagRestControllerTest extends WallabagApiTestCase
78 ); 78 );
79 } 79 }
80 80
81 public function testGetEntriesWithFullOptions()
82 {
83 $this->client->request('GET', '/api/entries', [
84 'archive' => 1,
85 'starred' => 1,
86 'sort' => 'updated',
87 'order' => 'asc',
88 'page' => 1,
89 'perPage' => 2,
90 'tags' => 'foo',
91 'since' => 1443274283,
92 ]);
93
94 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
95
96 $content = json_decode($this->client->getResponse()->getContent(), true);
97
98 $this->assertGreaterThanOrEqual(1, count($content));
99 $this->assertArrayHasKey('items', $content['_embedded']);
100 $this->assertGreaterThanOrEqual(0, $content['total']);
101 $this->assertEquals(1, $content['page']);
102 $this->assertEquals(2, $content['limit']);
103 $this->assertGreaterThanOrEqual(1, $content['pages']);
104
105 $this->assertArrayHasKey('_links', $content);
106 $this->assertArrayHasKey('self', $content['_links']);
107 $this->assertArrayHasKey('first', $content['_links']);
108 $this->assertArrayHasKey('last', $content['_links']);
109
110 foreach (['self', 'first', 'last'] as $link) {
111 $this->assertArrayHasKey('href', $content['_links'][$link]);
112 $this->assertContains('archive=1', $content['_links'][$link]['href']);
113 $this->assertContains('starred=1', $content['_links'][$link]['href']);
114 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
115 $this->assertContains('order=asc', $content['_links'][$link]['href']);
116 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
117 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
118 }
119
120 $this->assertTrue(
121 $this->client->getResponse()->headers->contains(
122 'Content-Type',
123 'application/json'
124 )
125 );
126 }
127
81 public function testGetStarredEntries() 128 public function testGetStarredEntries()
82 { 129 {
83 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); 130 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
@@ -92,6 +139,17 @@ class WallabagRestControllerTest extends WallabagApiTestCase
92 $this->assertEquals(1, $content['page']); 139 $this->assertEquals(1, $content['page']);
93 $this->assertGreaterThanOrEqual(1, $content['pages']); 140 $this->assertGreaterThanOrEqual(1, $content['pages']);
94 141
142 $this->assertArrayHasKey('_links', $content);
143 $this->assertArrayHasKey('self', $content['_links']);
144 $this->assertArrayHasKey('first', $content['_links']);
145 $this->assertArrayHasKey('last', $content['_links']);
146
147 foreach (['self', 'first', 'last'] as $link) {
148 $this->assertArrayHasKey('href', $content['_links'][$link]);
149 $this->assertContains('starred=1', $content['_links'][$link]['href']);
150 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
151 }
152
95 $this->assertTrue( 153 $this->assertTrue(
96 $this->client->getResponse()->headers->contains( 154 $this->client->getResponse()->headers->contains(
97 'Content-Type', 155 'Content-Type',
@@ -114,6 +172,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
114 $this->assertEquals(1, $content['page']); 172 $this->assertEquals(1, $content['page']);
115 $this->assertGreaterThanOrEqual(1, $content['pages']); 173 $this->assertGreaterThanOrEqual(1, $content['pages']);
116 174
175 $this->assertArrayHasKey('_links', $content);
176 $this->assertArrayHasKey('self', $content['_links']);
177 $this->assertArrayHasKey('first', $content['_links']);
178 $this->assertArrayHasKey('last', $content['_links']);
179
180 foreach (['self', 'first', 'last'] as $link) {
181 $this->assertArrayHasKey('href', $content['_links'][$link]);
182 $this->assertContains('archive=1', $content['_links'][$link]['href']);
183 }
184
117 $this->assertTrue( 185 $this->assertTrue(
118 $this->client->getResponse()->headers->contains( 186 $this->client->getResponse()->headers->contains(
119 'Content-Type', 187 'Content-Type',
@@ -136,6 +204,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
136 $this->assertEquals(1, $content['page']); 204 $this->assertEquals(1, $content['page']);
137 $this->assertGreaterThanOrEqual(1, $content['pages']); 205 $this->assertGreaterThanOrEqual(1, $content['pages']);
138 206
207 $this->assertArrayHasKey('_links', $content);
208 $this->assertArrayHasKey('self', $content['_links']);
209 $this->assertArrayHasKey('first', $content['_links']);
210 $this->assertArrayHasKey('last', $content['_links']);
211
212 foreach (['self', 'first', 'last'] as $link) {
213 $this->assertArrayHasKey('href', $content['_links'][$link]);
214 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
215 }
216
139 $this->assertTrue( 217 $this->assertTrue(
140 $this->client->getResponse()->headers->contains( 218 $this->client->getResponse()->headers->contains(
141 'Content-Type', 219 'Content-Type',
@@ -146,7 +224,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
146 224
147 public function testGetDatedEntries() 225 public function testGetDatedEntries()
148 { 226 {
149 $this->client->request('GET', '/api/entries', ['since' => 1]); 227 $this->client->request('GET', '/api/entries', ['since' => 1443274283]);
150 228
151 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 229 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
152 230
@@ -158,6 +236,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
158 $this->assertEquals(1, $content['page']); 236 $this->assertEquals(1, $content['page']);
159 $this->assertGreaterThanOrEqual(1, $content['pages']); 237 $this->assertGreaterThanOrEqual(1, $content['pages']);
160 238
239 $this->assertArrayHasKey('_links', $content);
240 $this->assertArrayHasKey('self', $content['_links']);
241 $this->assertArrayHasKey('first', $content['_links']);
242 $this->assertArrayHasKey('last', $content['_links']);
243
244 foreach (['self', 'first', 'last'] as $link) {
245 $this->assertArrayHasKey('href', $content['_links'][$link]);
246 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
247 }
248
161 $this->assertTrue( 249 $this->assertTrue(
162 $this->client->getResponse()->headers->contains( 250 $this->client->getResponse()->headers->contains(
163 'Content-Type', 251 'Content-Type',
@@ -181,6 +269,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
181 $this->assertEquals(1, $content['page']); 269 $this->assertEquals(1, $content['page']);
182 $this->assertEquals(1, $content['pages']); 270 $this->assertEquals(1, $content['pages']);
183 271
272 $this->assertArrayHasKey('_links', $content);
273 $this->assertArrayHasKey('self', $content['_links']);
274 $this->assertArrayHasKey('first', $content['_links']);
275 $this->assertArrayHasKey('last', $content['_links']);
276
277 foreach (['self', 'first', 'last'] as $link) {
278 $this->assertArrayHasKey('href', $content['_links'][$link]);
279 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
280 }
281
184 $this->assertTrue( 282 $this->assertTrue(
185 $this->client->getResponse()->headers->contains( 283 $this->client->getResponse()->headers->contains(
186 'Content-Type', 284 'Content-Type',