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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php') 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() -- 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/EntryRestControllerTest.php') 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 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php | 296 ++++++++++----------- 1 file changed, 148 insertions(+), 148 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php') 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()); } } -- 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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/EntryRestControllerTest.php') 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