]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php
fix tests for GET /entries/tags
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / WallabagRestControllerTest.php
index 0ffe7fe626311d83da7754be64cb3576126810e3..c45e52d782be5218f31faded99473a4a4642b778 100644 (file)
@@ -44,10 +44,6 @@ class WallabagRestControllerTest extends WallabagTestCase
     public function testWithBadHeaders()
     {
         $client = $this->createClient();
-        $client->request('GET', '/api/salts/admin.json');
-        $salt = json_decode($client->getResponse()->getContent());
-
-        $headers = $this->generateHeaders('admin', 'mypassword', $salt[0]);
 
         $entry = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
@@ -151,32 +147,68 @@ class WallabagRestControllerTest extends WallabagTestCase
         $this->assertEquals(404, $client->getResponse()->getStatusCode());
     }
 
-    public function testGetOneTag()
+    public function testGetTagsEntry()
     {
         $client = $this->createClient();
         $client->request('GET', '/api/salts/admin.json');
         $salt = json_decode($client->getResponse()->getContent());
+        $headers = $this->generateHeaders('admin', 'test', $salt[0]);
 
+        $entry = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneWithTags(1);
+
+        $entry = $entry[0];
+
+        if (!$entry) {
+            $this->markTestSkipped('No content found in db.');
+        }
+
+        $tags = array();
+        foreach ($entry->getTags() as $tag) {
+            $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel());
+        }
+
+        $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers);
+
+        $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent());
+    }
+
+    public function testPostTagsOnEntry()
+    {
+        $client = $this->createClient();
+        $client->request('GET', '/api/salts/admin.json');
+        $salt = json_decode($client->getResponse()->getContent());
         $headers = $this->generateHeaders('admin', 'test', $salt[0]);
 
-        $tag = $client->getContainer()
+        $entry = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
-            ->getRepository('WallabagCoreBundle:Tag')
-            ->findOneByLabel('foo');
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUser(1);
 
-        if (!$tag) {
+        if (!$entry) {
             $this->markTestSkipped('No content found in db.');
         }
 
-        $client->request('GET', '/api/tags/'.$tag->getLabel().'.json', array(), array(), $headers);
+        $newTags = 'tag1,tag2,tag3';
 
-        $this->assertEquals(json_encode($tag), $client->getResponse()->getContent());
+        $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers);
 
-        $this->assertTrue(
-            $client->getResponse()->headers->contains(
-                'Content-Type',
-                'application/json'
-            )
-        );
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $entryDB = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->find($entry->getId());
+
+        $tagsInDB = array();
+        foreach ($entryDB->getTags()->toArray() as $tag) {
+            $tagsInDB[$tag->getId()] = $tag->getLabel();
+        }
+
+        foreach (explode(',', $newTags) as $tag) {
+            $this->assertContains($tag, $tagsInDB);
+        }
     }
 }