aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/LinksTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-02-13 08:41:12 +0100
committerGitHub <noreply@github.com>2017-02-13 08:41:12 +0100
commit65e56cbe49a7eb2a0cb09dda85daab3b921472ee (patch)
tree3e1d42f51fc179d06cfe50531a755fd37df41468 /tests/api/controllers/LinksTest.php
parent5f3f19f1c0f1a4feac20c40fe9ee8437469450f3 (diff)
parentc37a6f820b0a213ee2d5980a96aafac262aeb97a (diff)
downloadShaarli-65e56cbe49a7eb2a0cb09dda85daab3b921472ee.tar.gz
Shaarli-65e56cbe49a7eb2a0cb09dda85daab3b921472ee.tar.zst
Shaarli-65e56cbe49a7eb2a0cb09dda85daab3b921472ee.zip
Merge pull request #769 from ArthurHoaro/api/getlinks-visibility
REST API - getLinks: support the visibility parameter
Diffstat (limited to 'tests/api/controllers/LinksTest.php')
-rw-r--r--tests/api/controllers/LinksTest.php50
1 files changed, 22 insertions, 28 deletions
diff --git a/tests/api/controllers/LinksTest.php b/tests/api/controllers/LinksTest.php
index 4ead26b9..284c3a9d 100644
--- a/tests/api/controllers/LinksTest.php
+++ b/tests/api/controllers/LinksTest.php
@@ -188,25 +188,33 @@ class LinksTest extends \PHPUnit_Framework_TestCase
188 } 188 }
189 189
190 /** 190 /**
191 * Test getLinks with private attribute to 1 or true. 191 * Test getLinks with visibility parameter set to all
192 */ 192 */
193 public function testGetLinksPrivate() 193 public function testGetLinksVisibilityAll()
194 { 194 {
195 $env = Environment::mock([ 195 $env = Environment::mock(
196 'REQUEST_METHOD' => 'GET', 196 [
197 'QUERY_STRING' => 'private=true' 197 'REQUEST_METHOD' => 'GET',
198 ]); 198 'QUERY_STRING' => 'visibility=all'
199 ]
200 );
199 $request = Request::createFromEnvironment($env); 201 $request = Request::createFromEnvironment($env);
200 $response = $this->controller->getLinks($request, new Response()); 202 $response = $this->controller->getLinks($request, new Response());
201 $this->assertEquals(200, $response->getStatusCode()); 203 $this->assertEquals(200, $response->getStatusCode());
202 $data = json_decode((string) $response->getBody(), true); 204 $data = json_decode((string)$response->getBody(), true);
203 $this->assertEquals($this->refDB->countPrivateLinks(), count($data)); 205 $this->assertEquals($this->refDB->countLinks(), count($data));
204 $this->assertEquals(6, $data[0]['id']); 206 $this->assertEquals(41, $data[0]['id']);
205 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); 207 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
208 }
206 209
210 /**
211 * Test getLinks with visibility parameter set to private
212 */
213 public function testGetLinksVisibilityPrivate()
214 {
207 $env = Environment::mock([ 215 $env = Environment::mock([
208 'REQUEST_METHOD' => 'GET', 216 'REQUEST_METHOD' => 'GET',
209 'QUERY_STRING' => 'private=1' 217 'QUERY_STRING' => 'visibility=private'
210 ]); 218 ]);
211 $request = Request::createFromEnvironment($env); 219 $request = Request::createFromEnvironment($env);
212 $response = $this->controller->getLinks($request, new Response()); 220 $response = $this->controller->getLinks($request, new Response());
@@ -218,35 +226,21 @@ class LinksTest extends \PHPUnit_Framework_TestCase
218 } 226 }
219 227
220 /** 228 /**
221 * Test getLinks with private attribute to false or 0 229 * Test getLinks with visibility parameter set to public
222 */ 230 */
223 public function testGetLinksNotPrivate() 231 public function testGetLinksVisibilityPublic()
224 { 232 {
225 $env = Environment::mock( 233 $env = Environment::mock(
226 [ 234 [
227 'REQUEST_METHOD' => 'GET', 235 'REQUEST_METHOD' => 'GET',
228 'QUERY_STRING' => 'private=0' 236 'QUERY_STRING' => 'visibility=public'
229 ]
230 );
231 $request = Request::createFromEnvironment($env);
232 $response = $this->controller->getLinks($request, new Response());
233 $this->assertEquals(200, $response->getStatusCode());
234 $data = json_decode((string)$response->getBody(), true);
235 $this->assertEquals($this->refDB->countLinks(), count($data));
236 $this->assertEquals(41, $data[0]['id']);
237 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
238
239 $env = Environment::mock(
240 [
241 'REQUEST_METHOD' => 'GET',
242 'QUERY_STRING' => 'private=false'
243 ] 237 ]
244 ); 238 );
245 $request = Request::createFromEnvironment($env); 239 $request = Request::createFromEnvironment($env);
246 $response = $this->controller->getLinks($request, new Response()); 240 $response = $this->controller->getLinks($request, new Response());
247 $this->assertEquals(200, $response->getStatusCode()); 241 $this->assertEquals(200, $response->getStatusCode());
248 $data = json_decode((string)$response->getBody(), true); 242 $data = json_decode((string)$response->getBody(), true);
249 $this->assertEquals($this->refDB->countLinks(), count($data)); 243 $this->assertEquals($this->refDB->countPublicLinks(), count($data));
250 $this->assertEquals(41, $data[0]['id']); 244 $this->assertEquals(41, $data[0]['id']);
251 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); 245 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
252 } 246 }