]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
REST API - getLinks: support the visibility parameter 769/head
authorArthurHoaro <arthur@hoa.ro>
Tue, 17 Jan 2017 17:51:40 +0000 (18:51 +0100)
committerArthurHoaro <arthur@hoa.ro>
Tue, 17 Jan 2017 17:53:18 +0000 (18:53 +0100)
application/api/controllers/Links.php
tests/api/controllers/LinksTest.php

index 01b7e783f0390ce1ff42756507b12cb952791c62..0a7968e3916c2168c6785de0ad4bdc0867f4e850 100644 (file)
@@ -34,15 +34,14 @@ class Links extends ApiController
      */
     public function getLinks($request, $response)
     {
-        $private = $request->getParam('private');
+        $private = $request->getParam('visibility');
         $links = $this->linkDb->filterSearch(
             [
                 'searchtags' => $request->getParam('searchtags', ''),
                 'searchterm' => $request->getParam('searchterm', ''),
             ],
             false,
-            // to updated in another PR depending on the API doc
-            ($private === 'true' || $private === '1') ? 'private' : 'all'
+            $private
         );
 
         // Return links from the {offset}th link, starting from 0.
index 4ead26b9f566db70683d9d2e9dd25413e7689ac8..284c3a9da94625b3713a50551640a90b51fadd59 100644 (file)
@@ -188,25 +188,33 @@ class LinksTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * Test getLinks with private attribute to 1 or true.
+     * Test getLinks with visibility parameter set to all
      */
-    public function testGetLinksPrivate()
+    public function testGetLinksVisibilityAll()
     {
-        $env = Environment::mock([
-            'REQUEST_METHOD' => 'GET',
-            'QUERY_STRING' => 'private=true'
-        ]);
+        $env = Environment::mock(
+            [
+                'REQUEST_METHOD' => 'GET',
+                'QUERY_STRING' => 'visibility=all'
+            ]
+        );
         $request = Request::createFromEnvironment($env);
         $response = $this->controller->getLinks($request, new Response());
         $this->assertEquals(200, $response->getStatusCode());
-        $data = json_decode((string) $response->getBody(), true);
-        $this->assertEquals($this->refDB->countPrivateLinks(), count($data));
-        $this->assertEquals(6, $data[0]['id']);
+        $data = json_decode((string)$response->getBody(), true);
+        $this->assertEquals($this->refDB->countLinks(), count($data));
+        $this->assertEquals(41, $data[0]['id']);
         $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
+    }
 
+    /**
+     * Test getLinks with visibility parameter set to private
+     */
+    public function testGetLinksVisibilityPrivate()
+    {
         $env = Environment::mock([
             'REQUEST_METHOD' => 'GET',
-            'QUERY_STRING' => 'private=1'
+            'QUERY_STRING' => 'visibility=private'
         ]);
         $request = Request::createFromEnvironment($env);
         $response = $this->controller->getLinks($request, new Response());
@@ -218,35 +226,21 @@ class LinksTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * Test getLinks with private attribute to false or 0
+     * Test getLinks with visibility parameter set to public
      */
-    public function testGetLinksNotPrivate()
+    public function testGetLinksVisibilityPublic()
     {
         $env = Environment::mock(
             [
                 'REQUEST_METHOD' => 'GET',
-                'QUERY_STRING' => 'private=0'
-            ]
-        );
-        $request = Request::createFromEnvironment($env);
-        $response = $this->controller->getLinks($request, new Response());
-        $this->assertEquals(200, $response->getStatusCode());
-        $data = json_decode((string)$response->getBody(), true);
-        $this->assertEquals($this->refDB->countLinks(), count($data));
-        $this->assertEquals(41, $data[0]['id']);
-        $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
-
-        $env = Environment::mock(
-            [
-                'REQUEST_METHOD' => 'GET',
-                'QUERY_STRING' => 'private=false'
+                'QUERY_STRING' => 'visibility=public'
             ]
         );
         $request = Request::createFromEnvironment($env);
         $response = $this->controller->getLinks($request, new Response());
         $this->assertEquals(200, $response->getStatusCode());
         $data = json_decode((string)$response->getBody(), true);
-        $this->assertEquals($this->refDB->countLinks(), count($data));
+        $this->assertEquals($this->refDB->countPublicLinks(), count($data));
         $this->assertEquals(41, $data[0]['id']);
         $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
     }