]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php
Merge pull request #1384 from wallabag/v2-fix-config-display
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Tests / Controller / WallabagRestControllerTest.php
index ea8ee072e9115411289aab425f866d6f52327c83..7ae54b576d577014bb3f5348235986973fc2b439 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wallabag\CoreBundle\Tests\Controller;
+namespace Wallabag\ApiBundle\Tests\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
 
@@ -9,7 +9,7 @@ class WallabagRestControllerTest extends WebTestCase
     protected static $salt;
 
     /**
-     * Grab the salt once and store it to be available for all tests
+     * Grab the salt once and store it to be available for all tests.
      */
     public static function setUpBeforeClass()
     {
@@ -24,7 +24,7 @@ class WallabagRestControllerTest extends WebTestCase
     }
 
     /**
-     * Generate HTTP headers for authenticate user on API
+     * Generate HTTP headers for authenticate user on API.
      *
      * @param string $username
      * @param string $password
@@ -170,6 +170,31 @@ class WallabagRestControllerTest extends WebTestCase
         $client = $this->createClient();
         $headers = $this->generateHeaders('admin', 'mypassword');
 
+        $client->request('GET', '/api/entries', array('star' => 1, 'sort' => 'updated'), array(), $headers);
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+        $content = json_decode($client->getResponse()->getContent(), true);
+
+        $this->assertGreaterThanOrEqual(1, count($content));
+        $this->assertNotEmpty($content['_embedded']['items']);
+        $this->assertGreaterThanOrEqual(1, $content['total']);
+        $this->assertEquals(1, $content['page']);
+        $this->assertGreaterThanOrEqual(1, $content['pages']);
+
+        $this->assertTrue(
+            $client->getResponse()->headers->contains(
+                'Content-Type',
+                'application/json'
+            )
+        );
+    }
+
+    public function testGetArchiveEntries()
+    {
+        $client = $this->createClient();
+        $headers = $this->generateHeaders('admin', 'mypassword');
+
         $client->request('GET', '/api/entries', array('archive' => 1), array(), $headers);
 
         $this->assertEquals(200, $client->getResponse()->getStatusCode());
@@ -177,10 +202,10 @@ class WallabagRestControllerTest extends WebTestCase
         $content = json_decode($client->getResponse()->getContent(), true);
 
         $this->assertGreaterThanOrEqual(1, count($content));
-        $this->assertEmpty($content['_embedded']['items']);
-        $this->assertEquals(0, $content['total']);
+        $this->assertNotEmpty($content['_embedded']['items']);
+        $this->assertGreaterThanOrEqual(1, $content['total']);
         $this->assertEquals(1, $content['page']);
-        $this->assertEquals(1, $content['pages']);
+        $this->assertGreaterThanOrEqual(1, $content['pages']);
 
         $this->assertTrue(
             $client->getResponse()->headers->contains(
@@ -327,7 +352,7 @@ class WallabagRestControllerTest extends WebTestCase
         $content = json_decode($client->getResponse()->getContent(), true);
 
         $this->assertArrayHasKey('tags', $content);
-        $this->assertEquals($nbTags+3, count($content['tags']));
+        $this->assertEquals($nbTags + 3, count($content['tags']));
 
         $entryDB = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
@@ -369,7 +394,7 @@ class WallabagRestControllerTest extends WebTestCase
         $content = json_decode($client->getResponse()->getContent(), true);
 
         $this->assertArrayHasKey('tags', $content);
-        $this->assertEquals($nbTags-1, count($content['tags']));
+        $this->assertEquals($nbTags - 1, count($content['tags']));
     }
 
     public function testGetUserTags()