aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 4aa60e90..067aed2c 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -128,6 +128,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
128 'perPage' => 2, 128 'perPage' => 2,
129 'tags' => 'foo', 129 'tags' => 'foo',
130 'since' => 1443274283, 130 'since' => 1443274283,
131 'public' => 0,
131 ]); 132 ]);
132 133
133 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 134 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -154,6 +155,53 @@ class EntryRestControllerTest extends WallabagApiTestCase
154 $this->assertContains('order=asc', $content['_links'][$link]['href']); 155 $this->assertContains('order=asc', $content['_links'][$link]['href']);
155 $this->assertContains('tags=foo', $content['_links'][$link]['href']); 156 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
156 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 157 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
158 $this->assertContains('public=0', $content['_links'][$link]['href']);
159 }
160
161 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
162 }
163
164 public function testGetEntriesPublicOnly()
165 {
166 $entry = $this->client->getContainer()
167 ->get('doctrine.orm.entity_manager')
168 ->getRepository('WallabagCoreBundle:Entry')
169 ->findOneByUser(1);
170
171 if (!$entry) {
172 $this->markTestSkipped('No content found in db.');
173 }
174
175 // generate at least one public entry
176 $entry->generateUid();
177
178 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
179 $em->persist($entry);
180 $em->flush();
181
182 $this->client->request('GET', '/api/entries', [
183 'public' => 1,
184 ]);
185
186 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
187
188 $content = json_decode($this->client->getResponse()->getContent(), true);
189
190 $this->assertGreaterThanOrEqual(1, count($content));
191 $this->assertArrayHasKey('items', $content['_embedded']);
192 $this->assertGreaterThanOrEqual(1, $content['total']);
193 $this->assertEquals(1, $content['page']);
194 $this->assertEquals(30, $content['limit']);
195 $this->assertGreaterThanOrEqual(1, $content['pages']);
196
197 $this->assertArrayHasKey('_links', $content);
198 $this->assertArrayHasKey('self', $content['_links']);
199 $this->assertArrayHasKey('first', $content['_links']);
200 $this->assertArrayHasKey('last', $content['_links']);
201
202 foreach (['self', 'first', 'last'] as $link) {
203 $this->assertArrayHasKey('href', $content['_links'][$link]);
204 $this->assertContains('public=1', $content['_links'][$link]['href']);
157 } 205 }
158 206
159 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 207 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
@@ -348,6 +396,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
348 'language' => 'de', 396 'language' => 'de',
349 'published_at' => '2016-09-08T11:55:58+0200', 397 'published_at' => '2016-09-08T11:55:58+0200',
350 'authors' => 'bob,helen', 398 'authors' => 'bob,helen',
399 'public' => 1,
351 ]); 400 ]);
352 401
353 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 402 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -367,6 +416,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
367 $this->assertCount(2, $content['published_by']); 416 $this->assertCount(2, $content['published_by']);
368 $this->assertContains('bob', $content['published_by']); 417 $this->assertContains('bob', $content['published_by']);
369 $this->assertContains('helen', $content['published_by']); 418 $this->assertContains('helen', $content['published_by']);
419 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
370 } 420 }
371 421
372 public function testPostSameEntry() 422 public function testPostSameEntry()
@@ -481,6 +531,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
481 'preview_picture' => 'http://preview.io/picture.jpg', 531 'preview_picture' => 'http://preview.io/picture.jpg',
482 'authors' => 'bob,sponge', 532 'authors' => 'bob,sponge',
483 'content' => 'awesome', 533 'content' => 'awesome',
534 'public' => 0,
484 ]); 535 ]);
485 536
486 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 537 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -497,6 +548,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
497 $this->assertContains('sponge', $content['published_by']); 548 $this->assertContains('sponge', $content['published_by']);
498 $this->assertContains('bob', $content['published_by']); 549 $this->assertContains('bob', $content['published_by']);
499 $this->assertEquals('awesome', $content['content']); 550 $this->assertEquals('awesome', $content['content']);
551 $this->assertFalse($content['is_public'], 'Entry is no more shared');
500 } 552 }
501 553
502 public function testPatchEntryWithoutQuotes() 554 public function testPatchEntryWithoutQuotes()