aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api/controllers/info
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-05-19 15:04:04 +0200
committerArthurHoaro <arthur@hoa.ro>2018-06-04 18:51:22 +0200
commitd3f42ca487287447efb81061609644108044a038 (patch)
tree6e9d5a33290f857c8f7a04dbdf8cf0ca749db149 /tests/api/controllers/info
parent17e45b2e9c33c736751e059276fadb480f98e621 (diff)
downloadShaarli-d3f42ca487287447efb81061609644108044a038.tar.gz
Shaarli-d3f42ca487287447efb81061609644108044a038.tar.zst
Shaarli-d3f42ca487287447efb81061609644108044a038.zip
Implements Tags endpoints for Shaarli's REST API
Endpoints: * List All Tags [GET] * Get a tag [GET] * Update a tag [PUT] * Delete a tag [DELETE] Fixes #904 References shaarli/api-documentation#34
Diffstat (limited to 'tests/api/controllers/info')
-rw-r--r--tests/api/controllers/info/InfoTest.php115
1 files changed, 115 insertions, 0 deletions
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
new file mode 100644
index 00000000..f7e63bfa
--- /dev/null
+++ b/tests/api/controllers/info/InfoTest.php
@@ -0,0 +1,115 @@
1<?php
2namespace Shaarli\Api\Controllers;
3
4use Shaarli\Config\ConfigManager;
5
6use Slim\Container;
7use Slim\Http\Environment;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class InfoTest
13 *
14 * Test REST API controller Info.
15 *
16 * @package Api\Controllers
17 */
18class InfoTest extends \PHPUnit_Framework_TestCase
19{
20 /**
21 * @var string datastore to test write operations
22 */
23 protected static $testDatastore = 'sandbox/datastore.php';
24
25 /**
26 * @var ConfigManager instance
27 */
28 protected $conf;
29
30 /**
31 * @var \ReferenceLinkDB instance.
32 */
33 protected $refDB = null;
34
35 /**
36 * @var Container instance.
37 */
38 protected $container;
39
40 /**
41 * @var Info controller instance.
42 */
43 protected $controller;
44
45 /**
46 * Before every test, instantiate a new Api with its config, plugins and links.
47 */
48 public function setUp()
49 {
50 $this->conf = new ConfigManager('tests/utils/config/configJson.json.php');
51 $this->refDB = new \ReferenceLinkDB();
52 $this->refDB->write(self::$testDatastore);
53
54 $this->container = new Container();
55 $this->container['conf'] = $this->conf;
56 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false);
57 $this->container['history'] = null;
58
59 $this->controller = new Info($this->container);
60 }
61
62 /**
63 * After every test, remove the test datastore.
64 */
65 public function tearDown()
66 {
67 @unlink(self::$testDatastore);
68 }
69
70 /**
71 * Test /info service.
72 */
73 public function testGetInfo()
74 {
75 $env = Environment::mock([
76 'REQUEST_METHOD' => 'GET',
77 ]);
78 $request = Request::createFromEnvironment($env);
79
80 $response = $this->controller->getInfo($request, new Response());
81 $this->assertEquals(200, $response->getStatusCode());
82 $data = json_decode((string) $response->getBody(), true);
83
84 $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
85 $this->assertEquals(2, $data['private_counter']);
86 $this->assertEquals('Shaarli', $data['settings']['title']);
87 $this->assertEquals('?', $data['settings']['header_link']);
88 $this->assertEquals('UTC', $data['settings']['timezone']);
89 $this->assertEquals(ConfigManager::$DEFAULT_PLUGINS, $data['settings']['enabled_plugins']);
90 $this->assertEquals(false, $data['settings']['default_private_links']);
91
92 $title = 'My links';
93 $headerLink = 'http://shaarli.tld';
94 $timezone = 'Europe/Paris';
95 $enabledPlugins = array('foo', 'bar');
96 $defaultPrivateLinks = true;
97 $this->conf->set('general.title', $title);
98 $this->conf->set('general.header_link', $headerLink);
99 $this->conf->set('general.timezone', $timezone);
100 $this->conf->set('general.enabled_plugins', $enabledPlugins);
101 $this->conf->set('privacy.default_private_links', $defaultPrivateLinks);
102
103 $response = $this->controller->getInfo($request, new Response());
104 $this->assertEquals(200, $response->getStatusCode());
105 $data = json_decode((string) $response->getBody(), true);
106
107 $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
108 $this->assertEquals(2, $data['private_counter']);
109 $this->assertEquals($title, $data['settings']['title']);
110 $this->assertEquals($headerLink, $data['settings']['header_link']);
111 $this->assertEquals($timezone, $data['settings']['timezone']);
112 $this->assertEquals($enabledPlugins, $data['settings']['enabled_plugins']);
113 $this->assertEquals($defaultPrivateLinks, $data['settings']['default_private_links']);
114 }
115}