From ca9a83ee511a1e9c54d375b76509de699bd2164a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 24 Feb 2017 11:31:31 +0100 Subject: return id of article instead of true if entry exists --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 409a8291..dc5160c7 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -642,7 +642,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(true, $content['exists']); + $this->assertEquals(2, $content['exists']); } public function testGetEntriesExistsWithManyUrls() @@ -657,7 +657,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey($url1, $content); $this->assertArrayHasKey($url2, $content); - $this->assertEquals(true, $content[$url1]); + $this->assertEquals(2, $content[$url1]); $this->assertEquals(false, $content[$url2]); } -- cgit v1.2.3 From fdd725f58cfe96d9bb9454d0347f6ff847fce69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 20 Apr 2017 14:58:20 +0200 Subject: Added notmatches operator for tagging rule --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index dc5160c7..d9acacfc 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -337,7 +337,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals(false, $content['is_starred']); $this->assertEquals('New title for my article', $content['title']); $this->assertEquals(1, $content['user_id']); - $this->assertCount(1, $content['tags']); + $this->assertCount(2, $content['tags']); } public function testPostSameEntry() @@ -356,7 +356,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); $this->assertEquals(true, $content['is_archived']); $this->assertEquals(false, $content['is_starred']); - $this->assertCount(2, $content['tags']); + $this->assertCount(3, $content['tags']); } public function testPostArchivedAndStarredEntry() -- cgit v1.2.3 From d1fc590211b8dc7360bf5b7ee01c67ccff0577ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Apr 2017 11:12:41 +0200 Subject: Added API endpoint to handle a list of URL and to add/delete tags --- .../Controller/EntryRestControllerTest.php | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index dc5160c7..1f5c7a4f 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -714,4 +714,35 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); } + + public function testPostEntriesTagsListAction() + { + $list = [ + [ + 'url' => 'http://0.0.0.0/entry1', + 'tags' => 'foo bar, baz', + 'action' => 'delete', + ], + [ + 'url' => 'http://0.0.0.0/entry2', + 'tags' => 'new tag 1, new tag 2', + 'action' => 'add', + ], + ]; + + $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + + $this->assertFalse($content[0]['entry']); + $this->assertEquals('http://0.0.0.0/entry1', $content[0]['url']); + $this->assertEquals('delete', $content[0]['action']); + + $this->assertInternalType('int', $content[1]['entry']); + $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); + $this->assertEquals('add', $content[1]['action']); + } } -- cgit v1.2.3 From 80299ed282d4f18ef92a79f29f9346b96acde468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Apr 2017 12:24:17 +0200 Subject: Added endpoint to handle URL list to add/delete tags --- .../Controller/EntryRestControllerTest.php | 59 ++++++++++++++++++---- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 1f5c7a4f..638e8bcd 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -717,32 +717,69 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testPostEntriesTagsListAction() { + $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + + $tags = $entry->getTags(); + + $this->assertCount(4, $tags); + $list = [ [ - 'url' => 'http://0.0.0.0/entry1', - 'tags' => 'foo bar, baz', - 'action' => 'delete', + 'url' => 'http://0.0.0.0/entry2', + 'tags' => 'new tag 1, new tag 2', ], + ]; + + $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertInternalType('int', $content[0]['entry']); + $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); + + $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + + $tags = $entry->getTags(); + $this->assertCount(6, $tags); + } + + public function testDeleteEntriesTagsListAction() + { + $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + + $tags = $entry->getTags(); + + $this->assertCount(6, $tags); + + $list = [ [ 'url' => 'http://0.0.0.0/entry2', 'tags' => 'new tag 1, new tag 2', - 'action' => 'add', ], ]; - $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); + $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); + $this->assertInternalType('int', $content[0]['entry']); + $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); - $this->assertFalse($content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry1', $content[0]['url']); - $this->assertEquals('delete', $content[0]['action']); + $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); - $this->assertInternalType('int', $content[1]['entry']); - $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); - $this->assertEquals('add', $content[1]['action']); + $tags = $entry->getTags(); + $this->assertCount(4, $tags); } } -- cgit v1.2.3 From dcbebc17aaa50ea16eb0b7e379c14ebbcf0a645a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 29 Apr 2017 12:58:39 +0200 Subject: Fix tests --- .../Controller/EntryRestControllerTest.php | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 638e8bcd..19fb5170 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -298,7 +298,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser(1, ['id' => 'asc']); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -719,15 +719,15 @@ class EntryRestControllerTest extends WallabagApiTestCase { $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); $tags = $entry->getTags(); - $this->assertCount(4, $tags); + $this->assertCount(2, $tags); $list = [ [ - 'url' => 'http://0.0.0.0/entry2', + 'url' => 'http://0.0.0.0/entry4', 'tags' => 'new tag 1, new tag 2', ], ]; @@ -739,29 +739,29 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertInternalType('int', $content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); + $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); $tags = $entry->getTags(); - $this->assertCount(6, $tags); + $this->assertCount(4, $tags); } public function testDeleteEntriesTagsListAction() { $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); $tags = $entry->getTags(); - $this->assertCount(6, $tags); + $this->assertCount(4, $tags); $list = [ [ - 'url' => 'http://0.0.0.0/entry2', + 'url' => 'http://0.0.0.0/entry4', 'tags' => 'new tag 1, new tag 2', ], ]; @@ -773,13 +773,13 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertInternalType('int', $content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); + $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry2', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); $tags = $entry->getTags(); - $this->assertCount(4, $tags); + $this->assertCount(2, $tags); } } -- cgit v1.2.3 From 1eca7831a69b9470b92dcc72e1ce51b42b291338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Apr 2017 10:22:57 +0200 Subject: Added API endpoint to handle a list of URL By passing an array, you can add / delete URL in mass (bulk request) --- .../Controller/EntryRestControllerTest.php | 46 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 19fb5170..c37d08cb 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -766,20 +766,50 @@ class EntryRestControllerTest extends WallabagApiTestCase ], ]; - $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); + $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list)); + } + + public function testPostMassEntriesAction() + { + $list = [ + [ + 'url' => 'http://0.0.0.0/entry2', + 'action' => 'delete', + ], + [ + 'url' => 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', + 'action' => 'add', + ], + [ + 'url' => 'http://0.0.0.0/entry3', + 'action' => 'delete', + ], + [ + 'url' => 'http://0.0.0.0/entry6', + 'action' => 'add', + ], + ]; + + $this->client->request('POST', '/api/entries/lists?list='.json_encode($list)); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertInternalType('int', $content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); + $this->assertTrue($content[0]['entry']); + $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); + $this->assertEquals('delete', $content[0]['action']); - $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); + $this->assertInternalType('int', $content[1]['entry']); + $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[1]['url']); + $this->assertEquals('add', $content[1]['action']); - $tags = $entry->getTags(); - $this->assertCount(2, $tags); + $this->assertFalse($content[2]['entry']); + $this->assertEquals('http://0.0.0.0/entry3', $content[2]['url']); + $this->assertEquals('delete', $content[2]['action']); + + $this->assertInternalType('int', $content[3]['entry']); + $this->assertEquals('http://0.0.0.0/entry6', $content[3]['url']); + $this->assertEquals('add', $content[3]['action']); } } -- cgit v1.2.3 From a7abcc7b7a5e3417eff70e2a5993558f83fc5d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 24 Apr 2017 11:31:00 +0200 Subject: Splitted the endpoint in two --- .../Controller/EntryRestControllerTest.php | 55 ++++++++++------------ 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index c37d08cb..64c24a2d 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -769,47 +769,44 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list)); } - public function testPostMassEntriesAction() + + public function testPostEntriesListAction() { $list = [ - [ - 'url' => 'http://0.0.0.0/entry2', - 'action' => 'delete', - ], - [ - 'url' => 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', - 'action' => 'add', - ], - [ - 'url' => 'http://0.0.0.0/entry3', - 'action' => 'delete', - ], - [ - 'url' => 'http://0.0.0.0/entry6', - 'action' => 'add', - ], + 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', + 'http://0.0.0.0/entry6', ]; - $this->client->request('POST', '/api/entries/lists?list='.json_encode($list)); + $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertTrue($content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); - $this->assertEquals('delete', $content[0]['action']); + $this->assertInternalType('int', $content[0]['entry']); + $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); $this->assertInternalType('int', $content[1]['entry']); - $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[1]['url']); - $this->assertEquals('add', $content[1]['action']); + $this->assertEquals('http://0.0.0.0/entry6', $content[1]['url']); + } + + public function testDeleteEntriesListAction() + { + $list = [ + 'http://0.0.0.0/entry2', + 'http://0.0.0.0/entry3', + ]; + + $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); - $this->assertFalse($content[2]['entry']); - $this->assertEquals('http://0.0.0.0/entry3', $content[2]['url']); - $this->assertEquals('delete', $content[2]['action']); + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertTrue($content[0]['entry']); + $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); - $this->assertInternalType('int', $content[3]['entry']); - $this->assertEquals('http://0.0.0.0/entry6', $content[3]['url']); - $this->assertEquals('add', $content[3]['action']); + $this->assertFalse($content[1]['entry']); + $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); } } -- cgit v1.2.3 From 719ba257d3d6495eaa0f4ea749b5aa4740f94dda Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 29 Apr 2017 12:24:27 +0200 Subject: Fix tests --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 64c24a2d..b732a8be 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -774,7 +774,7 @@ class EntryRestControllerTest extends WallabagApiTestCase { $list = [ 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', - 'http://0.0.0.0/entry6', + 'http://0.0.0.0/entry1', ]; $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); @@ -787,13 +787,13 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); $this->assertInternalType('int', $content[1]['entry']); - $this->assertEquals('http://0.0.0.0/entry6', $content[1]['url']); + $this->assertEquals('http://0.0.0.0/entry1', $content[1]['url']); } public function testDeleteEntriesListAction() { $list = [ - 'http://0.0.0.0/entry2', + 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', 'http://0.0.0.0/entry3', ]; @@ -804,7 +804,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertTrue($content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry2', $content[0]['url']); + $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); $this->assertFalse($content[1]['entry']); $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); -- cgit v1.2.3 From 7fa844a34983f9929348e70ddd408cf6ba5811b6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 29 Apr 2017 12:32:26 +0200 Subject: Fix tests (for real this time) --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index b732a8be..88a5be93 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -774,7 +774,7 @@ class EntryRestControllerTest extends WallabagApiTestCase { $list = [ 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', - 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry2', ]; $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); @@ -787,7 +787,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); $this->assertInternalType('int', $content[1]['entry']); - $this->assertEquals('http://0.0.0.0/entry1', $content[1]['url']); + $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); } public function testDeleteEntriesListAction() -- cgit v1.2.3 From efd351c98fa0caa4c8df9c7ff6965c537524f12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 1 May 2017 09:21:59 +0200 Subject: Added limit --- .../Controller/EntryRestControllerTest.php | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 88a5be93..8594ad0b 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -809,4 +809,27 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertFalse($content[1]['entry']); $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage API limit reached + */ + public function testLimitBulkAction() + { + $list = [ + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + 'http://0.0.0.0/entry1', + ]; + + $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); + } } -- cgit v1.2.3 From 72db15ca5d7950a604f359056fc6a627f25e4ee4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 5 May 2017 12:05:50 +0200 Subject: Little refacto and send 400 on reaching urls limit --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 8594ad0b..34a2f894 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -810,10 +810,6 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); } - /** - * @expectedException Symfony\Component\Config\Definition\Exception\Exception - * @expectedExceptionMessage API limit reached - */ public function testLimitBulkAction() { $list = [ @@ -831,5 +827,8 @@ class EntryRestControllerTest extends WallabagApiTestCase ]; $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); + + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); } } -- cgit v1.2.3 From 7d2d1d685920e8b4975c3967c031ae0abb7098c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 5 May 2017 15:14:58 +0200 Subject: Added migrations execution after fresh install --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index f0173cef..362c269b 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -766,10 +766,9 @@ class EntryRestControllerTest extends WallabagApiTestCase ], ]; - $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list)); + $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); } - public function testPostEntriesListAction() { $list = [ -- cgit v1.2.3 From 1594a79fc5eefe217ed463144857d0693b6714fa Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 23:15:25 +0200 Subject: Retrieve tag / tags value from query or request It allows to request to delete a tag using query string instead of body parameter (which seems to be the standard). Instead of breaking the previous behavior, I used a generic way to retrieve parameter (which looks into request attributes, query parameters and request parameters) --- .../ApiBundle/Controller/TagRestControllerTest.php | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index bde5251f..90b132eb 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -54,7 +54,18 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); } - public function testDeleteTagByLabel() + public function dataForDeletingTagByLabel() + { + return [ + 'by_query' => [true], + 'by_body' => [false], + ]; + } + + /** + * @dataProvider dataForDeletingTagByLabel + */ + public function testDeleteTagByLabel($useQueryString) { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); $entry = $this->client->getContainer() @@ -73,7 +84,11 @@ class TagRestControllerTest extends WallabagApiTestCase $em->persist($entry); $em->flush(); - $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); + if ($useQueryString) { + $this->client->request('DELETE', '/api/tag/label.json?tag='.$tag->getLabel()); + } else { + $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); + } $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -98,7 +113,10 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); } - public function testDeleteTagsByLabel() + /** + * @dataProvider dataForDeletingTagByLabel + */ + public function testDeleteTagsByLabel($useQueryString) { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); $entry = $this->client->getContainer() @@ -122,7 +140,11 @@ class TagRestControllerTest extends WallabagApiTestCase $em->persist($entry); $em->flush(); - $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + if ($useQueryString) { + $this->client->request('DELETE', '/api/tags/label.json?tags='.$tag->getLabel().','.$tag2->getLabel()); + } else { + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + } $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); -- cgit v1.2.3 From 5709ecb36809fb009446a11a758232bbe8f264e4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 07:56:01 +0200 Subject: Re-use `NewUserType` to validate registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only ugly things is how we handle error by generating the view and then parse the content to retrieve all errors… Fix exposition fields in User entity --- .../Controller/UserRestControllerTest.php | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php new file mode 100644 index 00000000..21d59a16 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -0,0 +1,98 @@ +client->request('GET', '/api/user.json'); + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('id', $content); + $this->assertArrayHasKey('email', $content); + $this->assertArrayHasKey('name', $content); + $this->assertArrayHasKey('username', $content); + $this->assertArrayHasKey('created_at', $content); + $this->assertArrayHasKey('updated_at', $content); + + $this->assertEquals('bigboss@wallabag.org', $content['email']); + $this->assertEquals('Big boss', $content['name']); + $this->assertEquals('admin', $content['username']); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testCreateNewUser() + { + $this->client->request('PUT', '/api/user.json', [ + 'username' => 'google', + 'password' => 'googlegoogle', + 'email' => 'wallabag@google.com', + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('id', $content); + $this->assertArrayHasKey('email', $content); + $this->assertArrayHasKey('username', $content); + $this->assertArrayHasKey('created_at', $content); + $this->assertArrayHasKey('updated_at', $content); + + $this->assertEquals('wallabag@google.com', $content['email']); + $this->assertEquals('google', $content['username']); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testCreateNewUserWithExistingEmail() + { + $this->client->request('PUT', '/api/user.json', [ + 'username' => 'google', + 'password' => 'googlegoogle', + 'email' => 'bigboss@wallabag.org', + ]); + + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('error', $content); + $this->assertArrayHasKey('username', $content['error']); + $this->assertArrayHasKey('email', $content['error']); + + // $this->assertEquals('fos_user.username.already_used', $content['error']['username'][0]); + // $this->assertEquals('fos_user.email.already_used', $content['error']['email'][0]); + // This shouldn't be translated ... + $this->assertEquals('This value is already used.', $content['error']['username'][0]); + $this->assertEquals('This value is already used.', $content['error']['email'][0]); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testCreateNewUserWithTooShortPassword() + { + $this->client->request('PUT', '/api/user.json', [ + 'username' => 'facebook', + 'password' => 'face', + 'email' => 'facebook@wallabag.org', + ]); + + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('error', $content); + $this->assertArrayHasKey('password', $content['error']); + + $this->assertEquals('validator.password_too_short', $content['error']['password'][0]); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } +} -- cgit v1.2.3 From fe6461e4aaff5aa2fd846492e3abd9ea38c07a5b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 09:57:57 +0200 Subject: Avoid side effect on other tests --- .../ApiBundle/Controller/UserRestControllerTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index 21d59a16..3f4969a5 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -49,12 +49,24 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertEquals('google', $content['username']); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + + // remove the created user to avoid side effect on other tests + // @todo remove these lines when test will be isolated + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + + $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Config c WHERE c.user = :user_id'); + $query->setParameter('user_id', $content['id']); + $query->execute(); + + $query = $em->createQuery('DELETE FROM Wallabag\UserBundle\Entity\User u WHERE u.id = :id'); + $query->setParameter('id', $content['id']); + $query->execute(); } public function testCreateNewUserWithExistingEmail() { $this->client->request('PUT', '/api/user.json', [ - 'username' => 'google', + 'username' => 'admin', 'password' => 'googlegoogle', 'email' => 'bigboss@wallabag.org', ]); -- cgit v1.2.3 From e668a8124c46d47add4248963d77f3b29b37b3ce Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 11 May 2017 08:14:29 +0200 Subject: Allow other fields to be send using API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Entry API can now have these new fields: - content - language - preview_picture - published_at Re-use the ContentProxy to be able to do the same using the web UI (in the future). htmLawed is used to clean stuff from content, I hope it’ll be enough to avoid security breach. Lower content validation when we want to update an entry with content already defined. Before, language & content_type were required. If there weren’t provided, we re-fetched the content using graby. I think these fields aren’t required for an entry to be created. So I removed them. Which means some import from the v1 export won’t be re-fetched since they provide content, url & title. Also, remove liberation link from Readability import to avoid overlaping import (from wallabag v1, which had the same link) --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index bf7d373a..1b0c06d2 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -342,6 +342,9 @@ class EntryRestControllerTest extends WallabagApiTestCase 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', 'tags' => 'google', 'title' => 'New title for my article', + 'content' => 'my content', + 'language' => 'de_DE', + 'published_at' => '2016-09-08T11:55:58+0200', ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -355,6 +358,9 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('New title for my article', $content['title']); $this->assertEquals(1, $content['user_id']); $this->assertCount(2, $content['tags']); + $this->assertSame('my content', $content['content']); + $this->assertSame('de_DE', $content['language']); + $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); } public function testPostSameEntry() -- cgit v1.2.3 From fb436e8ca0c7468b9698050df0b78447e2d0854f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 11 May 2017 20:10:22 +0200 Subject: Add support for authors --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 1b0c06d2..e9ba4634 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -345,6 +345,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'content' => 'my content', 'language' => 'de_DE', 'published_at' => '2016-09-08T11:55:58+0200', + 'authors' => 'bob,helen', ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -361,6 +362,9 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('my content', $content['content']); $this->assertSame('de_DE', $content['language']); $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); + $this->assertCount(2, $content['published_by']); + $this->assertContains('bob', $content['published_by']); + $this->assertContains('helen', $content['published_by']); } public function testPostSameEntry() -- cgit v1.2.3 From 7ab5eb9508921d84b4b4ec84a59135d536da748e Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 15 May 2017 20:47:59 +0200 Subject: Isolated tests Use https://github.com/dmaicher/doctrine-test-bundle to have test isolation. --- .../Controller/DeveloperControllerTest.php | 40 +++++++++++++++------- .../Controller/EntryRestControllerTest.php | 37 +++++++++++++------- .../ApiBundle/Controller/TagRestControllerTest.php | 33 +++++++++--------- 3 files changed, 69 insertions(+), 41 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 6659443b..d37cbbf9 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\ApiBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\ApiBundle\Entity\Client; class DeveloperControllerTest extends WallabagCoreTestCase { @@ -33,14 +34,10 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertContains('My app', $alert[0]); } - /** - * @depends testCreateClient - */ public function testCreateToken() { $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); + $apiClient = $this->createApiClientForUser('admin'); $client->request('POST', '/oauth/v2/token', [ 'grant_type' => 'password', @@ -83,6 +80,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase public function testRemoveClient() { $client = $this->getClient(); + $adminApiClient = $this->createApiClientForUser('admin'); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); // Try to remove an admin's client with a wrong user @@ -90,12 +88,8 @@ class DeveloperControllerTest extends WallabagCoreTestCase $client->request('GET', '/developer'); $this->assertContains('no_client', $client->getResponse()->getContent()); - // get an ID of a admin's client - $this->logInAs('admin'); - $nbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); - $this->logInAs('bob'); - $client->request('GET', '/developer/client/delete/'.$nbClients[0]->getId()); + $client->request('GET', '/developer/client/delete/'.$adminApiClient->getId()); $this->assertEquals(403, $client->getResponse()->getStatusCode()); // Try to remove the admin's client with the good user @@ -111,7 +105,29 @@ class DeveloperControllerTest extends WallabagCoreTestCase $client->click($link); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); - $this->assertGreaterThan(count($newNbClients), count($nbClients)); + $this->assertNull( + $em->getRepository('WallabagApiBundle:Client')->find($adminApiClient->getId()), + 'The client should have been removed' + ); + } + + /** + * @param string $username + * + * @return Client + */ + private function createApiClientForUser($username) + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $userManager = $client->getContainer()->get('fos_user.user_manager'); + $user = $userManager->findUserBy(array('username' => $username)); + $apiClient = new Client($user); + $apiClient->setName('My app'); + $apiClient->setAllowedGrantTypes(['password']); + $em->persist($apiClient); + $em->flush(); + + return $apiClient; } } diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index bf7d373a..1ecd03fb 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -3,8 +3,10 @@ namespace Tests\Wallabag\ApiBundle\Controller; use Tests\Wallabag\ApiBundle\WallabagApiTestCase; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Helper\ContentProxy; +use Wallabag\UserBundle\Entity\User; class EntryRestControllerTest extends WallabagApiTestCase { @@ -801,22 +803,28 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testDeleteEntriesTagsListAction() { - $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = new Entry($em->getReference(User::class, 1)); + $entry->setUrl('http://0.0.0.0/test-entry'); + $entry->addTag((new Tag())->setLabel('foo-tag')); + $entry->addTag((new Tag())->setLabel('bar-tag')); + $em->persist($entry); + $em->flush(); - $tags = $entry->getTags(); - - $this->assertCount(4, $tags); + $em->clear(); $list = [ [ - 'url' => 'http://0.0.0.0/entry4', - 'tags' => 'new tag 1, new tag 2', + 'url' => 'http://0.0.0.0/test-entry', + 'tags' => 'foo-tag, bar-tag', ], ]; $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId()); + $this->assertCount(0, $entry->getTags()); } public function testPostEntriesListAction() @@ -841,9 +849,14 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testDeleteEntriesListAction() { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); + + $em->flush(); + $em->clear(); $list = [ - 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', - 'http://0.0.0.0/entry3', + 'http://0.0.0.0/test-entry1', + 'http://0.0.0.0/test-entry-not-exist', ]; $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); @@ -853,10 +866,10 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertTrue($content[0]['entry']); - $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); + $this->assertEquals('http://0.0.0.0/test-entry1', $content[0]['url']); $this->assertFalse($content[1]['entry']); - $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); + $this->assertEquals('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); } public function testLimitBulkAction() diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 90b132eb..7f69bd67 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -22,36 +22,35 @@ class TagRestControllerTest extends WallabagApiTestCase return end($content); } - /** - * @depends testGetUserTags - */ - public function testDeleteUserTag($tag) + public function testDeleteUserTag() { - $tagName = $tag['label']; + $tagLabel = 'tagtest'; + $tag = new Tag(); + $tag->setLabel($tagLabel); + + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $em->persist($tag); + $em->flush(); + $em->clear(); - $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); + $this->client->request('DELETE', '/api/tags/'.$tag->getId().'.json'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('label', $content); - $this->assertEquals($tag['label'], $content['label']); - $this->assertEquals($tag['slug'], $content['slug']); + $this->assertEquals($tag->getLabel(), $content['label']); + $this->assertEquals($tag->getSlug(), $content['slug']); - $entries = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findAllByTagId($this->user->getId(), $tag['id']); + $entries = $em->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->user->getId(), $tag->getId()); $this->assertCount(0, $entries); - $tag = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($tagName); + $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); - $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); + $this->assertNull($tag, $tagLabel.' was removed because it begun an orphan tag'); } public function dataForDeletingTagByLabel() -- cgit v1.2.3 From 426bb453d295900fb3e35dce2f9081a42639cf27 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 2 Jun 2017 10:19:33 +0200 Subject: API user creation behing a toggle I've added a toggle feature (in internal settings) so that user api creation can be disabled while form registration still can be enabled. Also, the /api/user endpoint shouldn't require authentication. Even if we check the authentication when sending a GET request, to retrieve current user information. I've moved all the internal settings definition to config to avoid duplicated place to define them. I don't know why we didn't did that earlier. --- .../Controller/UserRestControllerTest.php | 96 ++++++++++++++++++---- .../Controller/WallabagRestControllerTest.php | 10 ++- 2 files changed, 85 insertions(+), 21 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index 3f4969a5..c1095da8 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -27,8 +27,25 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); } + public function testGetUserWithoutAuthentication() + { + $client = static::createClient(); + $client->request('GET', '/api/user.json'); + $this->assertEquals(401, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('error', $content); + $this->assertArrayHasKey('error_description', $content); + + $this->assertEquals('access_denied', $content['error']); + + $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + } + public function testCreateNewUser() { + $this->client->getContainer()->get('craue_config')->set('api_user_registration', 1); $this->client->request('PUT', '/api/user.json', [ 'username' => 'google', 'password' => 'googlegoogle', @@ -50,30 +67,51 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); - // remove the created user to avoid side effect on other tests - // @todo remove these lines when test will be isolated - $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $this->client->getContainer()->get('craue_config')->set('api_user_registration', 0); + } + + public function testCreateNewUserWithoutAuthentication() + { + // create a new client instead of using $this->client to be sure client isn't authenticated + $client = static::createClient(); + $client->getContainer()->get('craue_config')->set('api_user_registration', 1); + $client->request('PUT', '/api/user.json', [ + 'username' => 'google', + 'password' => 'googlegoogle', + 'email' => 'wallabag@google.com', + ]); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('id', $content); + $this->assertArrayHasKey('email', $content); + $this->assertArrayHasKey('username', $content); + $this->assertArrayHasKey('created_at', $content); + $this->assertArrayHasKey('updated_at', $content); + + $this->assertEquals('wallabag@google.com', $content['email']); + $this->assertEquals('google', $content['username']); - $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Config c WHERE c.user = :user_id'); - $query->setParameter('user_id', $content['id']); - $query->execute(); + $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); - $query = $em->createQuery('DELETE FROM Wallabag\UserBundle\Entity\User u WHERE u.id = :id'); - $query->setParameter('id', $content['id']); - $query->execute(); + $client->getContainer()->get('craue_config')->set('api_user_registration', 0); } public function testCreateNewUserWithExistingEmail() { - $this->client->request('PUT', '/api/user.json', [ + $client = static::createClient(); + $client->getContainer()->get('craue_config')->set('api_user_registration', 1); + $client->request('PUT', '/api/user.json', [ 'username' => 'admin', 'password' => 'googlegoogle', 'email' => 'bigboss@wallabag.org', ]); - $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + $this->assertEquals(400, $client->getResponse()->getStatusCode()); - $content = json_decode($this->client->getResponse()->getContent(), true); + $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('error', $content); $this->assertArrayHasKey('username', $content['error']); @@ -85,26 +123,50 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertEquals('This value is already used.', $content['error']['username'][0]); $this->assertEquals('This value is already used.', $content['error']['email'][0]); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + + $client->getContainer()->get('craue_config')->set('api_user_registration', 0); } public function testCreateNewUserWithTooShortPassword() { - $this->client->request('PUT', '/api/user.json', [ + $client = static::createClient(); + $client->getContainer()->get('craue_config')->set('api_user_registration', 1); + $client->request('PUT', '/api/user.json', [ 'username' => 'facebook', 'password' => 'face', 'email' => 'facebook@wallabag.org', ]); - $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + $this->assertEquals(400, $client->getResponse()->getStatusCode()); - $content = json_decode($this->client->getResponse()->getContent(), true); + $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('error', $content); $this->assertArrayHasKey('password', $content['error']); $this->assertEquals('validator.password_too_short', $content['error']['password'][0]); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + + $client->getContainer()->get('craue_config')->set('api_user_registration', 0); + } + + public function testCreateNewUserWhenRegistrationIsDisabled() + { + $client = static::createClient(); + $client->request('PUT', '/api/user.json', [ + 'username' => 'facebook', + 'password' => 'face', + 'email' => 'facebook@wallabag.org', + ]); + + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('error', $content); + + $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); } } diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index c87e58de..df638e8f 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -8,12 +8,14 @@ class WallabagRestControllerTest extends WallabagApiTestCase { public function testGetVersion() { - $this->client->request('GET', '/api/version'); + // create a new client instead of using $this->client to be sure client isn't authenticated + $client = static::createClient(); + $client->request('GET', '/api/version'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $content = json_decode($this->client->getResponse()->getContent(), true); + $content = json_decode($client->getResponse()->getContent(), true); - $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content); + $this->assertEquals($client->getContainer()->getParameter('wallabag_core.version'), $content); } } -- cgit v1.2.3 From a1e6187406289b6b54f8044ba1f209979454204b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 2 Jun 2017 20:03:25 +0200 Subject: Return 201 on user creation --- tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index c1095da8..5735bc58 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -52,7 +52,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'email' => 'wallabag@google.com', ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertEquals(201, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -81,7 +81,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'email' => 'wallabag@google.com', ]); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(201, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); -- cgit v1.2.3 From 645291e8feb0f3e977b9518da7d731fda8cf1f30 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 2 Jun 2017 20:52:49 +0200 Subject: Add ability to patch an entry with more fields Like when we create an entry, we can now patch an entry with new fields: - content - language - preview_picture - published_at - authors --- .../Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 0968cfaf..74ec34b1 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -477,6 +477,10 @@ class EntryRestControllerTest extends WallabagApiTestCase 'tags' => 'new tag '.uniqid(), 'starred' => '1', 'archive' => '0', + 'language' => 'de_DE', + 'preview_picture' => 'http://preview.io/picture.jpg', + 'authors' => 'bob,sponge', + 'content' => 'awesome', ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -488,6 +492,11 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('New awesome title', $content['title']); $this->assertGreaterThan($nbTags, count($content['tags'])); $this->assertEquals(1, $content['user_id']); + $this->assertEquals('de_DE', $content['language']); + $this->assertEquals('http://preview.io/picture.jpg', $content['preview_picture']); + $this->assertContains('sponge', $content['published_by']); + $this->assertContains('bob', $content['published_by']); + $this->assertEquals('awesome', $content['content']); } public function testPatchEntryWithoutQuotes() @@ -509,6 +518,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'tags' => 'new tag '.uniqid(), 'starred' => 1, 'archive' => 0, + 'authors' => ['bob', 'sponge'], ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -519,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals($entry->getUrl(), $content['url']); $this->assertEquals('New awesome title', $content['title']); $this->assertGreaterThan($nbTags, count($content['tags'])); + $this->assertTrue(empty($content['published_by']), 'Authors were not saved because of an array instead of a string'); } public function testGetTagsEntry() -- cgit v1.2.3 From 0c00e5251671c3648eabb8888271c09137ad902d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 7 Jun 2017 23:23:28 +0200 Subject: Create a client when creating a user using the api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While creating a new user using the API, we also create a new client for the current user. So the app which just create the user can use its newly created client to configure the app. That new client is only return after creating the user. When calling the endpoint /api/user to get user information, the new client information won’t be return. --- .../Wallabag/ApiBundle/Controller/UserRestControllerTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index 5735bc58..9f01a976 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -61,10 +61,16 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('username', $content); $this->assertArrayHasKey('created_at', $content); $this->assertArrayHasKey('updated_at', $content); + $this->assertArrayHasKey('default_client', $content); $this->assertEquals('wallabag@google.com', $content['email']); $this->assertEquals('google', $content['username']); + $this->assertArrayHasKey('client_secret', $content['default_client']); + $this->assertArrayHasKey('client_id', $content['default_client']); + + $this->assertEquals('Default client', $content['default_client']['name']); + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); $this->client->getContainer()->get('craue_config')->set('api_user_registration', 0); @@ -90,10 +96,16 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('username', $content); $this->assertArrayHasKey('created_at', $content); $this->assertArrayHasKey('updated_at', $content); + $this->assertArrayHasKey('default_client', $content); $this->assertEquals('wallabag@google.com', $content['email']); $this->assertEquals('google', $content['username']); + $this->assertArrayHasKey('client_secret', $content['default_client']); + $this->assertArrayHasKey('client_id', $content['default_client']); + + $this->assertEquals('Default client', $content['default_client']['name']); + $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); $client->getContainer()->get('craue_config')->set('api_user_registration', 0); -- cgit v1.2.3 From a8d3fe50df52ec486add5691a3b67fe5205a032e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 14:25:44 +0200 Subject: Add ability to name the client --- tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index 9f01a976..4e65f130 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -85,6 +85,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'username' => 'google', 'password' => 'googlegoogle', 'email' => 'wallabag@google.com', + 'client_name' => 'My client name !!', ]); $this->assertEquals(201, $client->getResponse()->getStatusCode()); @@ -104,7 +105,7 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('client_secret', $content['default_client']); $this->assertArrayHasKey('client_id', $content['default_client']); - $this->assertEquals('Default client', $content['default_client']['name']); + $this->assertEquals('My client name !!', $content['default_client']['name']); $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); -- cgit v1.2.3 From e9056dd96f9e8c2e06b5752b8de767bbedfc71ea Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 22:51:30 +0200 Subject: Fix test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit de_DE is not valid language. Zataz doesn’t send a valid language in their content (they use `fr-FR`). --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 74ec34b1..4aa60e90 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -345,7 +345,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'tags' => 'google', 'title' => 'New title for my article', 'content' => 'my content', - 'language' => 'de_DE', + 'language' => 'de', 'published_at' => '2016-09-08T11:55:58+0200', 'authors' => 'bob,helen', ]); @@ -362,7 +362,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals(1, $content['user_id']); $this->assertCount(2, $content['tags']); $this->assertSame('my content', $content['content']); - $this->assertSame('de_DE', $content['language']); + $this->assertSame('de', $content['language']); $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); $this->assertCount(2, $content['published_by']); $this->assertContains('bob', $content['published_by']); @@ -477,7 +477,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'tags' => 'new tag '.uniqid(), 'starred' => '1', 'archive' => '0', - 'language' => 'de_DE', + 'language' => 'de_AT', 'preview_picture' => 'http://preview.io/picture.jpg', 'authors' => 'bob,sponge', 'content' => 'awesome', @@ -492,7 +492,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals('New awesome title', $content['title']); $this->assertGreaterThan($nbTags, count($content['tags'])); $this->assertEquals(1, $content['user_id']); - $this->assertEquals('de_DE', $content['language']); + $this->assertEquals('de_AT', $content['language']); $this->assertEquals('http://preview.io/picture.jpg', $content['preview_picture']); $this->assertContains('sponge', $content['published_by']); $this->assertContains('bob', $content['published_by']); -- cgit v1.2.3 From 1112e54772c9308ee3d7417869b5b8ef9b2b9812 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 10 Jun 2017 15:31:57 +0200 Subject: Add public filter/field in the API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Listing entries can now be filtered by “public”. Creating or patching an entry can now set is to public or remove the public. Entry response now include “is_public” boolean field --- .../Controller/EntryRestControllerTest.php | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 4aa60e90..067aed2c 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -128,6 +128,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'perPage' => 2, 'tags' => 'foo', 'since' => 1443274283, + 'public' => 0, ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -154,6 +155,53 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('order=asc', $content['_links'][$link]['href']); $this->assertContains('tags=foo', $content['_links'][$link]['href']); $this->assertContains('since=1443274283', $content['_links'][$link]['href']); + $this->assertContains('public=0', $content['_links'][$link]['href']); + } + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testGetEntriesPublicOnly() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + // generate at least one public entry + $entry->generateUid(); + + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $em->persist($entry); + $em->flush(); + + $this->client->request('GET', '/api/entries', [ + 'public' => 1, + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertArrayHasKey('items', $content['_embedded']); + $this->assertGreaterThanOrEqual(1, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertEquals(30, $content['limit']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('public=1', $content['_links'][$link]['href']); } $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); @@ -348,6 +396,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'language' => 'de', 'published_at' => '2016-09-08T11:55:58+0200', 'authors' => 'bob,helen', + 'public' => 1, ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -367,6 +416,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertCount(2, $content['published_by']); $this->assertContains('bob', $content['published_by']); $this->assertContains('helen', $content['published_by']); + $this->assertTrue($content['is_public'], 'A public link has been generated for that entry'); } public function testPostSameEntry() @@ -481,6 +531,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'preview_picture' => 'http://preview.io/picture.jpg', 'authors' => 'bob,sponge', 'content' => 'awesome', + 'public' => 0, ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -497,6 +548,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('sponge', $content['published_by']); $this->assertContains('bob', $content['published_by']); $this->assertEquals('awesome', $content['content']); + $this->assertFalse($content['is_public'], 'Entry is no more shared'); } public function testPatchEntryWithoutQuotes() -- cgit v1.2.3 From caa0b1765b8c249ff4a868980d90e3410b26b664 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 14 Jun 2017 17:30:12 +0200 Subject: Add client_credentials oAuth2 auth method Signed-off-by: Thomas Citharel --- .../Controller/DeveloperControllerTest.php | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index d37cbbf9..53aed12b 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -34,7 +34,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertContains('My app', $alert[0]); } - public function testCreateToken() + public function testCreateTokenFromPasswords() { $client = $this->getClient(); $apiClient = $this->createApiClientForUser('admin'); @@ -56,6 +56,26 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('refresh_token', $data); } + public function testCreateTokenFromClientCredentialsOnly() + { + $client = $this->getClient(); + $apiClient = $this->createApiClientForUser('admin', ['client_credentials']); + + $client->request('POST', '/oauth/v2/token', [ + 'grant_type' => 'client_credentials', + 'client_id' => $apiClient->getPublicId(), + 'client_secret' => $apiClient->getSecret(), + ]); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $data = json_decode($client->getResponse()->getContent(), true); + $this->assertArrayHasKey('access_token', $data); + $this->assertArrayHasKey('expires_in', $data); + $this->assertArrayHasKey('token_type', $data); + // Client Credentials created-clients have no refresh tokens + } + public function testListingClient() { $this->logInAs('admin'); @@ -114,9 +134,10 @@ class DeveloperControllerTest extends WallabagCoreTestCase /** * @param string $username * + * @param array $grantTypes * @return Client */ - private function createApiClientForUser($username) + private function createApiClientForUser($username, $grantTypes = ['password']) { $client = $this->getClient(); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); @@ -124,7 +145,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $user = $userManager->findUserBy(array('username' => $username)); $apiClient = new Client($user); $apiClient->setName('My app'); - $apiClient->setAllowedGrantTypes(['password']); + $apiClient->setAllowedGrantTypes($grantTypes); $em->persist($apiClient); $em->flush(); -- cgit v1.2.3 From 18696f77fdc76f7055d84460d459051a6bb7253a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 23 Jun 2017 08:30:23 +0200 Subject: Avoid BC on exists endpoint --- .../Controller/EntryRestControllerTest.php | 41 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 067aed2c..dc21bd32 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -759,18 +759,51 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals(true, $content['is_starred']); } - public function testGetEntriesExists() + public function dataForEntriesExistWithUrl() { - $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); + return [ + 'with_id' => [ + 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', + 'expectedValue' => 2, + ], + 'without_id' => [ + 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', + 'expectedValue' => true, + ], + ]; + } + + /** + * @dataProvider dataForEntriesExistWithUrl + */ + public function testGetEntriesExists($url, $expectedValue) + { + $this->client->request('GET', $url); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(2, $content['exists']); + $this->assertSame($expectedValue, $content['exists']); } public function testGetEntriesExistsWithManyUrls() + { + $url1 = 'http://0.0.0.0/entry2'; + $url2 = 'http://0.0.0.0/entry10'; + $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2.'&return_id=1'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey($url1, $content); + $this->assertArrayHasKey($url2, $content); + $this->assertSame(2, $content[$url1]); + $this->assertSame(false, $content[$url2]); + } + + public function testGetEntriesExistsWithManyUrlsReturnBool() { $url1 = 'http://0.0.0.0/entry2'; $url2 = 'http://0.0.0.0/entry10'; @@ -782,7 +815,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey($url1, $content); $this->assertArrayHasKey($url2, $content); - $this->assertEquals(2, $content[$url1]); + $this->assertEquals(true, $content[$url1]); $this->assertEquals(false, $content[$url2]); } -- cgit v1.2.3 From 39ffaba3232b6378f47883615c58a9ffba668af3 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 28 Jun 2017 08:15:06 +0200 Subject: Return null instead of false --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index dc21bd32..c0391d87 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -800,7 +800,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey($url1, $content); $this->assertArrayHasKey($url2, $content); $this->assertSame(2, $content[$url1]); - $this->assertSame(false, $content[$url2]); + $this->assertNull($content[$url2]); } public function testGetEntriesExistsWithManyUrlsReturnBool() @@ -815,8 +815,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey($url1, $content); $this->assertArrayHasKey($url2, $content); - $this->assertEquals(true, $content[$url1]); - $this->assertEquals(false, $content[$url2]); + $this->assertTrue($content[$url1]); + $this->assertFalse($content[$url2]); } public function testGetEntriesExistsWhichDoesNotExists() -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../Controller/DeveloperControllerTest.php | 24 +- .../Controller/EntryRestControllerTest.php | 296 ++++++++++----------- .../ApiBundle/Controller/TagRestControllerTest.php | 38 +-- .../Controller/UserRestControllerTest.php | 54 ++-- .../Controller/WallabagRestControllerTest.php | 4 +- 5 files changed, 208 insertions(+), 208 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 53aed12b..2caeccf5 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -15,7 +15,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); $crawler = $client->request('GET', '/developer/client/create'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[type=submit]')->form(); @@ -25,7 +25,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); $this->assertGreaterThan(count($nbClients), count($newNbClients)); @@ -47,7 +47,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase 'password' => 'mypassword', ]); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $data = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('access_token', $data); @@ -67,7 +67,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase 'client_secret' => $apiClient->getSecret(), ]); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $data = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('access_token', $data); @@ -84,8 +84,8 @@ class DeveloperControllerTest extends WallabagCoreTestCase $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); $crawler = $client->request('GET', '/developer'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); + $this->assertSame(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); } public function testDeveloperHowto() @@ -94,7 +94,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $crawler = $client->request('GET', '/developer/howto/first-app'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testRemoveClient() @@ -109,8 +109,8 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertContains('no_client', $client->getResponse()->getContent()); $this->logInAs('bob'); - $client->request('GET', '/developer/client/delete/'.$adminApiClient->getId()); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $client->request('GET', '/developer/client/delete/' . $adminApiClient->getId()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); // Try to remove the admin's client with the good user $this->logInAs('admin'); @@ -123,7 +123,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase ; $client->click($link); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertNull( $em->getRepository('WallabagApiBundle:Client')->find($adminApiClient->getId()), @@ -133,8 +133,8 @@ class DeveloperControllerTest extends WallabagCoreTestCase /** * @param string $username + * @param array $grantTypes * - * @param array $grantTypes * @return Client */ private function createApiClientForUser($username, $grantTypes = ['password']) @@ -142,7 +142,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); $userManager = $client->getContainer()->get('fos_user.user_manager'); - $user = $userManager->findUserBy(array('username' => $username)); + $user = $userManager->findUserBy(['username' => $username]); $apiClient = new Client($user); $apiClient->setName('My app'); $apiClient->setAllowedGrantTypes($grantTypes); diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index c0391d87..2a333a0d 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -21,19 +21,19 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals($entry->getTitle(), $content['title']); - $this->assertEquals($entry->getUrl(), $content['url']); + $this->assertSame($entry->getTitle(), $content['title']); + $this->assertSame($entry->getUrl(), $content['url']); $this->assertCount(count($entry->getTags()), $content['tags']); - $this->assertEquals($entry->getUserName(), $content['user_name']); - $this->assertEquals($entry->getUserEmail(), $content['user_email']); - $this->assertEquals($entry->getUserId(), $content['user_id']); + $this->assertSame($entry->getUserName(), $content['user_name']); + $this->assertSame($entry->getUserEmail(), $content['user_email']); + $this->assertSame($entry->getUserId(), $content['user_id']); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testExportEntry() @@ -47,39 +47,39 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('GET', '/api/entries/'.$entry->getId().'/export.epub'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('GET', '/api/entries/' . $entry->getId() . '/export.epub'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); // epub format got the content type in the content $this->assertContains('application/epub', $this->client->getResponse()->getContent()); - $this->assertEquals('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type')); // re-auth client for mobi $client = $this->createAuthorizedClient(); - $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $client->request('GET', '/api/entries/' . $entry->getId() . '/export.mobi'); + $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type')); // re-auth client for pdf $client = $this->createAuthorizedClient(); - $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $client->request('GET', '/api/entries/' . $entry->getId() . '/export.pdf'); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertContains('PDF-', $client->getResponse()->getContent()); - $this->assertEquals('application/pdf', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/pdf', $client->getResponse()->headers->get('Content-Type')); // re-auth client for pdf $client = $this->createAuthorizedClient(); - $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $client->request('GET', '/api/entries/' . $entry->getId() . '/export.txt'); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type')); // re-auth client for pdf $client = $this->createAuthorizedClient(); - $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $client->request('GET', '/api/entries/' . $entry->getId() . '/export.csv'); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type')); } @@ -95,26 +95,26 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); + $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json'); - $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); + $this->assertSame(403, $this->client->getResponse()->getStatusCode()); } public function testGetEntries() { $this->client->request('GET', '/api/entries'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->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->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetEntriesWithFullOptions() @@ -131,15 +131,15 @@ class EntryRestControllerTest extends WallabagApiTestCase 'public' => 0, ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThanOrEqual(1, count($content)); $this->assertArrayHasKey('items', $content['_embedded']); $this->assertGreaterThanOrEqual(0, $content['total']); - $this->assertEquals(1, $content['page']); - $this->assertEquals(2, $content['limit']); + $this->assertSame(1, $content['page']); + $this->assertSame(2, $content['limit']); $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertArrayHasKey('_links', $content); @@ -158,7 +158,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('public=0', $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetEntriesPublicOnly() @@ -183,15 +183,15 @@ class EntryRestControllerTest extends WallabagApiTestCase 'public' => 1, ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThanOrEqual(1, count($content)); $this->assertArrayHasKey('items', $content['_embedded']); $this->assertGreaterThanOrEqual(1, $content['total']); - $this->assertEquals(1, $content['page']); - $this->assertEquals(30, $content['limit']); + $this->assertSame(1, $content['page']); + $this->assertSame(30, $content['limit']); $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertArrayHasKey('_links', $content); @@ -204,7 +204,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('public=1', $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetEntriesOnPageTwo() @@ -214,27 +214,27 @@ class EntryRestControllerTest extends WallabagApiTestCase 'perPage' => 2, ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThanOrEqual(0, $content['total']); - $this->assertEquals(2, $content['page']); - $this->assertEquals(2, $content['limit']); + $this->assertSame(2, $content['page']); + $this->assertSame(2, $content['limit']); } public function testGetStarredEntries() { $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->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->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertArrayHasKey('_links', $content); @@ -248,21 +248,21 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('sort=updated', $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetArchiveEntries() { $this->client->request('GET', '/api/entries', ['archive' => 1]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->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->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertArrayHasKey('_links', $content); @@ -275,21 +275,21 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('archive=1', $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetTaggedEntries() { $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->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->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertArrayHasKey('_links', $content); @@ -299,24 +299,24 @@ class EntryRestControllerTest extends WallabagApiTestCase foreach (['self', 'first', 'last'] as $link) { $this->assertArrayHasKey('href', $content['_links'][$link]); - $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); + $this->assertContains('tags=' . urlencode('foo,bar'), $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetDatedEntries() { $this->client->request('GET', '/api/entries', ['since' => 1443274283]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->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->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); $this->assertArrayHasKey('_links', $content); @@ -329,7 +329,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('since=1443274283', $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetDatedSupEntries() @@ -337,15 +337,15 @@ class EntryRestControllerTest extends WallabagApiTestCase $future = new \DateTime(date('Y-m-d H:i:s')); $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThanOrEqual(1, count($content)); $this->assertEmpty($content['_embedded']['items']); - $this->assertEquals(0, $content['total']); - $this->assertEquals(1, $content['page']); - $this->assertEquals(1, $content['pages']); + $this->assertSame(0, $content['total']); + $this->assertSame(1, $content['page']); + $this->assertSame(1, $content['pages']); $this->assertArrayHasKey('_links', $content); $this->assertArrayHasKey('self', $content['_links']); @@ -354,10 +354,10 @@ class EntryRestControllerTest extends WallabagApiTestCase foreach (['self', 'first', 'last'] as $link) { $this->assertArrayHasKey('href', $content['_links'][$link]); - $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); + $this->assertContains('since=' . ($future->getTimestamp() + 1000), $content['_links'][$link]['href']); } - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testDeleteEntry() @@ -371,19 +371,19 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); + $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals($entry->getTitle(), $content['title']); - $this->assertEquals($entry->getUrl(), $content['url']); + $this->assertSame($entry->getTitle(), $content['title']); + $this->assertSame($entry->getUrl(), $content['url']); // We'll try to delete this entry again - $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); + $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); - $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } public function testPostEntry() @@ -399,16 +399,16 @@ class EntryRestControllerTest extends WallabagApiTestCase 'public' => 1, ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); - $this->assertEquals(false, $content['is_archived']); - $this->assertEquals(false, $content['is_starred']); - $this->assertEquals('New title for my article', $content['title']); - $this->assertEquals(1, $content['user_id']); + $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); + $this->assertSame(false, $content['is_archived']); + $this->assertSame(false, $content['is_starred']); + $this->assertSame('New title for my article', $content['title']); + $this->assertSame(1, $content['user_id']); $this->assertCount(2, $content['tags']); $this->assertSame('my content', $content['content']); $this->assertSame('de', $content['language']); @@ -427,14 +427,14 @@ class EntryRestControllerTest extends WallabagApiTestCase 'tags' => 'google, apple', ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); - $this->assertEquals(true, $content['is_archived']); - $this->assertEquals(false, $content['is_starred']); + $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); + $this->assertSame(true, $content['is_archived']); + $this->assertSame(false, $content['is_starred']); $this->assertCount(3, $content['tags']); } @@ -456,10 +456,10 @@ class EntryRestControllerTest extends WallabagApiTestCase 'url' => 'http://www.example.com/', ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.example.com/', $content['url']); + $this->assertSame('http://www.example.com/', $content['url']); } finally { // Remove the created entry to avoid side effects on other tests if (isset($content['id'])) { @@ -479,15 +479,15 @@ class EntryRestControllerTest extends WallabagApiTestCase 'starred' => '1', ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); - $this->assertEquals(true, $content['is_archived']); - $this->assertEquals(true, $content['is_starred']); - $this->assertEquals(1, $content['user_id']); + $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); + $this->assertSame(true, $content['is_archived']); + $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['user_id']); } public function testPostArchivedAndStarredEntryWithoutQuotes() @@ -498,14 +498,14 @@ class EntryRestControllerTest extends WallabagApiTestCase 'starred' => 1, ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); - $this->assertEquals(false, $content['is_archived']); - $this->assertEquals(true, $content['is_starred']); + $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); + $this->assertSame(false, $content['is_archived']); + $this->assertSame(true, $content['is_starred']); } public function testPatchEntry() @@ -522,9 +522,9 @@ class EntryRestControllerTest extends WallabagApiTestCase // hydrate the tags relations $nbTags = count($entry->getTags()); - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 'title' => 'New awesome title', - 'tags' => 'new tag '.uniqid(), + 'tags' => 'new tag ' . uniqid(), 'starred' => '1', 'archive' => '0', 'language' => 'de_AT', @@ -534,20 +534,20 @@ class EntryRestControllerTest extends WallabagApiTestCase 'public' => 0, ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals($entry->getId(), $content['id']); - $this->assertEquals($entry->getUrl(), $content['url']); - $this->assertEquals('New awesome title', $content['title']); + $this->assertSame($entry->getId(), $content['id']); + $this->assertSame($entry->getUrl(), $content['url']); + $this->assertSame('New awesome title', $content['title']); $this->assertGreaterThan($nbTags, count($content['tags'])); - $this->assertEquals(1, $content['user_id']); - $this->assertEquals('de_AT', $content['language']); - $this->assertEquals('http://preview.io/picture.jpg', $content['preview_picture']); + $this->assertSame(1, $content['user_id']); + $this->assertSame('de_AT', $content['language']); + $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); $this->assertContains('sponge', $content['published_by']); $this->assertContains('bob', $content['published_by']); - $this->assertEquals('awesome', $content['content']); + $this->assertSame('awesome', $content['content']); $this->assertFalse($content['is_public'], 'Entry is no more shared'); } @@ -565,23 +565,23 @@ class EntryRestControllerTest extends WallabagApiTestCase // hydrate the tags relations $nbTags = count($entry->getTags()); - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 'title' => 'New awesome title', - 'tags' => 'new tag '.uniqid(), + 'tags' => 'new tag ' . uniqid(), 'starred' => 1, 'archive' => 0, 'authors' => ['bob', 'sponge'], ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals($entry->getId(), $content['id']); - $this->assertEquals($entry->getUrl(), $content['url']); - $this->assertEquals('New awesome title', $content['title']); + $this->assertSame($entry->getId(), $content['id']); + $this->assertSame($entry->getUrl(), $content['url']); + $this->assertSame('New awesome title', $content['title']); $this->assertGreaterThan($nbTags, count($content['tags'])); - $this->assertTrue(empty($content['published_by']), 'Authors were not saved because of an array instead of a string'); + $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); } public function testGetTagsEntry() @@ -602,9 +602,9 @@ class EntryRestControllerTest extends WallabagApiTestCase $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()]; } - $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags'); + $this->client->request('GET', '/api/entries/' . $entry->getId() . '/tags'); - $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent()); + $this->assertSame(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent()); } public function testPostTagsOnEntry() @@ -622,14 +622,14 @@ class EntryRestControllerTest extends WallabagApiTestCase $newTags = 'tag1,tag2,tag3'; - $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]); + $this->client->request('POST', '/api/entries/' . $entry->getId() . '/tags', ['tags' => $newTags]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('tags', $content); - $this->assertEquals($nbTags + 3, count($content['tags'])); + $this->assertSame($nbTags + 3, count($content['tags'])); $entryDB = $this->client->getContainer() ->get('doctrine.orm.entity_manager') @@ -662,14 +662,14 @@ class EntryRestControllerTest extends WallabagApiTestCase $nbTags = count($entry->getTags()); $tag = $entry->getTags()[0]; - $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json'); + $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '/tags/' . $tag->getId() . '.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('tags', $content); - $this->assertEquals($nbTags - 1, count($content['tags'])); + $this->assertSame($nbTags - 1, count($content['tags'])); } public function testSaveIsArchivedAfterPost() @@ -687,11 +687,11 @@ class EntryRestControllerTest extends WallabagApiTestCase 'url' => $entry->getUrl(), ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(true, $content['is_archived']); + $this->assertSame(true, $content['is_archived']); } public function testSaveIsStarredAfterPost() @@ -709,11 +709,11 @@ class EntryRestControllerTest extends WallabagApiTestCase 'url' => $entry->getUrl(), ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(true, $content['is_starred']); + $this->assertSame(true, $content['is_starred']); } public function testSaveIsArchivedAfterPatch() @@ -727,15 +727,15 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ - 'title' => $entry->getTitle().'++', + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'title' => $entry->getTitle() . '++', ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(true, $content['is_archived']); + $this->assertSame(true, $content['is_archived']); } public function testSaveIsStarredAfterPatch() @@ -748,15 +748,15 @@ class EntryRestControllerTest extends WallabagApiTestCase if (!$entry) { $this->markTestSkipped('No content found in db.'); } - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ - 'title' => $entry->getTitle().'++', + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'title' => $entry->getTitle() . '++', ]); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(true, $content['is_starred']); + $this->assertSame(true, $content['is_starred']); } public function dataForEntriesExistWithUrl() @@ -780,7 +780,7 @@ class EntryRestControllerTest extends WallabagApiTestCase { $this->client->request('GET', $url); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -791,9 +791,9 @@ class EntryRestControllerTest extends WallabagApiTestCase { $url1 = 'http://0.0.0.0/entry2'; $url2 = 'http://0.0.0.0/entry10'; - $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2.'&return_id=1'); + $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -807,9 +807,9 @@ class EntryRestControllerTest extends WallabagApiTestCase { $url1 = 'http://0.0.0.0/entry2'; $url2 = 'http://0.0.0.0/entry10'; - $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2); + $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -823,18 +823,18 @@ class EntryRestControllerTest extends WallabagApiTestCase { $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertEquals(false, $content['exists']); + $this->assertSame(false, $content['exists']); } public function testGetEntriesExistsWithNoUrl() { $this->client->request('GET', '/api/entries/exists?url='); - $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); + $this->assertSame(403, $this->client->getResponse()->getStatusCode()); } public function testReloadEntryErrorWhileFetching() @@ -847,8 +847,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); - $this->assertEquals(304, $this->client->getResponse()->getStatusCode()); + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json'); + $this->assertSame(304, $this->client->getResponse()->getStatusCode()); } public function testReloadEntry() @@ -863,14 +863,14 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->setUp(); - $this->client->request('PATCH', '/api/entries/'.$json['id'].'/reload.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertNotEmpty($content['title']); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testPostEntriesTagsListAction() @@ -890,14 +890,14 @@ class EntryRestControllerTest extends WallabagApiTestCase ], ]; - $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode($list)); + $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode($list)); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertInternalType('int', $content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry4', $content[0]['url']); + $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']); $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') @@ -926,8 +926,8 @@ class EntryRestControllerTest extends WallabagApiTestCase ], ]; - $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list)); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId()); $this->assertCount(0, $entry->getTags()); @@ -940,17 +940,17 @@ class EntryRestControllerTest extends WallabagApiTestCase 'http://0.0.0.0/entry2', ]; - $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); + $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list)); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertInternalType('int', $content[0]['entry']); - $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); + $this->assertSame('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); $this->assertInternalType('int', $content[1]['entry']); - $this->assertEquals('http://0.0.0.0/entry2', $content[1]['url']); + $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']); } public function testDeleteEntriesListAction() @@ -965,17 +965,17 @@ class EntryRestControllerTest extends WallabagApiTestCase 'http://0.0.0.0/test-entry-not-exist', ]; - $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); + $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode($list)); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertTrue($content[0]['entry']); - $this->assertEquals('http://0.0.0.0/test-entry1', $content[0]['url']); + $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']); $this->assertFalse($content[1]['entry']); - $this->assertEquals('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); + $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); } public function testLimitBulkAction() @@ -994,9 +994,9 @@ class EntryRestControllerTest extends WallabagApiTestCase 'http://0.0.0.0/entry1', ]; - $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); + $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list)); - $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); } } diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 7f69bd67..430e548d 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -11,7 +11,7 @@ class TagRestControllerTest extends WallabagApiTestCase { $this->client->request('GET', '/api/tags.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -33,15 +33,15 @@ class TagRestControllerTest extends WallabagApiTestCase $em->flush(); $em->clear(); - $this->client->request('DELETE', '/api/tags/'.$tag->getId().'.json'); + $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('label', $content); - $this->assertEquals($tag->getLabel(), $content['label']); - $this->assertEquals($tag->getSlug(), $content['slug']); + $this->assertSame($tag->getLabel(), $content['label']); + $this->assertSame($tag->getSlug(), $content['slug']); $entries = $em->getRepository('WallabagCoreBundle:Entry') ->findAllByTagId($this->user->getId(), $tag->getId()); @@ -50,7 +50,7 @@ class TagRestControllerTest extends WallabagApiTestCase $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); - $this->assertNull($tag, $tagLabel.' was removed because it begun an orphan tag'); + $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); } public function dataForDeletingTagByLabel() @@ -84,18 +84,18 @@ class TagRestControllerTest extends WallabagApiTestCase $em->flush(); if ($useQueryString) { - $this->client->request('DELETE', '/api/tag/label.json?tag='.$tag->getLabel()); + $this->client->request('DELETE', '/api/tag/label.json?tag=' . $tag->getLabel()); } else { $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); } - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('label', $content); - $this->assertEquals($tag->getLabel(), $content['label']); - $this->assertEquals($tag->getSlug(), $content['slug']); + $this->assertSame($tag->getLabel(), $content['label']); + $this->assertSame($tag->getSlug(), $content['slug']); $entries = $this->client->getContainer() ->get('doctrine.orm.entity_manager') @@ -109,7 +109,7 @@ class TagRestControllerTest extends WallabagApiTestCase { $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']); - $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } /** @@ -140,24 +140,24 @@ class TagRestControllerTest extends WallabagApiTestCase $em->flush(); if ($useQueryString) { - $this->client->request('DELETE', '/api/tags/label.json?tags='.$tag->getLabel().','.$tag2->getLabel()); + $this->client->request('DELETE', '/api/tags/label.json?tags=' . $tag->getLabel() . ',' . $tag2->getLabel()); } else { - $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel() . ',' . $tag2->getLabel()]); } - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(2, $content); $this->assertArrayHasKey('label', $content[0]); - $this->assertEquals($tag->getLabel(), $content[0]['label']); - $this->assertEquals($tag->getSlug(), $content[0]['slug']); + $this->assertSame($tag->getLabel(), $content[0]['label']); + $this->assertSame($tag->getSlug(), $content[0]['slug']); $this->assertArrayHasKey('label', $content[1]); - $this->assertEquals($tag2->getLabel(), $content[1]['label']); - $this->assertEquals($tag2->getSlug(), $content[1]['slug']); + $this->assertSame($tag2->getLabel(), $content[1]['label']); + $this->assertSame($tag2->getSlug(), $content[1]['slug']); $entries = $this->client->getContainer() ->get('doctrine.orm.entity_manager') @@ -178,6 +178,6 @@ class TagRestControllerTest extends WallabagApiTestCase { $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']); - $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } } diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index 4e65f130..51fac2bd 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -9,7 +9,7 @@ class UserRestControllerTest extends WallabagApiTestCase public function testGetUser() { $this->client->request('GET', '/api/user.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -20,27 +20,27 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('created_at', $content); $this->assertArrayHasKey('updated_at', $content); - $this->assertEquals('bigboss@wallabag.org', $content['email']); - $this->assertEquals('Big boss', $content['name']); - $this->assertEquals('admin', $content['username']); + $this->assertSame('bigboss@wallabag.org', $content['email']); + $this->assertSame('Big boss', $content['name']); + $this->assertSame('admin', $content['username']); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testGetUserWithoutAuthentication() { $client = static::createClient(); $client->request('GET', '/api/user.json'); - $this->assertEquals(401, $client->getResponse()->getStatusCode()); + $this->assertSame(401, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('error', $content); $this->assertArrayHasKey('error_description', $content); - $this->assertEquals('access_denied', $content['error']); + $this->assertSame('access_denied', $content['error']); - $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); } public function testCreateNewUser() @@ -52,7 +52,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'email' => 'wallabag@google.com', ]); - $this->assertEquals(201, $this->client->getResponse()->getStatusCode()); + $this->assertSame(201, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -63,15 +63,15 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('updated_at', $content); $this->assertArrayHasKey('default_client', $content); - $this->assertEquals('wallabag@google.com', $content['email']); - $this->assertEquals('google', $content['username']); + $this->assertSame('wallabag@google.com', $content['email']); + $this->assertSame('google', $content['username']); $this->assertArrayHasKey('client_secret', $content['default_client']); $this->assertArrayHasKey('client_id', $content['default_client']); - $this->assertEquals('Default client', $content['default_client']['name']); + $this->assertSame('Default client', $content['default_client']['name']); - $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); $this->client->getContainer()->get('craue_config')->set('api_user_registration', 0); } @@ -88,7 +88,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'client_name' => 'My client name !!', ]); - $this->assertEquals(201, $client->getResponse()->getStatusCode()); + $this->assertSame(201, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); @@ -99,15 +99,15 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('updated_at', $content); $this->assertArrayHasKey('default_client', $content); - $this->assertEquals('wallabag@google.com', $content['email']); - $this->assertEquals('google', $content['username']); + $this->assertSame('wallabag@google.com', $content['email']); + $this->assertSame('google', $content['username']); $this->assertArrayHasKey('client_secret', $content['default_client']); $this->assertArrayHasKey('client_id', $content['default_client']); - $this->assertEquals('My client name !!', $content['default_client']['name']); + $this->assertSame('My client name !!', $content['default_client']['name']); - $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); $client->getContainer()->get('craue_config')->set('api_user_registration', 0); } @@ -122,7 +122,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'email' => 'bigboss@wallabag.org', ]); - $this->assertEquals(400, $client->getResponse()->getStatusCode()); + $this->assertSame(400, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); @@ -133,10 +133,10 @@ class UserRestControllerTest extends WallabagApiTestCase // $this->assertEquals('fos_user.username.already_used', $content['error']['username'][0]); // $this->assertEquals('fos_user.email.already_used', $content['error']['email'][0]); // This shouldn't be translated ... - $this->assertEquals('This value is already used.', $content['error']['username'][0]); - $this->assertEquals('This value is already used.', $content['error']['email'][0]); + $this->assertSame('This value is already used.', $content['error']['username'][0]); + $this->assertSame('This value is already used.', $content['error']['email'][0]); - $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); $client->getContainer()->get('craue_config')->set('api_user_registration', 0); } @@ -151,16 +151,16 @@ class UserRestControllerTest extends WallabagApiTestCase 'email' => 'facebook@wallabag.org', ]); - $this->assertEquals(400, $client->getResponse()->getStatusCode()); + $this->assertSame(400, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('error', $content); $this->assertArrayHasKey('password', $content['error']); - $this->assertEquals('validator.password_too_short', $content['error']['password'][0]); + $this->assertSame('validator.password_too_short', $content['error']['password'][0]); - $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); $client->getContainer()->get('craue_config')->set('api_user_registration', 0); } @@ -174,12 +174,12 @@ class UserRestControllerTest extends WallabagApiTestCase 'email' => 'facebook@wallabag.org', ]); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('error', $content); - $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type')); + $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); } } diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index df638e8f..ac4d6cdc 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -12,10 +12,10 @@ class WallabagRestControllerTest extends WallabagApiTestCase $client = static::createClient(); $client->request('GET', '/api/version'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); - $this->assertEquals($client->getContainer()->getParameter('wallabag_core.version'), $content); + $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); } } -- cgit v1.2.3 From 38520658addc217f127b0627ea28dcf8d6e6178c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 3 Jul 2017 07:30:54 +0200 Subject: Fix tests --- .../Controller/EntryRestControllerTest.php | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 2a333a0d..ae4af4cd 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -405,8 +405,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); - $this->assertSame(false, $content['is_archived']); - $this->assertSame(false, $content['is_starred']); + $this->assertSame(0, $content['is_archived']); + $this->assertSame(0, $content['is_starred']); $this->assertSame('New title for my article', $content['title']); $this->assertSame(1, $content['user_id']); $this->assertCount(2, $content['tags']); @@ -433,8 +433,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); - $this->assertSame(true, $content['is_archived']); - $this->assertSame(false, $content['is_starred']); + $this->assertSame(1, $content['is_archived']); + $this->assertSame(0, $content['is_starred']); $this->assertCount(3, $content['tags']); } @@ -485,8 +485,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); - $this->assertSame(true, $content['is_archived']); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['is_archived']); + $this->assertSame(1, $content['is_starred']); $this->assertSame(1, $content['user_id']); } @@ -504,8 +504,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThan(0, $content['id']); $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); - $this->assertSame(false, $content['is_archived']); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(0, $content['is_archived']); + $this->assertSame(1, $content['is_starred']); } public function testPatchEntry() @@ -691,7 +691,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_archived']); + $this->assertSame(1, $content['is_archived']); } public function testSaveIsStarredAfterPost() @@ -713,7 +713,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['is_starred']); } public function testSaveIsArchivedAfterPatch() @@ -735,7 +735,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_archived']); + $this->assertSame(1, $content['is_archived']); } public function testSaveIsStarredAfterPatch() @@ -756,7 +756,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['is_starred']); + $this->assertSame(1, $content['is_starred']); } public function dataForEntriesExistWithUrl() -- cgit v1.2.3 From a05b61159e147776f63baee731b5026796e5f7ae Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 30 Jun 2017 16:54:26 +0200 Subject: Fix PATCH method The PATCH method for the entry should only update what user sent to us and not the whole entry as it was before. Also, sending tags when patching an entry will now remove all current tags & assocatied new ones. --- .../Controller/EntryRestControllerTest.php | 68 ++++++++++++++++++---- 1 file changed, 58 insertions(+), 10 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index ae4af4cd..0647bb23 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -519,10 +519,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - // hydrate the tags relations - $nbTags = count($entry->getTags()); - - $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ 'title' => 'New awesome title', 'tags' => 'new tag ' . uniqid(), 'starred' => '1', @@ -532,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'authors' => 'bob,sponge', 'content' => 'awesome', 'public' => 0, + 'published_at' => 1488833381, ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -541,7 +539,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($entry->getId(), $content['id']); $this->assertSame($entry->getUrl(), $content['url']); $this->assertSame('New awesome title', $content['title']); - $this->assertGreaterThan($nbTags, count($content['tags'])); + $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag'); $this->assertSame(1, $content['user_id']); $this->assertSame('de_AT', $content['language']); $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); @@ -549,6 +547,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertContains('bob', $content['published_by']); $this->assertSame('awesome', $content['content']); $this->assertFalse($content['is_public'], 'Entry is no more shared'); + $this->assertContains('2017-03-06', $content['published_at']); } public function testPatchEntryWithoutQuotes() @@ -562,8 +561,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - // hydrate the tags relations - $nbTags = count($entry->getTags()); + $previousContent = $entry->getContent(); + $previousLanguage = $entry->getLanguage(); $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 'title' => 'New awesome title', @@ -579,9 +578,11 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($entry->getId(), $content['id']); $this->assertSame($entry->getUrl(), $content['url']); - $this->assertSame('New awesome title', $content['title']); + $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag'); $this->assertGreaterThan($nbTags, count($content['tags'])); $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); + $this->assertEquals($previousContent, $content['content'], 'Ensure content has not moved'); + $this->assertEquals($previousLanguage, $content['language'], 'Ensure language has not moved'); } public function testGetTagsEntry() @@ -727,8 +728,10 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ - 'title' => $entry->getTitle() . '++', + $previousTitle = $entry->getTitle(); + + $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ + 'title' => $entry->getTitle().'++', ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -736,6 +739,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertSame(1, $content['is_archived']); + $this->assertEquals($previousTitle.'++', $content['title']); } public function testSaveIsStarredAfterPatch() @@ -907,6 +911,17 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertCount(4, $tags); } + public function testPostEntriesTagsListActionNoList() + { + $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode([])); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertEmpty($content); + } + public function testDeleteEntriesTagsListAction() { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); @@ -933,6 +948,17 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertCount(0, $entry->getTags()); } + public function testDeleteEntriesTagsListActionNoList() + { + $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode([])); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertEmpty($content); + } + public function testPostEntriesListAction() { $list = [ @@ -953,6 +979,17 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']); } + public function testPostEntriesListActionWithNoUrls() + { + $this->client->request('POST', '/api/entries/lists?urls='.json_encode([])); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertEmpty($content); + } + public function testDeleteEntriesListAction() { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); @@ -978,6 +1015,17 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); } + public function testDeleteEntriesListActionWithNoUrls() + { + $this->client->request('DELETE', '/api/entries/list?urls='.json_encode([])); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertEmpty($content); + } + public function testLimitBulkAction() { $list = [ -- cgit v1.2.3 From c18a2476b601bc6b9893462d9be680c2e13c89e8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 3 Jul 2017 13:56:39 +0200 Subject: CS --- .../Controller/EntryRestControllerTest.php | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 0647bb23..c76be13d 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -519,7 +519,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->markTestSkipped('No content found in db.'); } - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 'title' => 'New awesome title', 'tags' => 'new tag ' . uniqid(), 'starred' => '1', @@ -579,10 +579,9 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($entry->getId(), $content['id']); $this->assertSame($entry->getUrl(), $content['url']); $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag'); - $this->assertGreaterThan($nbTags, count($content['tags'])); $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); - $this->assertEquals($previousContent, $content['content'], 'Ensure content has not moved'); - $this->assertEquals($previousLanguage, $content['language'], 'Ensure language has not moved'); + $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved'); + $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); } public function testGetTagsEntry() @@ -730,8 +729,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $previousTitle = $entry->getTitle(); - $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ - 'title' => $entry->getTitle().'++', + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'title' => $entry->getTitle() . '++', ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -739,7 +738,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertSame(1, $content['is_archived']); - $this->assertEquals($previousTitle.'++', $content['title']); + $this->assertSame($previousTitle . '++', $content['title']); } public function testSaveIsStarredAfterPatch() @@ -913,9 +912,9 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testPostEntriesTagsListActionNoList() { - $this->client->request('POST', '/api/entries/tags/lists?list='.json_encode([])); + $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode([])); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -950,9 +949,9 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testDeleteEntriesTagsListActionNoList() { - $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode([])); + $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode([])); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -981,9 +980,9 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testPostEntriesListActionWithNoUrls() { - $this->client->request('POST', '/api/entries/lists?urls='.json_encode([])); + $this->client->request('POST', '/api/entries/lists?urls=' . json_encode([])); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -1017,9 +1016,9 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testDeleteEntriesListActionWithNoUrls() { - $this->client->request('DELETE', '/api/entries/list?urls='.json_encode([])); + $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode([])); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); -- cgit v1.2.3 From 2e5b2fa808ca2793705069e56a3cc7e6631f9d9d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 8 Jul 2017 19:28:12 +0200 Subject: Revert client_credentials grant types --- .../Controller/DeveloperControllerTest.php | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 2caeccf5..e9e5ee3b 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -34,7 +34,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertContains('My app', $alert[0]); } - public function testCreateTokenFromPasswords() + public function testCreateToken() { $client = $this->getClient(); $apiClient = $this->createApiClientForUser('admin'); @@ -56,26 +56,6 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('refresh_token', $data); } - public function testCreateTokenFromClientCredentialsOnly() - { - $client = $this->getClient(); - $apiClient = $this->createApiClientForUser('admin', ['client_credentials']); - - $client->request('POST', '/oauth/v2/token', [ - 'grant_type' => 'client_credentials', - 'client_id' => $apiClient->getPublicId(), - 'client_secret' => $apiClient->getSecret(), - ]); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $data = json_decode($client->getResponse()->getContent(), true); - $this->assertArrayHasKey('access_token', $data); - $this->assertArrayHasKey('expires_in', $data); - $this->assertArrayHasKey('token_type', $data); - // Client Credentials created-clients have no refresh tokens - } - public function testListingClient() { $this->logInAs('admin'); -- cgit v1.2.3 From ff9f89fd2318cfb29a18d941077b5afc859bf0fe Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 24 Jul 2017 16:39:29 +0200 Subject: Add a test for updatePublishedAt To avoid error when a content is re-submitted and it previously add a published date. Also, fix the `testPostSameEntry` --- .../Controller/EntryRestControllerTest.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index c76be13d..2dc08be2 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -421,6 +421,16 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testPostSameEntry() { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = new Entry($em->getReference(User::class, 1)); + $entry->setUrl('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'); + $entry->setArchived(true); + $entry->addTag((new Tag())->setLabel('google')); + $entry->addTag((new Tag())->setLabel('apple')); + $em->persist($entry); + $em->flush(); + $em->clear(); + $this->client->request('POST', '/api/entries.json', [ 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', 'archive' => '1', @@ -1046,4 +1056,28 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(400, $this->client->getResponse()->getStatusCode()); $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); } + + public function testRePostEntryAndReUsePublishedAt() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = new Entry($em->getReference(User::class, 1)); + $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); + $entry->setContent('hihi'); + $entry->setUrl('http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); + $entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200')); + $em->persist($entry); + $em->flush(); + $em->clear(); + + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html', + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content['id']); + $this->assertSame('http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html', $content['url']); + } } -- cgit v1.2.3 From a991c46eedec0efb24d0a9974b1c7fcabf8cfa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20D?= Date: Wed, 23 Aug 2017 23:06:40 +0200 Subject: Set a starred_at field when an entry is starred. This date is used to sort starred entries. Can not use Entry::timestamps method otherwise starred_at will be updated each time entry is updated. Add an updateStar method into Entry class A migration script has been added in order to set starred_at field. --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 2dc08be2..f4c8a630 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -407,6 +407,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); $this->assertSame(0, $content['is_archived']); $this->assertSame(0, $content['is_starred']); + $this->assertNull($content['starred_at']); $this->assertSame('New title for my article', $content['title']); $this->assertSame(1, $content['user_id']); $this->assertCount(2, $content['tags']); @@ -483,6 +484,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testPostArchivedAndStarredEntry() { + $now = new \DateTime(); $this->client->request('POST', '/api/entries.json', [ 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', 'archive' => '1', @@ -497,6 +499,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); $this->assertSame(1, $content['is_archived']); $this->assertSame(1, $content['is_starred']); + $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); $this->assertSame(1, $content['user_id']); } @@ -753,6 +756,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testSaveIsStarredAfterPatch() { + $now = new \DateTime(); $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') @@ -770,6 +774,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertSame(1, $content['is_starred']); + $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); } public function dataForEntriesExistWithUrl() -- cgit v1.2.3 From 7c04b7396a296e31bb11beadc19550396ee728a8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 3 Aug 2017 12:46:20 +0200 Subject: Multiple tag search was broken from API First, the setParameter() were done on the same parameter which in fact just duplicated the condition in the SQL query (like `where t.label = 'test' and t.label = 'test'`. Changed the parameter doesn't help because the query was then wrong. Changing the way to match associated tags for an entry and it worked. --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index f4c8a630..fcec3f3b 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -292,6 +292,9 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertContains('foo', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "foo" tag'); + $this->assertContains('bar', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "bar" tag'); + $this->assertArrayHasKey('_links', $content); $this->assertArrayHasKey('self', $content['_links']); $this->assertArrayHasKey('first', $content['_links']); -- cgit v1.2.3 From d03b72f405095e4173dd07e6f38fe0cff23d36c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Viande?= Date: Tue, 26 Sep 2017 11:29:09 +0200 Subject: Fix #3361 add test --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index fcec3f3b..4ffe478d 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -308,6 +308,13 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } + public function testGetTaggedEntriesWithBadParams() + { + $this->client->request('GET', '/api/entries', ['tags' => ['foo','bar']]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + } + public function testGetDatedEntries() { $this->client->request('GET', '/api/entries', ['since' => 1443274283]); -- cgit v1.2.3 From bb86dc648660cf3d94c6800f97214426b52f2d8e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 11 Oct 2017 10:51:24 +0200 Subject: CS --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/ApiBundle/Controller') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 4ffe478d..95c64501 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -310,7 +310,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testGetTaggedEntriesWithBadParams() { - $this->client->request('GET', '/api/entries', ['tags' => ['foo','bar']]); + $this->client->request('GET', '/api/entries', ['tags' => ['foo', 'bar']]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); } -- cgit v1.2.3