From: Nicolas LÅ“uillet Date: Fri, 5 May 2017 11:56:34 +0000 (+0200) Subject: Merge pull request #3053 from wallabag/api-bulk-add X-Git-Tag: 2.3.0~31^2~107 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=69803049688179e1b03ef424dec91f1b9a4f9e91;hp=-c;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3053 from wallabag/api-bulk-add Added API endpoint to handle a list of URL --- 69803049688179e1b03ef424dec91f1b9a4f9e91 diff --combined tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index e6ffd664,34a2f894..f0173cef --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@@ -337,7 -337,7 +337,7 @@@ class EntryRestControllerTest extends W $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 +356,7 @@@ $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() @@@ -766,20 -766,69 +766,69 @@@ ], ]; - $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 = [ + '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/entry2', + ]; + + $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->assertInternalType('int', $content[0]['entry']); - $this->assertEquals('http://0.0.0.0/entry4', $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']); - $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://0.0.0.0/entry2', $content[1]['url']); + } - $tags = $entry->getTags(); - $this->assertCount(2, $tags); + public function testDeleteEntriesListAction() + { + $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', + ]; + + $this->client->request('DELETE', '/api/entries/list?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://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']); + } + + 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)); + + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + $this->assertContains('API limit reached', $this->client->getResponse()->getContent()); } }