From 7975395d10bb381de8cd15b5ee15198318af6d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Viande?= Date: Wed, 11 Apr 2018 11:42:52 +0200 Subject: Entry: add archived_at property and updateArchived method --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 58b617f3..6b26376d 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -438,6 +438,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(0, $content['is_archived']); $this->assertSame(0, $content['is_starred']); $this->assertNull($content['starred_at']); + $this->assertNull($content['archived_at']); $this->assertSame('New title for my article', $content['title']); $this->assertSame(1, $content['user_id']); $this->assertCount(2, $content['tags']); @@ -533,6 +534,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['is_archived']); $this->assertSame(1, $content['is_starred']); $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); + $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); $this->assertSame(1, $content['user_id']); } -- cgit v1.2.3 From 115de64e5bb9d7f9151ecf15e15a0d988563528e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 4 Oct 2018 14:07:20 +0200 Subject: Jump to Symfony 3.4 Thanks to the BC compatibility, almost nothing have to be changed. All changes are related to new bundle version of: - SensioFrameworkExtraBundle - DoctrineFixturesBundle --- tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | 2 +- tests/Wallabag/ApiBundle/WallabagApiTestCase.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index f58d1c12..090155d7 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -121,7 +121,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase { $client = $this->getClient(); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $userManager = $client->getContainer()->get('fos_user.user_manager'); + $userManager = $client->getContainer()->get('fos_user.user_manager.test'); $user = $userManager->findUserBy(['username' => $username]); $apiClient = new Client($user); $apiClient->setName('My app'); diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index 8a188e1c..0c52aea0 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php @@ -31,9 +31,9 @@ abstract class WallabagApiTestCase extends WebTestCase $container = $client->getContainer(); /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ - $userManager = $container->get('fos_user.user_manager'); + $userManager = $container->get('fos_user.user_manager.test'); /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ - $loginManager = $container->get('fos_user.security.login_manager'); + $loginManager = $container->get('fos_user.security.login_manager.test'); $firewallName = $container->getParameter('fos_user.firewall_name'); $this->user = $userManager->findUserBy(['username' => 'admin']); -- cgit v1.2.3 From 8f2038e5b15c2d7342ed18381531e5eb95e86d46 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 26 Nov 2018 22:22:49 +0100 Subject: Fix tests --- .../Controller/EntryRestControllerTest.php | 84 +++++++++++----------- tests/Wallabag/ApiBundle/WallabagApiTestCase.php | 19 +++++ 2 files changed, 59 insertions(+), 44 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 6b26376d..176da3cd 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -15,7 +15,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isArchived' => false]); + ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -41,7 +41,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']); + ->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -60,7 +60,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isArchived' => false]); + ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -108,7 +108,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 2, 'isArchived' => false]); + ->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -185,7 +185,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -394,7 +394,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1, ['id' => 'asc']); + ->findOneByUser($this->getUserId(), ['id' => 'asc']); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -440,7 +440,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertNull($content['starred_at']); $this->assertNull($content['archived_at']); $this->assertSame('New title for my article', $content['title']); - $this->assertSame(1, $content['user_id']); + $this->assertSame($this->getUserId(), $content['user_id']); $this->assertCount(2, $content['tags']); $this->assertNull($content['origin_url']); $this->assertSame('my content', $content['content']); @@ -455,7 +455,7 @@ 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 = new Entry($em->getReference(User::class, $this->getUserId())); $entry->setUrl('https://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')); @@ -535,7 +535,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['is_starred']); $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); - $this->assertSame(1, $content['user_id']); + $this->assertSame($this->getUserId(), $content['user_id']); } public function testPostArchivedAndStarredEntryWithoutQuotes() @@ -584,7 +584,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -611,7 +611,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $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->assertSame(1, $content['user_id']); + $this->assertSame($this->getUserId(), $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']); @@ -626,7 +626,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -660,7 +660,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -691,7 +691,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -723,7 +723,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -768,7 +768,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1); + ->findOneByUser($this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -833,7 +833,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isArchived' => true]); + ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -855,7 +855,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isStarred' => true]); + ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -877,7 +877,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isArchived' => true]); + ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -903,7 +903,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isStarred' => true]); + ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -920,32 +920,27 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); } - public function dataForEntriesExistWithUrl() + public function testGetEntriesExistsWithReturnId() { - 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, - ], - ]; + $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1'); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value + $this->assertGreaterThan(1, $content['exists']); } - /** - * @dataProvider dataForEntriesExistWithUrl - */ - public function testGetEntriesExists($url, $expectedValue) + public function testGetEntriesExistsWithoutReturnId() { - $this->client->request('GET', $url); + $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame($expectedValue, $content['exists']); + $this->assertSame(true, $content['exists']); } public function testGetEntriesExistsWithManyUrls() @@ -960,7 +955,8 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey($url1, $content); $this->assertArrayHasKey($url2, $content); - $this->assertSame(2, $content[$url1]); + // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value + $this->assertGreaterThan(1, $content[$url1]); $this->assertNull($content[$url2]); } @@ -1002,7 +998,7 @@ class EntryRestControllerTest extends WallabagApiTestCase { $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); if (!$entry) { $this->markTestSkipped('No content found in db.'); @@ -1038,7 +1034,7 @@ class EntryRestControllerTest extends WallabagApiTestCase { $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); $tags = $entry->getTags(); @@ -1062,7 +1058,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); + ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); $tags = $entry->getTags(); $this->assertCount(4, $tags); @@ -1082,7 +1078,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testDeleteEntriesTagsListAction() { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); - $entry = new Entry($em->getReference(User::class, 1)); + $entry = new Entry($em->getReference(User::class, $this->getUserId())); $entry->setUrl('http://0.0.0.0/test-entry'); $entry->addTag((new Tag())->setLabel('foo-tag')); $entry->addTag((new Tag())->setLabel('bar-tag')); @@ -1150,7 +1146,7 @@ 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->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1')); $em->flush(); $em->clear(); @@ -1208,7 +1204,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testRePostEntryAndReUsePublishedAt() { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); - $entry = new Entry($em->getReference(User::class, 1)); + $entry = new Entry($em->getReference(User::class, $this->getUserId())); $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); $entry->setContent('hihi'); $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index 0c52aea0..a0f2f889 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php @@ -48,4 +48,23 @@ abstract class WallabagApiTestCase extends WebTestCase return $client; } + + /** + * Return the ID for the user admin. + * Used because on heavy testing we don't want to re-create the database on each run. + * Which means "admin" user won't have id 1 all the time. + * + * @param string $username + * + * @return int + */ + public function getUserId($username = 'admin') + { + return $this->client + ->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagUserBundle:User') + ->findOneByUserName($username) + ->getId(); + } } -- cgit v1.2.3 From b13b2ef052f3c21f17ab2a4f3f410049e3c79c83 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 26 Nov 2018 22:46:44 +0100 Subject: CS --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 2 +- tests/Wallabag/ApiBundle/WallabagApiTestCase.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 176da3cd..3696f8f9 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -940,7 +940,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(true, $content['exists']); + $this->assertTrue($content['exists']); } public function testGetEntriesExistsWithManyUrls() diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index a0f2f889..fd2e113e 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php @@ -54,11 +54,11 @@ abstract class WallabagApiTestCase extends WebTestCase * Used because on heavy testing we don't want to re-create the database on each run. * Which means "admin" user won't have id 1 all the time. * - * @param string $username + * @param string $username * * @return int */ - public function getUserId($username = 'admin') + protected function getUserId($username = 'admin') { return $this->client ->getContainer() -- cgit v1.2.3 From 0ee9848231d0a7a02fdc8e915d830ebaf6cc09c0 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 29 Dec 2018 19:43:07 +0100 Subject: TagRestController: add tests to ensure that other user's tags are unreachable Signed-off-by: Kevin Decherf --- .../ApiBundle/Controller/TagRestControllerTest.php | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 430e548d..8f1e6f02 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -7,6 +7,8 @@ use Wallabag\CoreBundle\Entity\Tag; class TagRestControllerTest extends WallabagApiTestCase { + private $otherUserTagLabel = 'bob'; + public function testGetUserTags() { $this->client->request('GET', '/api/tags.json'); @@ -19,6 +21,12 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('id', $content[0]); $this->assertArrayHasKey('label', $content[0]); + $tagLabels = array_map(function ($i) { + return $i['label']; + }, $content); + + $this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak'); + return end($content); } @@ -53,6 +61,16 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); } + public function testDeleteOtherUserTag() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($this->otherUserTagLabel); + + $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json'); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } + public function dataForDeletingTagByLabel() { return [ @@ -112,6 +130,13 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } + public function testDeleteTagByLabelOtherUser() + { + $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $this->otherUserTagLabel]); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } + /** * @dataProvider dataForDeletingTagByLabel */ @@ -180,4 +205,11 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } + + public function testDeleteTagsByLabelOtherUser() + { + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $this->otherUserTagLabel]); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } } -- cgit v1.2.3 From 6c40d7fc85b98e335adf765d1c6b4465647da62c Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 29 Dec 2018 20:43:34 +0100 Subject: TagRestController: fix test for tag without entries As the deletion now requires that at least one entry for the user must be linked to the given tag, we fix the test testDeleteUserTag by linking it to an entry. Signed-off-by: Kevin Decherf --- .../ApiBundle/Controller/TagRestControllerTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 8f1e6f02..9daa94cd 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -32,12 +32,22 @@ class TagRestControllerTest extends WallabagApiTestCase public function testDeleteUserTag() { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneWithTags($this->user->getId()); + + $entry = $entry[0]; + $tagLabel = 'tagtest'; $tag = new Tag(); $tag->setLabel($tagLabel); - - $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); $em->persist($tag); + + $entry->addTag($tag); + + $em->persist($entry); $em->flush(); $em->clear(); -- cgit v1.2.3 From 3a2d4cf9fda87760c86320a7f8a5041d1d4256c6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 9 Jan 2019 23:29:30 +0100 Subject: Cast client id to avoid PG error If someone send a malformated client_id when trying to authenticate using the API we got a 500 if wallabag use postgres because the request send a string instead of an integer. --- .../ApiBundle/Controller/DeveloperControllerTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index f58d1c12..e1a0ac7e 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -56,6 +56,20 @@ class DeveloperControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('refresh_token', $data); } + public function testCreateTokenWithBadClientId() + { + $client = $this->getClient(); + $client->request('POST', '/oauth/v2/token', [ + 'grant_type' => 'password', + 'client_id' => '$WALLABAG_CLIENT_ID', + 'client_secret' => 'secret', + 'username' => 'admin', + 'password' => 'mypassword', + ]); + + $this->assertSame(400, $client->getResponse()->getStatusCode()); + } + public function testListingClient() { $this->logInAs('admin'); -- cgit v1.2.3 From 78e3fafa3fab86638295fe1ee2a05a559bf56ab1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 14 Jan 2019 17:01:21 +0100 Subject: Avoid error when a bad `order` parameter is given Only allowed parameter are asc & desc --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 58b617f3..2a1d2e15 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -242,6 +242,15 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(2, $content['limit']); } + public function testGetStarredEntriesWithBadSort() + { + $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated', 'order' => 'unknown']); + + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + public function testGetStarredEntries() { $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); -- cgit v1.2.3 From 3bd65991adc253715c6b74ab0ee19ff2cf3e6c69 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 15 Jan 2019 10:17:11 +0100 Subject: Add a new endpoint to retrieve information from the wallabag instance Useful for api client which required some information. We might add more inside them in the future. The endpoint /api/version should be avoided now as it contains not so much information rather the version. --- .../ApiBundle/Controller/WallabagRestControllerTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index ac4d6cdc..8b49c0ae 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -18,4 +18,21 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); } + + public function testGetInfo() + { + // create a new client instead of using $this->client to be sure client isn't authenticated + $client = static::createClient(); + $client->request('GET', '/api/info'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('appname', $content); + $this->assertArrayHasKey('version', $content); + $this->assertArrayHasKey('allowed_registration', $content); + + $this->assertSame('wallabag', $content['appname']); + } } -- cgit v1.2.3 From 1e0d8ad7b728f6fb2cd886526b0fb84ef803e84f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 17 Jan 2019 14:28:05 +0100 Subject: Enable PHPStan - Fix error for level 0 & 1 (level 7 has 699 errors...) - Add `updated_at` to site_credential (so the `timestamps()` method applies correctly) --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 1a41338c..0b0c0276 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -794,7 +794,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('tags', $content); - $this->assertSame($nbTags + 3, \count($content['tags'])); + $this->assertCount($nbTags + 3, $content['tags']); $entryDB = $this->client->getContainer() ->get('doctrine.orm.entity_manager') @@ -834,7 +834,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('tags', $content); - $this->assertSame($nbTags - 1, \count($content['tags'])); + $this->assertCount($nbTags - 1, $content['tags']); } public function testSaveIsArchivedAfterPost() -- cgit v1.2.3 From b32057980e33e7ddd93480017496a589006b8260 Mon Sep 17 00:00:00 2001 From: Craig Roberts Date: Mon, 9 Apr 2018 17:24:45 +0800 Subject: Fixes [wallabag/wallabag#2611] Add a basic Search REST endpoint - Adds a new `search` key to `src/Wallabag/ApiBundle/Resources/config/routing_rest.yml` - Reuses the `getBuilderForSearchByUser` method from the EntryRepository - Supports, `term`, `page`, and `perPage` query parameters - Some very basic tests --- .../Controller/SearchRestControllerTest.php | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php new file mode 100644 index 00000000..5900ae53 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php @@ -0,0 +1,73 @@ +client->request('GET', '/api/search', [ + 'page' => 1, + 'perPage' => 2, + 'term' => 'entry' // 6 results + ]); + + $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->assertSame(1, $content['page']); + $this->assertSame(2, $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('term=entry', $content['_links'][$link]['href']); + } + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testGetSearchWithNoLimit() + { + $this->client->request('GET', '/api/search', [ + 'term' => 'entry' + ]); + + $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->assertSame(1, $content['page']); + $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('term=entry', $content['_links'][$link]['href']); + } + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } +} -- cgit v1.2.3 From 9133bd02d11c37c98b2c7c979e363cc7bff8f914 Mon Sep 17 00:00:00 2001 From: Craig Roberts Date: Tue, 10 Apr 2018 19:50:26 +0800 Subject: [wallabag/wallabag#2611] Fix PHPCS lint errors --- tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php index 5900ae53..f096f21b 100644 --- a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php @@ -4,9 +4,6 @@ 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 SearchRestControllerTest extends WallabagApiTestCase { @@ -15,7 +12,7 @@ class SearchRestControllerTest extends WallabagApiTestCase $this->client->request('GET', '/api/search', [ 'page' => 1, 'perPage' => 2, - 'term' => 'entry' // 6 results + 'term' => 'entry', // 6 results ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -45,7 +42,7 @@ class SearchRestControllerTest extends WallabagApiTestCase public function testGetSearchWithNoLimit() { $this->client->request('GET', '/api/search', [ - 'term' => 'entry' + 'term' => 'entry', ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); -- cgit v1.2.3 From 019e1acc4962229a538421b6f2b0643d03c1d72c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Oct 2018 20:11:45 +0200 Subject: Factorize sendResponse between Api controllers And run newer cs fixer --- tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php index f096f21b..fd524639 100644 --- a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php @@ -3,7 +3,6 @@ namespace Tests\Wallabag\ApiBundle\Controller; use Tests\Wallabag\ApiBundle\WallabagApiTestCase; -use Wallabag\CoreBundle\Entity\Entry; class SearchRestControllerTest extends WallabagApiTestCase { @@ -19,7 +18,7 @@ class SearchRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertGreaterThanOrEqual(1, \count($content)); $this->assertArrayHasKey('items', $content['_embedded']); $this->assertGreaterThanOrEqual(0, $content['total']); $this->assertSame(1, $content['page']); @@ -49,7 +48,7 @@ class SearchRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertGreaterThanOrEqual(1, \count($content)); $this->assertArrayHasKey('items', $content['_embedded']); $this->assertGreaterThanOrEqual(0, $content['total']); $this->assertSame(1, $content['page']); -- cgit v1.2.3 From 4e0ed3368d2bdc2fa0d330e58902e792a896be06 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 17 Feb 2019 15:25:21 +0100 Subject: tests: create entry for testDeleteEntry, fix missing id When using the entity manager to retrieve an already stored entry, the id disapears from $entry after the first delete call. This leads to testing a nonexistent endpoint (api/entries/.json) during the second delete call. This change now creates an entry specifically for the test. Signed-off-by: Kevin Decherf --- .../Controller/EntryRestControllerTest.php | 36 +++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 2a1d2e15..ddeca4c0 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -400,14 +400,36 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testDeleteEntry() { - $entry = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser(1, ['id' => 'asc']); + $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-delete-entry'); + $entry->setTitle('Test delete entry'); + $em->persist($entry); + $em->flush(); - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } + $em->clear(); + + $e = [ + 'title' => $entry->getTitle(), + 'url' => $entry->getUrl(), + 'id' => $entry->getId(), + ]; + + $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame($e['title'], $content['title']); + $this->assertSame($e['url'], $content['url']); + $this->assertSame($e['id'], $content['id']); + + // We'll try to delete this entry again + $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); -- cgit v1.2.3 From 508302042f96ce771a36f0114acb0b3a89c18880 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 17 Feb 2019 15:30:42 +0100 Subject: EntryRestController: add support of expect parameter to delete action The expect parameter enables an application to request the whole entry or only the id when requesting its deletion. `expects` defaults to `entry` to prevent any API breakage. Fixes #3711 Signed-off-by: Kevin Decherf --- .../Controller/EntryRestControllerTest.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index ddeca4c0..1489a472 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -431,18 +431,29 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } - $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); + public function testDeleteEntryExpectId() + { + $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-delete-entry-id'); + $em->persist($entry); + $em->flush(); + + $em->clear(); + + $id = $entry->getId(); + + $this->client->request('DELETE', '/api/entries/' . $id . '.json?expect=id'); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame($entry->getTitle(), $content['title']); - $this->assertSame($entry->getUrl(), $content['url']); - $this->assertSame($entry->getId(), $content['id']); + $this->assertSame($id, $content['id']); + $this->assertArrayNotHasKey('url', $content); // We'll try to delete this entry again - $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); + $this->client->request('DELETE', '/api/entries/' . $id . '.json'); $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } -- cgit v1.2.3 From 12a97c352275d81e9252ca4179de51180403eb6f Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 17 Feb 2019 18:19:51 +0100 Subject: tests: fix broken session clients for rest entry deletion tests Signed-off-by: Kevin Decherf --- .../ApiBundle/Controller/EntryRestControllerTest.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 1489a472..46b5f460 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -426,9 +426,10 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($e['id'], $content['id']); // We'll try to delete this entry again - $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); + $client = $this->createAuthorizedClient(); + $client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); - $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testDeleteEntryExpectId() @@ -453,9 +454,17 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertArrayNotHasKey('url', $content); // We'll try to delete this entry again - $this->client->request('DELETE', '/api/entries/' . $id . '.json'); + $client = $this->createAuthorizedClient(); + $client->request('DELETE', '/api/entries/' . $id . '.json'); + + $this->assertSame(404, $client->getResponse()->getStatusCode()); + } + + public function testDeleteEntryExpectBadRequest() + { + $this->client->request('DELETE', '/api/entries/1.json?expect=badrequest'); - $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); } public function testPostEntry() -- cgit v1.2.3 From bfe02a0b481055bb4e799200c8daa9a0ad987c71 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 28 May 2017 14:53:04 +0200 Subject: Hash the urls to check if they exist Signed-off-by: Thomas Citharel --- .../Controller/EntryRestControllerTest.php | 55 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 2151f587..8d96d7b8 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -987,6 +987,8 @@ class EntryRestControllerTest extends WallabagApiTestCase { $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); + $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2')); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -994,10 +996,22 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertTrue($content['exists']); } + public function testGetEntriesExistsWithHash() + { + $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2')); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame(2, $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->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -1027,9 +1041,46 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertFalse($content[$url2]); } + public function testGetEntriesExistsWithManyUrlsHashed() + { + $url1 = 'http://0.0.0.0/entry2'; + $url2 = 'http://0.0.0.0/entry10'; + $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2) . '&return_id=1'); + + $this->assertSame(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->assertNull($content[$url2]); + + $this->assertArrayHasKey(hash('md5', $url1), $content); + $this->assertArrayHasKey(hash('md5', $url2), $content); + $this->assertEquals(2, $content[hash('md5', $url1)]); + $this->assertEquals(false, $content[hash('md5', $url2)]); + } + + public function testGetEntriesExistsWithManyUrlsHashedReturnBool() + { + $url1 = 'http://0.0.0.0/entry2'; + $url2 = 'http://0.0.0.0/entry10'; + $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2)); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey($url1, $content); + $this->assertArrayHasKey($url2, $content); + $this->assertTrue($content[$url1]); + $this->assertFalse($content[$url2]); + } + public function testGetEntriesExistsWhichDoesNotExists() { - $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); + $this->client->request('GET', '/api/entries/exists?hashedurl='.hash('md5','http://google.com/entry2')); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -1040,7 +1091,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testGetEntriesExistsWithNoUrl() { - $this->client->request('GET', '/api/entries/exists?url='); + $this->client->request('GET', '/api/entries/exists?hashedurl='); $this->assertSame(403, $this->client->getResponse()->getStatusCode()); } -- cgit v1.2.3 From 9c2b2aae70b06411336e6eb6ac43b3ebd30dc38c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 11:50:33 +0200 Subject: Keep url in exists endpoint - Add migration - Use md5 instead of sha512 (we don't need security here, just a hash) - Update tests --- .../Controller/EntryRestControllerTest.php | 75 +++++++++++----------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 8d96d7b8..fc4dc9d9 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -971,40 +971,42 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); } - public function testGetEntriesExistsWithReturnId() + public function dataForEntriesExistWithUrl() { - $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1'); + $url = hash('md5', 'http://0.0.0.0/entry2'); - $this->assertSame(200, $this->client->getResponse()->getStatusCode()); - - $content = json_decode($this->client->getResponse()->getContent(), true); - - // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value - $this->assertGreaterThan(1, $content['exists']); - } - - public function testGetEntriesExistsWithoutReturnId() - { - $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); - - $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2')); - - $this->assertSame(200, $this->client->getResponse()->getStatusCode()); - - $content = json_decode($this->client->getResponse()->getContent(), true); - - $this->assertTrue($content['exists']); + 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, + ], + 'hashed_url_with_id' => [ + 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1', + 'expectedValue' => 2, + ], + 'hashed_url_without_id' => [ + 'url' => '/api/entries/exists?hashed_url=' . $url . '', + 'expectedValue' => true, + ], + ]; } - public function testGetEntriesExistsWithHash() + /** + * @dataProvider dataForEntriesExistWithUrl + */ + public function testGetEntriesExists($url, $expectedValue) { - $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2')); + $this->client->request('GET', $url); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertSame(2, $content['exists']); + $this->assertSame($expectedValue, $content['exists']); } public function testGetEntriesExistsWithManyUrls() @@ -1045,42 +1047,37 @@ 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?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2) . '&return_id=1'); + $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('md5', $url1) . '&hashed_urls[]=' . hash('md5', $url2) . '&return_id=1'); $this->assertSame(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->assertNull($content[$url2]); - $this->assertArrayHasKey(hash('md5', $url1), $content); $this->assertArrayHasKey(hash('md5', $url2), $content); - $this->assertEquals(2, $content[hash('md5', $url1)]); - $this->assertEquals(false, $content[hash('md5', $url2)]); + $this->assertSame(2, $content[hash('md5', $url1)]); + $this->assertNull($content[hash('md5', $url2)]); } public function testGetEntriesExistsWithManyUrlsHashedReturnBool() { $url1 = 'http://0.0.0.0/entry2'; $url2 = 'http://0.0.0.0/entry10'; - $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2)); + $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('md5', $url1) . '&hashed_urls[]=' . hash('md5', $url2)); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertArrayHasKey($url1, $content); - $this->assertArrayHasKey($url2, $content); - $this->assertTrue($content[$url1]); - $this->assertFalse($content[$url2]); + $this->assertArrayHasKey(hash('md5', $url1), $content); + $this->assertArrayHasKey(hash('md5', $url2), $content); + $this->assertTrue($content[hash('md5', $url1)]); + $this->assertFalse($content[hash('md5', $url2)]); } public function testGetEntriesExistsWhichDoesNotExists() { - $this->client->request('GET', '/api/entries/exists?hashedurl='.hash('md5','http://google.com/entry2')); + $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('md5', 'http://google.com/entry2')); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -1091,7 +1088,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testGetEntriesExistsWithNoUrl() { - $this->client->request('GET', '/api/entries/exists?hashedurl='); + $this->client->request('GET', '/api/entries/exists?hashed_url='); $this->assertSame(403, $this->client->getResponse()->getStatusCode()); } -- cgit v1.2.3 From 8a6456629814039cfc623cdb279bcba06dacff50 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 13:51:57 +0200 Subject: Use a better index for hashed_url It'll most often be used in addition to the `user_id`. Also, automatically generate the hash when saving the url. Switch from `md5` to `sha1`. --- .../Controller/EntryRestControllerTest.php | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index fc4dc9d9..34de8ec8 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -973,7 +973,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function dataForEntriesExistWithUrl() { - $url = hash('md5', 'http://0.0.0.0/entry2'); + $url = hash('sha1', 'http://0.0.0.0/entry2'); return [ 'with_id' => [ @@ -1047,37 +1047,37 @@ 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?hashed_urls[]=' . hash('md5', $url1) . '&hashed_urls[]=' . hash('md5', $url2) . '&return_id=1'); + $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1'); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertArrayHasKey(hash('md5', $url1), $content); - $this->assertArrayHasKey(hash('md5', $url2), $content); - $this->assertSame(2, $content[hash('md5', $url1)]); - $this->assertNull($content[hash('md5', $url2)]); + $this->assertArrayHasKey(hash('sha1', $url1), $content); + $this->assertArrayHasKey(hash('sha1', $url2), $content); + $this->assertSame(2, $content[hash('sha1', $url1)]); + $this->assertNull($content[hash('sha1', $url2)]); } public function testGetEntriesExistsWithManyUrlsHashedReturnBool() { $url1 = 'http://0.0.0.0/entry2'; $url2 = 'http://0.0.0.0/entry10'; - $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('md5', $url1) . '&hashed_urls[]=' . hash('md5', $url2)); + $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2)); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertArrayHasKey(hash('md5', $url1), $content); - $this->assertArrayHasKey(hash('md5', $url2), $content); - $this->assertTrue($content[hash('md5', $url1)]); - $this->assertFalse($content[hash('md5', $url2)]); + $this->assertArrayHasKey(hash('sha1', $url1), $content); + $this->assertArrayHasKey(hash('sha1', $url2), $content); + $this->assertTrue($content[hash('sha1', $url1)]); + $this->assertFalse($content[hash('sha1', $url2)]); } public function testGetEntriesExistsWhichDoesNotExists() { - $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('md5', 'http://google.com/entry2')); + $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2')); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); -- cgit v1.2.3 From c579ce2306297674c56376a2ab5c8ba66a272253 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Apr 2019 14:34:20 +0200 Subject: Some cleanup Also, do not run the hashed_url migration into a Doctrine migration --- .../ApiBundle/Controller/EntryRestControllerTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 34de8ec8..8cc12ed3 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -1076,6 +1076,17 @@ class EntryRestControllerTest extends WallabagApiTestCase } public function testGetEntriesExistsWhichDoesNotExists() + { + $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertFalse($content['exists']); + } + + public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl() { $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2')); @@ -1087,6 +1098,13 @@ class EntryRestControllerTest extends WallabagApiTestCase } public function testGetEntriesExistsWithNoUrl() + { + $this->client->request('GET', '/api/entries/exists?url='); + + $this->assertSame(403, $this->client->getResponse()->getStatusCode()); + } + + public function testGetEntriesExistsWithNoHashedUrl() { $this->client->request('GET', '/api/entries/exists?hashed_url='); -- cgit v1.2.3 From 2c290747cb0d235392f6e5d22205a706c6474168 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 12 May 2019 00:00:00 +0200 Subject: api/entries: add parameter detail to exclude or include content in response detail=metadata will nullify the content field of entries in order to make smaller responses. detail=full keeps the former behavior, it sends the content of entries. It's the default, for backward compatibility. Fixes #2817 Signed-off-by: Kevin Decherf --- .../Controller/EntryRestControllerTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 8cc12ed3..8b7898ee 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -133,6 +133,27 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertNotNull($content['_embedded']['items'][0]['content']); + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testGetEntriesDetailMetadata() + { + $this->client->request('GET', '/api/entries?detail=metadata'); + + $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->assertSame(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertNull($content['_embedded']['items'][0]['content']); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } -- cgit v1.2.3 From 34be2d5de44ade2a78be73decc0b90a2c1bca720 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 26 Jun 2019 22:31:47 +0200 Subject: Add ability to import/export tagging rules - Add missing translations - Add some tests - Add `/api/taggingrule/export` API endpoint - Add baggy theme - Add error message when importing tagging rules failed - Also fix all translations (I think we are good now) --- .../Controller/TaggingRuleRestControllerTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php new file mode 100644 index 00000000..b6477256 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php @@ -0,0 +1,15 @@ +client->request('GET', '/api/taggingrule/export'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } +} -- cgit v1.2.3 From 2f62f3abfe8c8187a8bc90294ed7c3be9bc71525 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 Jul 2019 14:02:58 +0200 Subject: Fix tests --- tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/ApiBundle') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 5586c70d..e3d69290 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -30,7 +30,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); $this->assertGreaterThan(\count($nbClients), \count($newNbClients)); - $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); + $this->assertGreaterThan(1, $alert = $crawler->filter('.settings table strong')->extract(['_text'])); $this->assertContains('My app', $alert[0]); } -- cgit v1.2.3