aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php180
1 files changed, 177 insertions, 3 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index c39cc357..ee5b2ab7 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Tag;
6 7
7class WallabagRestControllerTest extends WallabagApiTestCase 8class WallabagRestControllerTest extends WallabagApiTestCase
8{ 9{
@@ -121,6 +122,73 @@ class WallabagRestControllerTest extends WallabagApiTestCase
121 ); 122 );
122 } 123 }
123 124
125 public function testGetTaggedEntries()
126 {
127 $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']);
128
129 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
130
131 $content = json_decode($this->client->getResponse()->getContent(), true);
132
133 $this->assertGreaterThanOrEqual(1, count($content));
134 $this->assertNotEmpty($content['_embedded']['items']);
135 $this->assertGreaterThanOrEqual(1, $content['total']);
136 $this->assertEquals(1, $content['page']);
137 $this->assertGreaterThanOrEqual(1, $content['pages']);
138
139 $this->assertTrue(
140 $this->client->getResponse()->headers->contains(
141 'Content-Type',
142 'application/json'
143 )
144 );
145 }
146
147 public function testGetDatedEntries()
148 {
149 $this->client->request('GET', '/api/entries', ['since' => 1]);
150
151 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
152
153 $content = json_decode($this->client->getResponse()->getContent(), true);
154
155 $this->assertGreaterThanOrEqual(1, count($content));
156 $this->assertNotEmpty($content['_embedded']['items']);
157 $this->assertGreaterThanOrEqual(1, $content['total']);
158 $this->assertEquals(1, $content['page']);
159 $this->assertGreaterThanOrEqual(1, $content['pages']);
160
161 $this->assertTrue(
162 $this->client->getResponse()->headers->contains(
163 'Content-Type',
164 'application/json'
165 )
166 );
167 }
168
169 public function testGetDatedSupEntries()
170 {
171 $future = new \DateTime(date('Y-m-d H:i:s'));
172 $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]);
173
174 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
175
176 $content = json_decode($this->client->getResponse()->getContent(), true);
177
178 $this->assertGreaterThanOrEqual(1, count($content));
179 $this->assertEmpty($content['_embedded']['items']);
180 $this->assertEquals(0, $content['total']);
181 $this->assertEquals(1, $content['page']);
182 $this->assertEquals(1, $content['pages']);
183
184 $this->assertTrue(
185 $this->client->getResponse()->headers->contains(
186 'Content-Type',
187 'application/json'
188 )
189 );
190 }
191
124 public function testDeleteEntry() 192 public function testDeleteEntry()
125 { 193 {
126 $entry = $this->client->getContainer() 194 $entry = $this->client->getContainer()
@@ -292,7 +360,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
292 $entry = $this->client->getContainer() 360 $entry = $this->client->getContainer()
293 ->get('doctrine.orm.entity_manager') 361 ->get('doctrine.orm.entity_manager')
294 ->getRepository('WallabagCoreBundle:Entry') 362 ->getRepository('WallabagCoreBundle:Entry')
295 ->findOneWithTags(1); 363 ->findOneWithTags($this->user->getId());
296 364
297 $entry = $entry[0]; 365 $entry = $entry[0];
298 366
@@ -354,7 +422,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
354 $entry = $this->client->getContainer() 422 $entry = $this->client->getContainer()
355 ->get('doctrine.orm.entity_manager') 423 ->get('doctrine.orm.entity_manager')
356 ->getRepository('WallabagCoreBundle:Entry') 424 ->getRepository('WallabagCoreBundle:Entry')
357 ->findOneWithTags(1); 425 ->findOneWithTags($this->user->getId());
358 $entry = $entry[0]; 426 $entry = $entry[0];
359 427
360 if (!$entry) { 428 if (!$entry) {
@@ -405,7 +473,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
405 $this->assertEquals($tag['label'], $content['label']); 473 $this->assertEquals($tag['label'], $content['label']);
406 $this->assertEquals($tag['slug'], $content['slug']); 474 $this->assertEquals($tag['slug'], $content['slug']);
407 475
408 $entries = $entry = $this->client->getContainer() 476 $entries = $this->client->getContainer()
409 ->get('doctrine.orm.entity_manager') 477 ->get('doctrine.orm.entity_manager')
410 ->getRepository('WallabagCoreBundle:Entry') 478 ->getRepository('WallabagCoreBundle:Entry')
411 ->findAllByTagId($this->user->getId(), $tag['id']); 479 ->findAllByTagId($this->user->getId(), $tag['id']);
@@ -413,6 +481,112 @@ class WallabagRestControllerTest extends WallabagApiTestCase
413 $this->assertCount(0, $entries); 481 $this->assertCount(0, $entries);
414 } 482 }
415 483
484 public function testDeleteTagByLabel()
485 {
486 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
487 $entry = $this->client->getContainer()
488 ->get('doctrine.orm.entity_manager')
489 ->getRepository('WallabagCoreBundle:Entry')
490 ->findOneWithTags($this->user->getId());
491
492 $entry = $entry[0];
493
494 $tag = new Tag();
495 $tag->setLabel('Awesome tag for test');
496 $em->persist($tag);
497
498 $entry->addTag($tag);
499
500 $em->persist($entry);
501 $em->flush();
502
503 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
504
505 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
506
507 $content = json_decode($this->client->getResponse()->getContent(), true);
508
509 $this->assertArrayHasKey('label', $content);
510 $this->assertEquals($tag->getLabel(), $content['label']);
511 $this->assertEquals($tag->getSlug(), $content['slug']);
512
513 $entries = $this->client->getContainer()
514 ->get('doctrine.orm.entity_manager')
515 ->getRepository('WallabagCoreBundle:Entry')
516 ->findAllByTagId($this->user->getId(), $tag->getId());
517
518 $this->assertCount(0, $entries);
519 }
520
521 public function testDeleteTagByLabelNotFound()
522 {
523 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
524
525 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
526 }
527
528 public function testDeleteTagsByLabel()
529 {
530 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
531 $entry = $this->client->getContainer()
532 ->get('doctrine.orm.entity_manager')
533 ->getRepository('WallabagCoreBundle:Entry')
534 ->findOneWithTags($this->user->getId());
535
536 $entry = $entry[0];
537
538 $tag = new Tag();
539 $tag->setLabel('Awesome tag for tagsLabel');
540 $em->persist($tag);
541
542 $tag2 = new Tag();
543 $tag2->setLabel('Awesome tag for tagsLabel 2');
544 $em->persist($tag2);
545
546 $entry->addTag($tag);
547 $entry->addTag($tag2);
548
549 $em->persist($entry);
550 $em->flush();
551
552 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
553
554 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
555
556 $content = json_decode($this->client->getResponse()->getContent(), true);
557
558 $this->assertCount(2, $content);
559
560 $this->assertArrayHasKey('label', $content[0]);
561 $this->assertEquals($tag->getLabel(), $content[0]['label']);
562 $this->assertEquals($tag->getSlug(), $content[0]['slug']);
563
564 $this->assertArrayHasKey('label', $content[1]);
565 $this->assertEquals($tag2->getLabel(), $content[1]['label']);
566 $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
567
568 $entries = $this->client->getContainer()
569 ->get('doctrine.orm.entity_manager')
570 ->getRepository('WallabagCoreBundle:Entry')
571 ->findAllByTagId($this->user->getId(), $tag->getId());
572
573 $this->assertCount(0, $entries);
574
575 $entries = $this->client->getContainer()
576 ->get('doctrine.orm.entity_manager')
577 ->getRepository('WallabagCoreBundle:Entry')
578 ->findAllByTagId($this->user->getId(), $tag2->getId());
579
580 $this->assertCount(0, $entries);
581 }
582
583 public function testDeleteTagsByLabelNotFound()
584 {
585 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
586
587 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
588 }
589
416 public function testGetVersion() 590 public function testGetVersion()
417 { 591 {
418 $this->client->request('GET', '/api/version'); 592 $this->client->request('GET', '/api/version');