From d3f42ca487287447efb81061609644108044a038 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 19 May 2018 15:04:04 +0200 Subject: 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 --- tests/api/controllers/tags/GetTagNameTest.php | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 tests/api/controllers/tags/GetTagNameTest.php (limited to 'tests/api/controllers/tags/GetTagNameTest.php') diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php new file mode 100644 index 00000000..d60f5b38 --- /dev/null +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -0,0 +1,129 @@ +conf = new ConfigManager('tests/utils/config/configJson'); + $this->refDB = new \ReferenceLinkDB(); + $this->refDB->write(self::$testDatastore); + + $this->container = new Container(); + $this->container['conf'] = $this->conf; + $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); + $this->container['history'] = null; + + $this->controller = new Tags($this->container); + } + + /** + * After each test, remove the test datastore. + */ + public function tearDown() + { + @unlink(self::$testDatastore); + } + + /** + * Test basic getTag service: return gnu tag with 2 occurrences. + */ + public function testGetTag() + { + $tagName = 'gnu'; + $env = Environment::mock([ + 'REQUEST_METHOD' => 'GET', + ]); + $request = Request::createFromEnvironment($env); + + $response = $this->controller->getTag($request, new Response(), ['tagName' => $tagName]); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode((string) $response->getBody(), true); + $this->assertEquals(self::NB_FIELDS_TAG, count($data)); + $this->assertEquals($tagName, $data['name']); + $this->assertEquals(2, $data['occurrences']); + } + + /** + * Test getTag service which is not case sensitive: occurrences with both sTuff and stuff + */ + public function testGetTagNotCaseSensitive() + { + $tagName = 'sTuff'; + $env = Environment::mock([ + 'REQUEST_METHOD' => 'GET', + ]); + $request = Request::createFromEnvironment($env); + + $response = $this->controller->getTag($request, new Response(), ['tagName' => $tagName]); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode((string) $response->getBody(), true); + $this->assertEquals(self::NB_FIELDS_TAG, count($data)); + $this->assertEquals($tagName, $data['name']); + $this->assertEquals(2, $data['occurrences']); + } + + /** + * Test basic getLink service: get non existent link => ApiLinkNotFoundException. + * + * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException + * @expectedExceptionMessage Tag not found + */ + public function testGetTag404() + { + $env = Environment::mock([ + 'REQUEST_METHOD' => 'GET', + ]); + $request = Request::createFromEnvironment($env); + + $this->controller->getTag($request, new Response(), ['tagName' => 'nopenope']); + } +} -- cgit v1.2.3 From 7c57bd95383ec7a7d40735957ea9a792c370b5db Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 4 Jun 2018 18:58:59 +0200 Subject: GetTagsTest - Update to alpha sort for equal occurences --- tests/api/controllers/tags/GetTagNameTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/api/controllers/tags/GetTagNameTest.php') diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index d60f5b38..afac228e 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -112,7 +112,7 @@ class GetTagNameTest extends \PHPUnit_Framework_TestCase } /** - * Test basic getLink service: get non existent link => ApiLinkNotFoundException. + * Test basic getTag service: get non existent tag => ApiTagNotFoundException. * * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException * @expectedExceptionMessage Tag not found -- cgit v1.2.3