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 ++ tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'tests') 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']); } diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index e07c57dd..d709f4eb 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -849,7 +849,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $entryArchived->setContent('Youhou'); $entryArchived->setTitle('Youhou'); $entryArchived->addTag($tagArchived); - $entryArchived->setArchived(true); + $entryArchived->updateArchived(true); $em->persist($entryArchived); $annotationArchived = new Annotation($user); diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index bf0068b4..0ac119d8 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -621,7 +621,7 @@ class EntryControllerTest extends WallabagCoreTestCase $content->setMimetype('text/html'); $content->setTitle('test title entry'); $content->setContent('This is my content /o/'); - $content->setArchived(true); + $content->updateArchived(true); $content->setLanguage('fr'); $em->persist($content); @@ -774,7 +774,7 @@ class EntryControllerTest extends WallabagCoreTestCase $entry = new Entry($this->getLoggedInUser()); $entry->setUrl($this->url); - $entry->setArchived(false); + $entry->updateArchived(false); $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); @@ -1245,7 +1245,7 @@ class EntryControllerTest extends WallabagCoreTestCase $entry = new Entry($this->getLoggedInUser()); $entry->setUrl('http://0.0.0.0/foo/baz/qux'); $entry->setTitle('Le manège'); - $entry->setArchived(true); + $entry->updateArchived(true); $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); @@ -1275,7 +1275,7 @@ class EntryControllerTest extends WallabagCoreTestCase $entry = new Entry($this->getLoggedInUser()); $entry->setUrl('http://domain/qux'); $entry->setTitle('Le manège'); - $entry->setArchived(true); + $entry->updateArchived(true); $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); -- cgit v1.2.3 From 03b2058dbe792f539611fe77ae6e730f5b60ff86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Wed, 24 Jan 2018 17:53:00 +0100 Subject: Add tests about the tag renaming process. --- .../CoreBundle/Controller/TagControllerTest.php | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 768f4c07..be17dcf5 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -176,4 +176,49 @@ class TagControllerTest extends WallabagCoreTestCase $em->remove($tag); $em->flush(); } + + public function testRenameTagUsingTheFormInsideTagList() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $tag = new Tag(); + $tag->setLabel($this->tagName); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://0.0.0.0/foo'); + $entry->addTag($tag); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + + // We make a first request to set an history and test redirection after tag deletion + $crawler = $client->request('GET', '/tag/list'); + $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form(); + + $data = [ + 'tag[label]' => 'specific label', + ]; + + $client->submit($form, $data); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $freshEntry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->find($entry->getId()); + + $tags = $freshEntry->getTags()->toArray(); + foreach ($tags as $key => $item) { + $tags[$key] = $item->getLabel(); + } + + $this->assertFalse(array_search($tag->getLabel(), $tags, true), 'Previous tag is not attach to entry anymore.'); + + $newTag = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel('specific label'); + $this->assertInstanceOf(Tag::class, $newTag, 'Tag "specific label" exists.'); + $this->assertTrue($newTag->hasEntry($freshEntry), 'Tag "specific label" is assigned to the entry.'); + } } -- 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 --- .../Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php | 4 ++-- .../ApiBundle/Controller/DeveloperControllerTest.php | 2 +- tests/Wallabag/ApiBundle/WallabagApiTestCase.php | 4 ++-- tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php | 6 +++--- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 12 +++++++----- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php index 105e8add..9c7aba6b 100644 --- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php +++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php @@ -43,9 +43,9 @@ abstract class WallabagAnnotationTestCase 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']); 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']); diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index b13f6519..c4bd6dac 100644 --- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php @@ -26,7 +26,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase { parent::setUp(); - $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); + $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test'); $user = $userRepository->findOneByUserName('admin'); $this->adminEntry = new Entry($user); @@ -60,7 +60,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase $reloadedEntries = $this->getClient() ->getContainer() - ->get('wallabag_core.entry_repository') + ->get('wallabag_core.entry_repository.test') ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); foreach ($reloadedEntries as $reloadedEntry) { @@ -84,7 +84,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase 'interactive' => false, ]); - $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); + $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test'); $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); $this->assertNotEmpty($reloadedAdminEntry->getContent()); diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 0ac119d8..6effe43e 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -985,8 +985,13 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/share/' . $content->getId()); $this->assertSame(302, $client->getResponse()->getStatusCode()); - // follow link with uid - $crawler = $client->followRedirect(); + $shareUrl = $client->getResponse()->getTargetUrl(); + + // use a new client to have a fresh empty session (instead of a logged one from the previous client) + $client->restart(); + + $client->request('GET', $shareUrl); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); @@ -1002,9 +1007,6 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/share/' . $content->getUid()); $this->assertSame(404, $client->getResponse()->getStatusCode()); - $client->request('GET', '/view/' . $content->getId()); - $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); - // removing the share $client->request('GET', '/share/delete/' . $content->getId()); $this->assertSame(302, $client->getResponse()->getStatusCode()); diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 6e1163c5..816d22f4 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -84,8 +84,8 @@ abstract class WallabagCoreTestCase extends WebTestCase $container = $this->client->getContainer(); $session = $container->get('session'); - $userManager = $container->get('fos_user.user_manager'); - $loginManager = $container->get('fos_user.security.login_manager'); + $userManager = $container->get('fos_user.user_manager.test'); + $loginManager = $container->get('fos_user.security.login_manager.test'); $firewallName = $container->getParameter('fos_user.firewall_name'); $user = $userManager->findUserBy(['username' => $username]); -- cgit v1.2.3 From 4d4147b228ac90f329fd2d40dd4fb60cb980328a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 13 Oct 2018 09:24:39 +0200 Subject: Ensure language is valid - Do not override locale if user has choosen a locale from the login screen. - Add some tests about locale url --- .../CoreBundle/Controller/ConfigControllerTest.php | 35 ++++++++++++++++++++++ .../Event/Listener/UserLocaleListenerTest.php | 23 ++++++++++++++ .../EventListener/CreateConfigListenerTest.php | 6 +++- 3 files changed, 63 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index d709f4eb..cf9f1e97 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -965,4 +965,39 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->request('GET', '/config/view-mode'); } + + public function testChangeLocaleWithoutReferer() + { + $client = $this->getClient(); + + $client->request('GET', '/locale/de'); + $client->followRedirect(); + + $this->assertSame('de', $client->getRequest()->getLocale()); + $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); + } + + public function testChangeLocaleWithReferer() + { + $client = $this->getClient(); + + $client->request('GET', '/login'); + $client->request('GET', '/locale/de'); + $client->followRedirect(); + + $this->assertSame('de', $client->getRequest()->getLocale()); + $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); + } + + public function testChangeLocaleToBadLocale() + { + $client = $this->getClient(); + + $client->request('GET', '/login'); + $client->request('GET', '/locale/yuyuyuyu'); + $client->followRedirect(); + + $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); + $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); + } } diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index 93edfde8..ff0a9602 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php @@ -56,4 +56,27 @@ class UserLocaleListenerTest extends TestCase $this->assertNull($session->get('_locale')); } + + public function testWithLanguageFromSession() + { + $session = new Session(new MockArraySessionStorage()); + $listener = new UserLocaleListener($session); + $session->set('_locale', 'de'); + + $user = new User(); + $user->setEnabled(true); + + $config = new Config($user); + $config->setLanguage('fr'); + + $user->setConfig($config); + + $userToken = new UsernamePasswordToken($user, '', 'test'); + $request = Request::create('/'); + $event = new InteractiveLoginEvent($request, $userToken); + + $listener->onInteractiveLogin($event); + + $this->assertSame('de', $session->get('_locale')); + } } diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index 2b540fdf..c13bfbea 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Wallabag\CoreBundle\Entity\Config; use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\EventListener\CreateConfigListener; @@ -22,6 +24,7 @@ class CreateConfigListenerTest extends TestCase protected function setUp() { + $session = new Session(new MockArraySessionStorage()); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() ->getMock(); @@ -34,7 +37,8 @@ class CreateConfigListenerTest extends TestCase 'fr', 1, 1, - 1 + 1, + $session ); $this->dispatcher = new EventDispatcher(); -- 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/AnnotationControllerTest.php | 3 +- .../Controller/EntryRestControllerTest.php | 84 +++++++++++----------- tests/Wallabag/ApiBundle/WallabagApiTestCase.php | 19 +++++ .../ImportBundle/Command/ImportCommandTest.php | 4 +- 4 files changed, 63 insertions(+), 47 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 96474468..537283f2 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -100,8 +100,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase $this->assertSame('my quote', $content['quote']); /** @var Annotation $annotation */ - $annotation = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') + $annotation = $em ->getRepository('WallabagAnnotationBundle:Annotation') ->findLastAnnotationByPageId($entry->getId(), 1); 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(); + } } diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index f95320a4..8e1c528d 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -84,6 +84,8 @@ class ImportCommandTest extends WallabagCoreTestCase public function testRunImportCommandWithUserId() { + $this->logInAs('admin'); + $application = new Application($this->getClient()->getKernel()); $application->add(new ImportCommand()); @@ -92,7 +94,7 @@ class ImportCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->execute([ 'command' => $command->getName(), - 'username' => 1, + 'username' => $this->getLoggedInUserId(), 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', '--useUserId' => true, '--importer' => 'v2', -- 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') 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 9a8a1bdfdbc87047bffb457370e04ef58a24495c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 27 Nov 2018 11:38:28 +0100 Subject: Use our own fork for CraueConfigBundle Mostly to fix utf8mb4 issue --- tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index bd351b18..08685408 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -62,6 +62,7 @@ class InstallCommandTest extends WallabagCoreTestCase $databasePath = getenv('TEST_DATABASE_PATH'); // Remove variable environnement putenv('TEST_DATABASE_PATH'); + if ($databasePath && file_exists($databasePath)) { unlink($databasePath); } else { -- cgit v1.2.3 From 877787e5fe6a6545105616968939949b4db81347 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 28 Nov 2018 20:26:18 +0100 Subject: Fix utf8mb4 on vendor tables When creating the schema for test these tables use default length for string: 255. Which fail when using utf8mb4. > Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes Also move the `setKeepStaticConnections` in before and after class to avoid: > SAVEPOINT DOCTRINE2_SAVEPOINT_2 does not exist See https://github.com/dmaicher/doctrine-test-bundle#troubleshooting --- .../Wallabag/CoreBundle/Command/InstallCommandTest.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 08685408..d8928451 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -18,6 +18,18 @@ use Wallabag\CoreBundle\Command\InstallCommand; class InstallCommandTest extends WallabagCoreTestCase { + public static function setUpBeforeClass() + { + // disable doctrine-test-bundle + StaticDriver::setKeepStaticConnections(false); + } + + public static function tearDownAfterClass() + { + // enable doctrine-test-bundle + StaticDriver::setKeepStaticConnections(true); + } + public function setUp() { parent::setUp(); @@ -51,9 +63,6 @@ class InstallCommandTest extends WallabagCoreTestCase parent::setUp(); } - // disable doctrine-test-bundle - StaticDriver::setKeepStaticConnections(false); - $this->resetDatabase($this->getClient()); } @@ -72,8 +81,6 @@ class InstallCommandTest extends WallabagCoreTestCase $this->resetDatabase($client); } - // enable doctrine-test-bundle - StaticDriver::setKeepStaticConnections(true); parent::tearDown(); } -- 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') 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) --- .../Controller/AnnotationControllerTest.php | 2 +- .../ApiBundle/Controller/EntryRestControllerTest.php | 4 ++-- .../CoreBundle/Controller/ConfigControllerTest.php | 2 +- .../CoreBundle/Controller/EntryControllerTest.php | 11 +++++------ .../CoreBundle/Controller/ExportControllerTest.php | 2 +- .../CoreBundle/Controller/RssControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 3 +++ .../ParamConverter/UsernameRssTokenConverterTest.php | 2 +- .../ImportBundle/Consumer/AMQPEntryConsumerTest.php | 2 +- .../ImportBundle/Consumer/RedisEntryConsumerTest.php | 2 +- .../ImportBundle/Controller/ChromeControllerTest.php | 2 +- .../ImportBundle/Controller/FirefoxControllerTest.php | 2 +- .../Controller/InstapaperControllerTest.php | 4 ++-- .../Controller/PinboardControllerTest.php | 2 +- .../Controller/ReadabilityControllerTest.php | 2 +- .../Controller/WallabagV1ControllerTest.php | 2 +- .../Controller/WallabagV2ControllerTest.php | 4 ++-- .../UserBundle/Controller/ManageControllerTest.php | 2 +- .../Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php | 16 ---------------- .../UserBundle/Mailer/CountableMemorySpool.php | 19 +++++++++++++++++++ 20 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php (limited to 'tests') diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 537283f2..2c46e0a1 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -1,6 +1,6 @@ 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() diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index cf9f1e97..c9dbbaa3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -1,6 +1,6 @@ followRedirect(); - $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); + $title = $crawler->filter('div[id=article] h1')->extract(['_text']); + $this->assertGreaterThan(1, $title); $this->assertContains('My updated title hehe :)', $title[0]); - $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); + + $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']); + $this->assertCount(1, $stats); $this->assertNotContains('example.io', trim($stats[0])); } @@ -1327,10 +1330,6 @@ class EntryControllerTest extends WallabagCoreTestCase 'http://www.hao123.com/shequ?__noscript__-=1', 'zh_CN', ], - 'ru' => [ - 'https://www.kp.ru/daily/26879.7/3921982/', - 'ru', - ], 'pt_BR' => [ 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', 'pt_BR', diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 0c3d4c83..d7ce7c45 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -180,7 +180,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $csv); // +1 for title line - $this->assertSame(\count($contentInDB) + 1, \count($csv)); + $this->assertCount(\count($contentInDB) + 1, $csv); $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); $this->assertContains($contentInDB[0]['title'], $csv[1]); $this->assertContains($contentInDB[0]['url'], $csv[1]); diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 2af6e14f..afa90621 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -11,7 +11,7 @@ class RssControllerTest extends WallabagCoreTestCase $doc = new \DOMDocument(); $doc->loadXML($xml); - $xpath = new \DOMXpath($doc); + $xpath = new \DOMXPath($doc); if (null === $nb) { $this->assertGreaterThan(0, $xpath->query('//item')->length); diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 04e1a59c..29e12cbe 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -17,6 +17,9 @@ class RedirectTest extends TestCase /** @var Redirect */ private $redirect; + /** @var UsernamePasswordToken */ + private $token; + public function setUp() { $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index b044a700..800af5c9 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php @@ -1,6 +1,6 @@ assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok'); $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok'); - $this->assertSame(1, \count($content->getTags())); + $this->assertCount(1, $content->getTags()); $createdAt = $content->getCreatedAt(); $this->assertSame('2011', $createdAt->format('Y')); diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index dc5ed6d0..3e64f2e5 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -122,7 +122,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok'); $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok'); $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok'); - $this->assertSame(3, \count($content->getTags())); + $this->assertCount(3, $content->getTags()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php index 7390fa88..05347767 100644 --- a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php @@ -124,7 +124,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok'); $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok'); $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag'); - $this->assertSame(1, \count($content->getTags())); + $this->assertCount(1, $content->getTags()); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $content = $client->getContainer() @@ -138,7 +138,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase $this->assertContains('foot', $content->getTags()); $this->assertContains('test_tag', $content->getTags()); - $this->assertSame(2, \count($content->getTags())); + $this->assertCount(2, $content->getTags()); } public function testImportInstapaperWithFileAndMarkAllAsRead() diff --git a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php index 80819f45..15646d55 100644 --- a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php @@ -127,7 +127,7 @@ class PinboardControllerTest extends WallabagCoreTestCase $this->assertContains('foot', $tags, 'It includes the "foot" tag'); $this->assertContains('varnish', $tags, 'It includes the "varnish" tag'); $this->assertContains('php', $tags, 'It includes the "php" tag'); - $this->assertSame(3, \count($tags)); + $this->assertCount(3, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d')); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 5619659a..4f2f4053 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -125,7 +125,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); - $this->assertSame(1, \count($tags)); + $this->assertCount(1, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index c67941a7..1f57939d 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -127,7 +127,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); $this->assertContains('framabag', $tags, 'It includes the "framabag" tag'); - $this->assertSame(2, \count($tags)); + $this->assertCount(2, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); } diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 822656ba..b606e26a 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -128,7 +128,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); - $this->assertSame(1, \count($tags)); + $this->assertCount(1, $tags); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -147,7 +147,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertContains('foot', $tags, 'It includes the "foot" tag'); $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag'); $this->assertContains('blog', $tags, 'It includes the "blog" tag'); - $this->assertSame(3, \count($tags)); + $this->assertCount(3, $tags); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index adc2cf09..f44e6fbf 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -1,6 +1,6 @@ messages); - } - - public function getMessages() - { - return $this->messages; - } -} - class AuthCodeMailerTest extends TestCase { protected $mailer; diff --git a/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php new file mode 100644 index 00000000..53f240a1 --- /dev/null +++ b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php @@ -0,0 +1,19 @@ +messages); + } + + public function getMessages() + { + return $this->messages; + } +} -- cgit v1.2.3 From 0447a75b06142afe59a179bb59ee94f1978aa7a9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 12 Oct 2018 21:41:05 +0200 Subject: Use only one method to randomize Instead of one per type, one for all is ok. --- .../CoreBundle/Controller/EntryControllerTest.php | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 005296ff..28291b5a 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1495,4 +1495,30 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); } + + public function testRandom() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->request('GET', '/unread/random'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random'); + + $client->request('GET', '/starred/random'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random'); + + $client->request('GET', '/archive/random'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random'); + + $client->request('GET', '/untagged/random'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random'); + + $client->request('GET', '/all/random'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random'); + } } -- 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') 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') 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') 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 a6b242a1fd6f8900d80354361449f1bf62506ef9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Dec 2018 12:43:05 +0100 Subject: Enable OTP 2FA - Update SchebTwoFactorBundle to version 3 - Enable Google 2fa on the bundle - Disallow ability to use both email and google as 2fa - Update Ocramius Proxy Manager to handle typed function & attributes (from PHP 7) - use `$this->addFlash` shortcut instead of `$this->get('session')->getFlashBag()->add` - update admin to be able to create/reset the 2fa --- .../CoreBundle/Command/ShowUserCommandTest.php | 3 +- .../CoreBundle/Controller/ConfigControllerTest.php | 113 +++++++++++++++++++++ .../Controller/SecurityControllerTest.php | 28 +++-- .../UserBundle/Mailer/AuthCodeMailerTest.php | 2 +- 4 files changed, 136 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 9b34f2a0..ed383a2c 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -59,7 +59,8 @@ class ShowUserCommandTest extends WallabagCoreTestCase $this->assertContains('Username: admin', $tester->getDisplay()); $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); $this->assertContains('Display name: Big boss', $tester->getDisplay()); - $this->assertContains('2FA activated: no', $tester->getDisplay()); + $this->assertContains('2FA (email) activated', $tester->getDisplay()); + $this->assertContains('2FA (OTP) activated', $tester->getDisplay()); } public function testShowUser() diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index c9dbbaa3..9ca52c64 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -297,6 +297,119 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.config.notice.user_updated', $alert[0]); } + public function testUserEnable2faEmail() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=update_user_save]')->form(); + + $data = [ + 'update_user[emailTwoFactor]' => '1', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.config.notice.user_updated', $alert[0]); + + // restore user + $em = $this->getEntityManager(); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertTrue($user->isEmailTwoFactor()); + + $user->setEmailTwoFactor(false); + $em->persist($user); + $em->flush(); + } + + public function testUserEnable2faGoogle() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=update_user_save]')->form(); + + $data = [ + 'update_user[googleTwoFactor]' => '1', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.config.notice.user_updated', $alert[0]); + + // restore user + $em = $this->getEntityManager(); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertTrue($user->isGoogleAuthenticatorEnabled()); + + $user->setGoogleAuthenticatorSecret(null); + $em->persist($user); + $em->flush(); + } + + public function testUserEnable2faBoth() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[id=update_user_save]')->form(); + + $data = [ + 'update_user[googleTwoFactor]' => '1', + 'update_user[emailTwoFactor]' => '1', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.config.notice.user_updated', $alert[0]); + + // restore user + $em = $this->getEntityManager(); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertTrue($user->isGoogleAuthenticatorEnabled()); + $this->assertFalse($user->isEmailTwoFactor()); + + $user->setGoogleAuthenticatorSecret(null); + $em->persist($user); + $em->flush(); + } + public function testRssUpdateResetToken() { $this->logInAs('admin'); diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index 395208a2..b03c7550 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -26,7 +26,7 @@ class SecurityControllerTest extends WallabagCoreTestCase $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); } - public function testLoginWith2Factor() + public function testLoginWith2FactorEmail() { $client = $this->getClient(); @@ -42,7 +42,7 @@ class SecurityControllerTest extends WallabagCoreTestCase $user = $em ->getRepository('WallabagUserBundle:User') ->findOneByUsername('admin'); - $user->setTwoFactorAuthentication(true); + $user->setEmailTwoFactor(true); $em->persist($user); $em->flush(); @@ -54,12 +54,12 @@ class SecurityControllerTest extends WallabagCoreTestCase $user = $em ->getRepository('WallabagUserBundle:User') ->findOneByUsername('admin'); - $user->setTwoFactorAuthentication(false); + $user->setEmailTwoFactor(false); $em->persist($user); $em->flush(); } - public function testTrustedComputer() + public function testLoginWith2FactorGoogle() { $client = $this->getClient(); @@ -69,15 +69,27 @@ class SecurityControllerTest extends WallabagCoreTestCase return; } + $client->followRedirects(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); $user = $em ->getRepository('WallabagUserBundle:User') ->findOneByUsername('admin'); + $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM'); + $em->persist($user); + $em->flush(); + + $this->logInAsUsingHttp('admin'); + $crawler = $client->request('GET', '/config'); + $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); - $date = new \DateTime(); - $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); - $this->assertTrue($user->isTrustedComputer('ABCDEF')); - $this->assertFalse($user->isTrustedComputer('FEDCBA')); + // restore user + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + $user->setGoogleAuthenticatorSecret(null); + $em->persist($user); + $em->flush(); } public function testEnabledRegistration() diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php index e34e13a8..1713c10c 100644 --- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php +++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php @@ -33,7 +33,7 @@ TWIG; public function testSendEmail() { $user = new User(); - $user->setTwoFactorAuthentication(true); + $user->setEmailTwoFactor(true); $user->setEmailAuthCode(666666); $user->setEmail('test@wallabag.io'); $user->setName('Bob'); -- cgit v1.2.3 From edc79ad886e4c96d1c2d205fedf5a9c19a177ee1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Dec 2018 17:25:56 +0100 Subject: Fix test for custom version of the tidy extension --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 3dd9273c..508adb1b 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -163,7 +163,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertSame('fr', $entry->getLanguage()); @@ -205,7 +205,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertNull($entry->getPreviewPicture()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertSame('fr', $entry->getLanguage()); @@ -247,7 +247,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertNull($entry->getLanguage()); $this->assertSame('200', $entry->getHttpStatus()); @@ -296,7 +296,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertNull($entry->getPreviewPicture()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertSame('fr', $entry->getLanguage()); @@ -332,7 +332,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertSame('fr', $entry->getLanguage()); $this->assertSame(4.0, $entry->getReadingTime()); @@ -371,7 +371,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertSame('fr', $entry->getLanguage()); $this->assertSame(4.0, $entry->getReadingTime()); @@ -406,7 +406,7 @@ class ContentProxyTest extends TestCase $this->assertSame('http://1.1.1.1', $entry->getUrl()); $this->assertSame('this is my title', $entry->getTitle()); - $this->assertContains('this is my content', $entry->getContent()); + $this->assertContains('content', $entry->getContent()); $this->assertSame('text/html', $entry->getMimetype()); $this->assertSame('fr', $entry->getLanguage()); $this->assertSame(4.0, $entry->getReadingTime()); -- cgit v1.2.3 From a0c5eb003f1cbeef10d5620e98870c7556e17c75 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 18 Jan 2019 22:46:44 +0100 Subject: Change the way to enable 2FA And add a step to validate a generated code from the OTP app --- .../CoreBundle/Controller/ConfigControllerTest.php | 194 +++++++++------------ 1 file changed, 81 insertions(+), 113 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 9ca52c64..1090a686 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -297,119 +297,6 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.config.notice.user_updated', $alert[0]); } - public function testUserEnable2faEmail() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/config'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('button[id=update_user_save]')->form(); - - $data = [ - 'update_user[emailTwoFactor]' => '1', - ]; - - $client->submit($form, $data); - - $this->assertSame(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.config.notice.user_updated', $alert[0]); - - // restore user - $em = $this->getEntityManager(); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $this->assertTrue($user->isEmailTwoFactor()); - - $user->setEmailTwoFactor(false); - $em->persist($user); - $em->flush(); - } - - public function testUserEnable2faGoogle() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/config'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('button[id=update_user_save]')->form(); - - $data = [ - 'update_user[googleTwoFactor]' => '1', - ]; - - $client->submit($form, $data); - - $this->assertSame(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.config.notice.user_updated', $alert[0]); - - // restore user - $em = $this->getEntityManager(); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $this->assertTrue($user->isGoogleAuthenticatorEnabled()); - - $user->setGoogleAuthenticatorSecret(null); - $em->persist($user); - $em->flush(); - } - - public function testUserEnable2faBoth() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/config'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('button[id=update_user_save]')->form(); - - $data = [ - 'update_user[googleTwoFactor]' => '1', - 'update_user[emailTwoFactor]' => '1', - ]; - - $client->submit($form, $data); - - $this->assertSame(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.config.notice.user_updated', $alert[0]); - - // restore user - $em = $this->getEntityManager(); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $this->assertTrue($user->isGoogleAuthenticatorEnabled()); - $this->assertFalse($user->isEmailTwoFactor()); - - $user->setGoogleAuthenticatorSecret(null); - $em->persist($user); - $em->flush(); - } - public function testRssUpdateResetToken() { $this->logInAs('admin'); @@ -1113,4 +1000,85 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); } + + public function testUserEnable2faEmail() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config/otp/email'); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]); + + // restore user + $em = $this->getEntityManager(); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertTrue($user->isEmailTwoFactor()); + + $user->setEmailTwoFactor(false); + $em->persist($user); + $em->flush(); + } + + public function testUserEnable2faGoogle() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config/otp/app'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + // restore user + $em = $this->getEntityManager(); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertTrue($user->isGoogleTwoFactor()); + $this->assertGreaterThan(0, $user->getBackupCodes()); + + $user->setGoogleAuthenticatorSecret(false); + $user->setBackupCodes(null); + $em->persist($user); + $em->flush(); + } + + public function testUserEnable2faGoogleCancel() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/config/otp/app'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + // restore user + $em = $this->getEntityManager(); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertTrue($user->isGoogleTwoFactor()); + $this->assertGreaterThan(0, $user->getBackupCodes()); + + $crawler = $client->request('GET', '/config/otp/app/cancel'); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $this->assertFalse($user->isGoogleTwoFactor()); + $this->assertEmpty($user->getBackupCodes()); + } } -- cgit v1.2.3 From 8c0ba953070dca22e9a06999cfe355ea01847c64 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 27 Feb 2019 14:59:50 +0100 Subject: Adding more tests --- .../GrabySiteConfigBuilderTest.php | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 1173fc3d..7beccd30 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -134,4 +134,72 @@ class GrabySiteConfigBuilderTest extends TestCase $this->assertCount(1, $records, 'One log was recorded'); } + + public function testBuildConfigWithBadExtraFields() + { + /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ + $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') + ->disableOriginalConstructor() + ->getMock(); + + $grabySiteConfig = new GrabySiteConfig(); + $grabySiteConfig->requires_login = true; + $grabySiteConfig->login_uri = 'http://www.example.com/login'; + $grabySiteConfig->login_username_field = 'login'; + $grabySiteConfig->login_password_field = 'password'; + $grabySiteConfig->login_extra_fields = ['field']; + $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; + + $grabyConfigBuilderMock + ->method('buildForHost') + ->with('example.com') + ->will($this->returnValue($grabySiteConfig)); + + $logger = new Logger('foo'); + $handler = new TestHandler(); + $logger->pushHandler($handler); + + $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') + ->disableOriginalConstructor() + ->getMock(); + $siteCrentialRepo->expects($this->once()) + ->method('findOneByHostAndUser') + ->with('example.com', 1) + ->willReturn(['username' => 'foo', 'password' => 'bar']); + + $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') + ->disableOriginalConstructor() + ->getMock(); + $user->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $token = new UsernamePasswordToken($user, 'pass', 'provider'); + + $tokenStorage = new TokenStorage(); + $tokenStorage->setToken($token); + + $this->builder = new GrabySiteConfigBuilder( + $grabyConfigBuilderMock, + $tokenStorage, + $siteCrentialRepo, + $logger + ); + + $config = $this->builder->buildForHost('www.example.com'); + + $this->assertSame('example.com', $config->getHost()); + $this->assertTrue($config->requiresLogin()); + $this->assertSame('http://www.example.com/login', $config->getLoginUri()); + $this->assertSame('login', $config->getUsernameField()); + $this->assertSame('password', $config->getPasswordField()); + $this->assertSame([], $config->getExtraFields()); + $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); + $this->assertSame('foo', $config->getUsername()); + $this->assertSame('bar', $config->getPassword()); + + $records = $handler->getRecords(); + + $this->assertCount(1, $records, 'One log was recorded'); + } } -- 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 ++++++++++- .../Command/GenerateUrlHashesCommandTest.php | 101 +++++++++++++++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php (limited to 'tests') 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()); } diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php new file mode 100644 index 00000000..8ca772cb --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php @@ -0,0 +1,101 @@ +getClient()->getKernel()); + $application->add(new GenerateUrlHashesCommand()); + + $command = $application->find('wallabag:generate-hashed-urls'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + + $this->assertContains('Generating hashed urls for the 3 user account entries', $tester->getDisplay()); + $this->assertContains('Finished generated hashed urls', $tester->getDisplay()); + } + + public function testRunGenerateUrlHashesCommandWithBadUsername() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new GenerateUrlHashesCommand()); + + $command = $application->find('wallabag:generate-hashed-urls'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'unknown', + ]); + + $this->assertContains('User "unknown" not found', $tester->getDisplay()); + } + + public function testRunGenerateUrlHashesCommandForUser() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new GenerateUrlHashesCommand()); + + $command = $application->find('wallabag:generate-hashed-urls'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ]); + + $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); + } + + public function testGenerateUrls() + { + $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html'; + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + + $this->logInAs('admin'); + + $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); + + $entry1 = new Entry($user); + $entry1->setUrl($url); + + $em->persist($entry1); + + $em->flush(); + + $this->assertNull($entry1->getHashedUrl()); + + $application = new Application($this->getClient()->getKernel()); + $application->add(new GenerateUrlHashesCommand()); + + $command = $application->find('wallabag:generate-hashed-urls'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ]); + + $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); + + $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); + + $this->assertEquals($entry->getHashedUrl(), hash('sha512', $url)); + + $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); + $query->setParameter('url', $url); + $query->execute(); + } +} -- 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 +++++++++++----------- .../Command/GenerateUrlHashesCommandTest.php | 8 +-- 2 files changed, 40 insertions(+), 43 deletions(-) (limited to 'tests') 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()); } diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php index 8ca772cb..cc1e3fbc 100644 --- a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php @@ -22,7 +22,7 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase 'command' => $command->getName(), ]); - $this->assertContains('Generating hashed urls for the 3 user account entries', $tester->getDisplay()); + $this->assertContains('Generating hashed urls for "3" users', $tester->getDisplay()); $this->assertContains('Finished generated hashed urls', $tester->getDisplay()); } @@ -55,7 +55,7 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); + $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); } public function testGenerateUrls() @@ -88,11 +88,11 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); + $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); - $this->assertEquals($entry->getHashedUrl(), hash('sha512', $url)); + $this->assertSame($entry->getHashedUrl(), hash('md5', $url)); $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); $query->setParameter('url', $url); -- 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 +++++++++++----------- .../Command/GenerateUrlHashesCommandTest.php | 5 +---- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'tests') 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()); diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php index cc1e3fbc..17eed210 100644 --- a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php @@ -72,11 +72,8 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $entry1->setUrl($url); $em->persist($entry1); - $em->flush(); - $this->assertNull($entry1->getHashedUrl()); - $application = new Application($this->getClient()->getKernel()); $application->add(new GenerateUrlHashesCommand()); @@ -92,7 +89,7 @@ class GenerateUrlHashesCommandTest extends WallabagCoreTestCase $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); - $this->assertSame($entry->getHashedUrl(), hash('md5', $url)); + $this->assertSame($entry->getHashedUrl(), hash('sha1', $url)); $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); $query->setParameter('url', $url); -- 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') 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 531c8d0a5c55fa93438e227a7d349235fbd31d28 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 13 Jun 2017 18:48:10 +0200 Subject: Changed RSS to Atom feed and improve paging --- .../CoreBundle/Controller/ConfigControllerTest.php | 32 +-- .../CoreBundle/Controller/FeedControllerTest.php | 228 +++++++++++++++++++++ .../CoreBundle/Controller/RssControllerTest.php | 221 -------------------- .../Controller/SecurityControllerTest.php | 2 +- .../UsernameFeedTokenConverterTest.php | 218 ++++++++++++++++++++ .../UsernameRssTokenConverterTest.php | 218 -------------------- .../CoreBundle/Twig/WallabagExtensionTest.php | 25 +++ .../EventListener/CreateConfigListenerTest.php | 2 +- 8 files changed, 489 insertions(+), 457 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php delete mode 100644 tests/Wallabag/CoreBundle/Controller/RssControllerTest.php create mode 100644 tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php delete mode 100644 tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 1090a686..d8478ce3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -33,7 +33,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('button[id=config_save]')); $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); - $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); + $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); } public function testUpdate() @@ -297,7 +297,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.config.notice.user_updated', $alert[0]); } - public function testRssUpdateResetToken() + public function testFeedUpdateResetToken() { $this->logInAs('admin'); $client = $this->getClient(); @@ -313,7 +313,7 @@ class ConfigControllerTest extends WallabagCoreTestCase } $config = $user->getConfig(); - $config->setRssToken(null); + $config->setFeedToken(null); $em->persist($config); $em->flush(); @@ -322,7 +322,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('config.form_rss.no_token', $body[0]); + $this->assertContains('config.form_feed.no_token', $body[0]); $client->request('GET', '/generate-token'); $this->assertSame(302, $client->getResponse()->getStatusCode()); @@ -330,7 +330,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertNotContains('config.form_rss.no_token', $body[0]); + $this->assertNotContains('config.form_feed.no_token', $body[0]); } public function testGenerateTokenAjax() @@ -351,7 +351,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('token', $content); } - public function testRssUpdate() + public function testFeedUpdate() { $this->logInAs('admin'); $client = $this->getClient(); @@ -360,10 +360,10 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(200, $client->getResponse()->getStatusCode()); - $form = $crawler->filter('button[id=rss_config_save]')->form(); + $form = $crawler->filter('button[id=feed_config_save]')->form(); $data = [ - 'rss_config[rss_limit]' => 12, + 'feed_config[feed_limit]' => 12, ]; $client->submit($form, $data); @@ -372,31 +372,31 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); } - public function dataForRssFailed() + public function dataForFeedFailed() { return [ [ [ - 'rss_config[rss_limit]' => 0, + 'feed_config[feed_limit]' => 0, ], 'This value should be 1 or more.', ], [ [ - 'rss_config[rss_limit]' => 1000000000000, + 'feed_config[feed_limit]' => 1000000000000, ], - 'validator.rss_limit_too_high', + 'validator.feed_limit_too_high', ], ]; } /** - * @dataProvider dataForRssFailed + * @dataProvider dataForFeedFailed */ - public function testRssFailed($data, $expectedMessage) + public function testFeedFailed($data, $expectedMessage) { $this->logInAs('admin'); $client = $this->getClient(); @@ -405,7 +405,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(200, $client->getResponse()->getStatusCode()); - $form = $crawler->filter('button[id=rss_config_save]')->form(); + $form = $crawler->filter('button[id=feed_config_save]')->form(); $crawler = $client->submit($form, $data); diff --git a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php new file mode 100644 index 00000000..7442e8a4 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php @@ -0,0 +1,228 @@ +loadXML($xml); + + $xpath = new \DOMXpath($doc); + $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom'); + + if (null === $nb) { + $this->assertGreaterThan(0, $xpath->query('//a:entry')->length); + } else { + $this->assertEquals($nb, $xpath->query('//a:entry')->length); + } + + $this->assertEquals(1, $xpath->query('/a:feed')->length); + + $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length); + $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue); + $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length); + + $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length); + $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); + $this->assertEquals('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length); + if (null !== $tagValue && 0 === strpos($type, 'tag')) { + $this->assertEquals('wallabag — '.$type.' '.$tagValue.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); + $this->assertEquals('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); + } else { + $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); + $this->assertEquals('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); + } + + $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); + $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href')); + + $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); + + foreach ($xpath->query('//a:entry') as $item) { + $this->assertEquals(1, $xpath->query('a:title', $item)->length); + $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length); + $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); + $this->assertEquals(1, $xpath->query('a:id', $item)->length); + $this->assertEquals(1, $xpath->query('a:published', $item)->length); + $this->assertEquals(1, $xpath->query('a:content', $item)->length); + } + } + + public function dataForBadUrl() + { + return [ + [ + '/feed/admin/YZIOAUZIAO/unread', + ], + [ + '/feed/wallace/YZIOAUZIAO/starred', + ], + [ + '/feed/wallace/YZIOAUZIAO/archives', + ], + [ + '/feed/wallace/YZIOAUZIAO/all', + ], + ]; + } + + /** + * @dataProvider dataForBadUrl + */ + public function testBadUrl($url) + { + $client = $this->getClient(); + + $client->request('GET', $url); + + $this->assertSame(404, $client->getResponse()->getStatusCode()); + } + + public function testUnread() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(2); + $em->persist($config); + $em->flush(); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'unread', 2); + } + + public function testStarred() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(1); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/feed/admin/SUPERTOKEN/starred'); + + $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); + + $this->validateDom($client->getResponse()->getContent(), 'starred'); + } + + public function testArchives() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/feed/admin/SUPERTOKEN/archive'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'archive'); + } + + public function testAll() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/feed/admin/SUPERTOKEN/all'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'all'); + } + + public function testPagination() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(1); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'unread'); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'unread'); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + } + + public function testTags() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo-bar'); + + $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + } +} diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php deleted file mode 100644 index afa90621..00000000 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ /dev/null @@ -1,221 +0,0 @@ -loadXML($xml); - - $xpath = new \DOMXPath($doc); - - if (null === $nb) { - $this->assertGreaterThan(0, $xpath->query('//item')->length); - } else { - $this->assertSame($nb, $xpath->query('//item')->length); - } - - $this->assertSame(1, $xpath->query('/rss')->length); - $this->assertSame(1, $xpath->query('/rss/channel')->length); - - $this->assertSame(1, $xpath->query('/rss/channel/title')->length); - $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); - - $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); - - $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); - $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); - - $this->assertSame(1, $xpath->query('/rss/channel/description')->length); - $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); - - $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); - $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); - - $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); - $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); - - foreach ($xpath->query('//item') as $item) { - $this->assertSame(1, $xpath->query('title', $item)->length); - $this->assertSame(1, $xpath->query('source', $item)->length); - $this->assertSame(1, $xpath->query('link', $item)->length); - $this->assertSame(1, $xpath->query('guid', $item)->length); - $this->assertSame(1, $xpath->query('pubDate', $item)->length); - $this->assertSame(1, $xpath->query('description', $item)->length); - } - } - - public function dataForBadUrl() - { - return [ - [ - '/admin/YZIOAUZIAO/unread.xml', - ], - [ - '/wallace/YZIOAUZIAO/starred.xml', - ], - [ - '/wallace/YZIOAUZIAO/archives.xml', - ], - [ - '/wallace/YZIOAUZIAO/all.xml', - ], - ]; - } - - /** - * @dataProvider dataForBadUrl - */ - public function testBadUrl($url) - { - $client = $this->getClient(); - - $client->request('GET', $url); - - $this->assertSame(404, $client->getResponse()->getStatusCode()); - } - - public function testUnread() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(2); - $em->persist($config); - $em->flush(); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); - } - - public function testStarred() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(1); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); - - $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); - } - - public function testArchives() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(null); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); - } - - public function testAll() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(null); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/all.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'all', 'all'); - } - - public function testPagination() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(1); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); - $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); - $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); - $this->assertSame(302, $client->getResponse()->getStatusCode()); - } - - public function testTags() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(null); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); - - $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); - $this->assertSame(302, $client->getResponse()->getStatusCode()); - } -} diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index b03c7550..3c3354d7 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -23,7 +23,7 @@ class SecurityControllerTest extends WallabagCoreTestCase $client->followRedirects(); $crawler = $client->request('GET', '/config'); - $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); } public function testLoginWith2FactorEmail() diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php new file mode 100644 index 00000000..92fe38cd --- /dev/null +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php @@ -0,0 +1,218 @@ +assertFalse($converter->supports($params)); + } + + public function testSupportsWithNoRegistryManagers() + { + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue([])); + + $params = new ParamConverter([]); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertFalse($converter->supports($params)); + } + + public function testSupportsWithNoConfigurationClass() + { + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue(['default' => null])); + + $params = new ParamConverter([]); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertFalse($converter->supports($params)); + } + + public function testSupportsWithNotTheGoodClass() + { + $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') + ->disableOriginalConstructor() + ->getMock(); + + $meta->expects($this->once()) + ->method('getName') + ->will($this->returnValue('nothingrelated')); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getClassMetadata') + ->with('superclass') + ->will($this->returnValue($meta)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue(['default' => null])); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('superclass') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'superclass']); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertFalse($converter->supports($params)); + } + + public function testSupportsWithGoodClass() + { + $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') + ->disableOriginalConstructor() + ->getMock(); + + $meta->expects($this->once()) + ->method('getName') + ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getClassMetadata') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($meta)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue(['default' => null])); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertTrue($converter->supports($params)); + } + + public function testApplyEmptyRequest() + { + $params = new ParamConverter([]); + $converter = new UsernameFeedTokenConverter(); + + $res = $converter->apply(new Request(), $params); + + $this->assertFalse($res); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @expectedExceptionMessage User not found + */ + public function testApplyUserNotFound() + { + $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $repo->expects($this->once()) + ->method('findOneByUsernameAndFeedToken') + ->with('test', 'test') + ->will($this->returnValue(null)); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getRepository') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($repo)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); + $converter = new UsernameFeedTokenConverter($registry); + $request = new Request([], [], ['username' => 'test', 'token' => 'test']); + + $converter->apply($request, $params); + } + + public function testApplyUserFound() + { + $user = new User(); + + $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $repo->expects($this->once()) + ->method('findOneByUsernameAndFeedtoken') + ->with('test', 'test') + ->will($this->returnValue($user)); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getRepository') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($repo)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); + $converter = new UsernameFeedTokenConverter($registry); + $request = new Request([], [], ['username' => 'test', 'token' => 'test']); + + $converter->apply($request, $params); + + $this->assertSame($user, $request->attributes->get('user')); + } +} diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php deleted file mode 100644 index 800af5c9..00000000 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ /dev/null @@ -1,218 +0,0 @@ -assertFalse($converter->supports($params)); - } - - public function testSupportsWithNoRegistryManagers() - { - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue([])); - - $params = new ParamConverter([]); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertFalse($converter->supports($params)); - } - - public function testSupportsWithNoConfigurationClass() - { - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue(['default' => null])); - - $params = new ParamConverter([]); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertFalse($converter->supports($params)); - } - - public function testSupportsWithNotTheGoodClass() - { - $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') - ->disableOriginalConstructor() - ->getMock(); - - $meta->expects($this->once()) - ->method('getName') - ->will($this->returnValue('nothingrelated')); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getClassMetadata') - ->with('superclass') - ->will($this->returnValue($meta)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue(['default' => null])); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('superclass') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'superclass']); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertFalse($converter->supports($params)); - } - - public function testSupportsWithGoodClass() - { - $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') - ->disableOriginalConstructor() - ->getMock(); - - $meta->expects($this->once()) - ->method('getName') - ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getClassMetadata') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($meta)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue(['default' => null])); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertTrue($converter->supports($params)); - } - - public function testApplyEmptyRequest() - { - $params = new ParamConverter([]); - $converter = new UsernameRssTokenConverter(); - - $res = $converter->apply(new Request(), $params); - - $this->assertFalse($res); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - * @expectedExceptionMessage User not found - */ - public function testApplyUserNotFound() - { - $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $repo->expects($this->once()) - ->method('findOneByUsernameAndRsstoken') - ->with('test', 'test') - ->will($this->returnValue(null)); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getRepository') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($repo)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); - $converter = new UsernameRssTokenConverter($registry); - $request = new Request([], [], ['username' => 'test', 'token' => 'test']); - - $converter->apply($request, $params); - } - - public function testApplyUserFound() - { - $user = new User(); - - $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $repo->expects($this->once()) - ->method('findOneByUsernameAndRsstoken') - ->with('test', 'test') - ->will($this->returnValue($user)); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getRepository') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($repo)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); - $converter = new UsernameRssTokenConverter($registry); - $request = new Request([], [], ['username' => 'test', 'token' => 'test']); - - $converter->apply($request, $params); - - $this->assertSame($user, $request->attributes->get('user')); - } -} diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index bb92f745..3fd90fda 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -32,6 +32,31 @@ class WallabagExtensionTest extends TestCase $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); } + public function testRemoveScheme() + { + $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') + ->disableOriginalConstructor() + ->getMock(); + + $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') + ->disableOriginalConstructor() + ->getMock(); + + $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface') + ->disableOriginalConstructor() + ->getMock(); + + $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); + + $this->assertEquals('lemonde.fr', $extension->removeScheme('lemonde.fr')); + $this->assertEquals('gist.github.com', $extension->removeScheme('gist.github.com')); + $this->assertEquals('gist.github.com', $extension->removeScheme('https://gist.github.com')); + } + public function testRemoveSchemeAndWww() { $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index c13bfbea..fd32f380 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -62,7 +62,7 @@ class CreateConfigListenerTest extends TestCase $config = new Config($user); $config->setTheme('baggy'); $config->setItemsPerPage(20); - $config->setRssLimit(50); + $config->setFeedLimit(50); $config->setLanguage('fr'); $config->setReadingSpeed(1); -- cgit v1.2.3 From f277bc042c8e805aab14b31b5b51e2878d80c6f4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 25 Apr 2019 14:12:56 +0200 Subject: Fix tests & cs & migration --- .../CoreBundle/Controller/EntryControllerTest.php | 2 +- .../CoreBundle/Controller/FeedControllerTest.php | 54 +++++++++++----------- .../Controller/SecurityControllerTest.php | 2 +- .../CoreBundle/Twig/WallabagExtensionTest.php | 6 +-- 4 files changed, 32 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 28291b5a..caa8929d 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -166,7 +166,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame($this->url, $content->getUrl()); $this->assertContains('Google', $content->getTitle()); $this->assertSame('fr', $content->getLanguage()); - $this->assertSame('2016-04-07 19:01:35', $content->getPublishedAt()->format('Y-m-d H:i:s')); + $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s')); $this->assertArrayHasKey('x-frame-options', $content->getHeaders()); $client->getContainer()->get('craue_config')->set('store_article_headers', 0); } diff --git a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php index 7442e8a4..70f33ebe 100644 --- a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php @@ -11,48 +11,48 @@ class FeedControllerTest extends WallabagCoreTestCase $doc = new \DOMDocument(); $doc->loadXML($xml); - $xpath = new \DOMXpath($doc); + $xpath = new \DOMXPath($doc); $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom'); if (null === $nb) { $this->assertGreaterThan(0, $xpath->query('//a:entry')->length); } else { - $this->assertEquals($nb, $xpath->query('//a:entry')->length); + $this->assertSame($nb, $xpath->query('//a:entry')->length); } - $this->assertEquals(1, $xpath->query('/a:feed')->length); + $this->assertSame(1, $xpath->query('/a:feed')->length); - $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length); + $this->assertSame(1, $xpath->query('/a:feed/a:title')->length); $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue); $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue); - $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length); + $this->assertSame(1, $xpath->query('/a:feed/a:updated')->length); - $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length); - $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); - $this->assertEquals('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); + $this->assertSame(1, $xpath->query('/a:feed/a:generator')->length); + $this->assertSame('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); + $this->assertSame('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); - $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length); + $this->assertSame(1, $xpath->query('/a:feed/a:subtitle')->length); if (null !== $tagValue && 0 === strpos($type, 'tag')) { - $this->assertEquals('wallabag — '.$type.' '.$tagValue.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); - $this->assertEquals('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); + $this->assertSame('wallabag — ' . $type . ' ' . $tagValue . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); + $this->assertSame('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); } else { - $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); - $this->assertEquals('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); + $this->assertSame('wallabag — ' . $type . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); + $this->assertSame('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); } - $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); + $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href')); - $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); + $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); foreach ($xpath->query('//a:entry') as $item) { - $this->assertEquals(1, $xpath->query('a:title', $item)->length); - $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length); - $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); - $this->assertEquals(1, $xpath->query('a:id', $item)->length); - $this->assertEquals(1, $xpath->query('a:published', $item)->length); - $this->assertEquals(1, $xpath->query('a:content', $item)->length); + $this->assertSame(1, $xpath->query('a:title', $item)->length); + $this->assertSame(1, $xpath->query('a:link[@rel="via"]', $item)->length); + $this->assertSame(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); + $this->assertSame(1, $xpath->query('a:id', $item)->length); + $this->assertSame(1, $xpath->query('a:published', $item)->length); + $this->assertSame(1, $xpath->query('a:content', $item)->length); } } @@ -190,15 +190,15 @@ class FeedControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'unread'); $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'unread'); $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); } public function testTags() @@ -216,13 +216,13 @@ class FeedControllerTest extends WallabagCoreTestCase $em->flush(); $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); + $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo'); $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo-bar'); + $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo'); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); + $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000'); $this->assertSame(302, $client->getResponse()->getStatusCode()); } } diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index 3c3354d7..93019b1f 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -13,7 +13,7 @@ class SecurityControllerTest extends WallabagCoreTestCase $client->followRedirects(); $crawler = $client->request('GET', '/config'); - $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); } public function testLoginWithout2Factor() diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index 3fd90fda..39fcec16 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -52,9 +52,9 @@ class WallabagExtensionTest extends TestCase $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); - $this->assertEquals('lemonde.fr', $extension->removeScheme('lemonde.fr')); - $this->assertEquals('gist.github.com', $extension->removeScheme('gist.github.com')); - $this->assertEquals('gist.github.com', $extension->removeScheme('https://gist.github.com')); + $this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr')); + $this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com')); + $this->assertSame('gist.github.com', $extension->removeScheme('https://gist.github.com')); } public function testRemoveSchemeAndWww() -- cgit v1.2.3 From 68a90821a305867e9b655da2dbfe558d37253990 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 26 Apr 2019 13:40:58 +0200 Subject: Handle redirection from previous feeds --- .../CoreBundle/Controller/FeedControllerTest.php | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php index 70f33ebe..d52d7bb8 100644 --- a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php @@ -225,4 +225,37 @@ class FeedControllerTest extends WallabagCoreTestCase $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000'); $this->assertSame(302, $client->getResponse()->getStatusCode()); } + + public function dataForRedirect() + { + return [ + [ + '/admin/YZIOAUZIAO/unread.xml', + ], + [ + '/admin/YZIOAUZIAO/starred.xml', + ], + [ + '/admin/YZIOAUZIAO/archive.xml', + ], + [ + '/admin/YZIOAUZIAO/all.xml', + ], + [ + '/admin/YZIOAUZIAO/tags/foo.xml', + ], + ]; + } + + /** + * @dataProvider dataForRedirect + */ + public function testRedirectFromRssToAtom($url) + { + $client = $this->getClient(); + + $client->request('GET', $url); + + $this->assertSame(301, $client->getResponse()->getStatusCode()); + } } -- cgit v1.2.3 From 77bd7f690db45be10a32fe4ceebccdd0edf7c24f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 10 May 2019 15:49:39 +0200 Subject: CS --- .../GrabySiteConfigBuilderTest.php | 6 ++-- .../UsernameFeedTokenConverterTest.php | 32 +++++++++++----------- .../EventListener/CreateConfigListenerTest.php | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 7beccd30..277d8012 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -33,7 +33,7 @@ class GrabySiteConfigBuilderTest extends TestCase $grabyConfigBuilderMock ->method('buildForHost') ->with('example.com') - ->will($this->returnValue($grabySiteConfig)); + ->willReturn($grabySiteConfig); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -93,7 +93,7 @@ class GrabySiteConfigBuilderTest extends TestCase $grabyConfigBuilderMock ->method('buildForHost') ->with('unknown.com') - ->will($this->returnValue(new GrabySiteConfig())); + ->willReturn(new GrabySiteConfig()); $logger = new Logger('foo'); $handler = new TestHandler(); @@ -153,7 +153,7 @@ class GrabySiteConfigBuilderTest extends TestCase $grabyConfigBuilderMock ->method('buildForHost') ->with('example.com') - ->will($this->returnValue($grabySiteConfig)); + ->willReturn($grabySiteConfig); $logger = new Logger('foo'); $handler = new TestHandler(); diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php index 92fe38cd..48c82dde 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php @@ -26,7 +26,7 @@ class UsernameFeedTokenConverterTest extends TestCase $registry->expects($this->once()) ->method('getManagers') - ->will($this->returnValue([])); + ->willReturn([]); $params = new ParamConverter([]); $converter = new UsernameFeedTokenConverter($registry); @@ -42,7 +42,7 @@ class UsernameFeedTokenConverterTest extends TestCase $registry->expects($this->once()) ->method('getManagers') - ->will($this->returnValue(['default' => null])); + ->willReturn(['default' => null]); $params = new ParamConverter([]); $converter = new UsernameFeedTokenConverter($registry); @@ -58,7 +58,7 @@ class UsernameFeedTokenConverterTest extends TestCase $meta->expects($this->once()) ->method('getName') - ->will($this->returnValue('nothingrelated')); + ->willReturn('nothingrelated'); $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') ->disableOriginalConstructor() @@ -67,7 +67,7 @@ class UsernameFeedTokenConverterTest extends TestCase $em->expects($this->once()) ->method('getClassMetadata') ->with('superclass') - ->will($this->returnValue($meta)); + ->willReturn($meta); $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') ->disableOriginalConstructor() @@ -75,12 +75,12 @@ class UsernameFeedTokenConverterTest extends TestCase $registry->expects($this->once()) ->method('getManagers') - ->will($this->returnValue(['default' => null])); + ->willReturn(['default' => null]); $registry->expects($this->once()) ->method('getManagerForClass') ->with('superclass') - ->will($this->returnValue($em)); + ->willReturn($em); $params = new ParamConverter(['class' => 'superclass']); $converter = new UsernameFeedTokenConverter($registry); @@ -96,7 +96,7 @@ class UsernameFeedTokenConverterTest extends TestCase $meta->expects($this->once()) ->method('getName') - ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); + ->willReturn('Wallabag\UserBundle\Entity\User'); $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') ->disableOriginalConstructor() @@ -105,7 +105,7 @@ class UsernameFeedTokenConverterTest extends TestCase $em->expects($this->once()) ->method('getClassMetadata') ->with('WallabagUserBundle:User') - ->will($this->returnValue($meta)); + ->willReturn($meta); $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') ->disableOriginalConstructor() @@ -113,12 +113,12 @@ class UsernameFeedTokenConverterTest extends TestCase $registry->expects($this->once()) ->method('getManagers') - ->will($this->returnValue(['default' => null])); + ->willReturn(['default' => null]); $registry->expects($this->once()) ->method('getManagerForClass') ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); + ->willReturn($em); $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); $converter = new UsernameFeedTokenConverter($registry); @@ -149,7 +149,7 @@ class UsernameFeedTokenConverterTest extends TestCase $repo->expects($this->once()) ->method('findOneByUsernameAndFeedToken') ->with('test', 'test') - ->will($this->returnValue(null)); + ->willReturn(null); $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') ->disableOriginalConstructor() @@ -158,7 +158,7 @@ class UsernameFeedTokenConverterTest extends TestCase $em->expects($this->once()) ->method('getRepository') ->with('WallabagUserBundle:User') - ->will($this->returnValue($repo)); + ->willReturn($repo); $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') ->disableOriginalConstructor() @@ -167,7 +167,7 @@ class UsernameFeedTokenConverterTest extends TestCase $registry->expects($this->once()) ->method('getManagerForClass') ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); + ->willReturn($em); $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); $converter = new UsernameFeedTokenConverter($registry); @@ -187,7 +187,7 @@ class UsernameFeedTokenConverterTest extends TestCase $repo->expects($this->once()) ->method('findOneByUsernameAndFeedtoken') ->with('test', 'test') - ->will($this->returnValue($user)); + ->willReturn($user); $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') ->disableOriginalConstructor() @@ -196,7 +196,7 @@ class UsernameFeedTokenConverterTest extends TestCase $em->expects($this->once()) ->method('getRepository') ->with('WallabagUserBundle:User') - ->will($this->returnValue($repo)); + ->willReturn($repo); $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') ->disableOriginalConstructor() @@ -205,7 +205,7 @@ class UsernameFeedTokenConverterTest extends TestCase $registry->expects($this->once()) ->method('getManagerForClass') ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); + ->willReturn($em); $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); $converter = new UsernameFeedTokenConverter($registry); diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index fd32f380..d976c4ac 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -68,7 +68,7 @@ class CreateConfigListenerTest extends TestCase $this->em->expects($this->once()) ->method('persist') - ->will($this->returnValue($config)); + ->willReturn($config); $this->em->expects($this->once()) ->method('flush'); -- cgit v1.2.3 From b8b37ccdea6b453aa228cb79755752b5738b98b9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 15 May 2019 14:58:40 +0200 Subject: CS --- .../GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 44affde8..9e0a9136 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -12,6 +12,8 @@ use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; class GrabySiteConfigBuilderTest extends WallabagCoreTestCase { + private $builder; + public function testBuildConfigExists() { $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') @@ -157,8 +159,8 @@ class GrabySiteConfigBuilderTest extends WallabagCoreTestCase ->disableOriginalConstructor() ->getMock(); $siteCrentialRepo->expects($this->once()) - ->method('findOneByHostAndUser') - ->with('example.com', 1) + ->method('findOneByHostsAndUser') + ->with(['example.com', '.com'], 1) ->willReturn(['username' => 'foo', 'password' => 'bar']); $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') -- 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') 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 715fabf8f286177c7abb216f0c867a989de18c32 Mon Sep 17 00:00:00 2001 From: nicofrand Date: Mon, 13 May 2019 21:56:52 +0200 Subject: [tests] Set first picture as preview picture --- .../CoreBundle/Helper/ContentProxyTest.php | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 508adb1b..8ed7fa5f 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -214,6 +214,90 @@ class ContentProxyTest extends TestCase $this->assertSame('1.1.1.1', $entry->getDomainName()); } + public function testWithContentAndContentImage() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => "

Test

", + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'status' => '200', + 'open_graph' => [ + 'og_title' => 'my OG title', + 'og_description' => 'OG desc', + 'og_image' => null, + ], + ]); + + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); + + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); + $this->assertSame("

Test

", $entry->getContent()); + $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame(0.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); + } + + public function testWithContentImageAndOgImage() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => "

Test

", + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'status' => '200', + 'open_graph' => [ + 'og_title' => 'my OG title', + 'og_description' => 'OG desc', + 'og_image' => 'http://3.3.3.3/cover.jpg', + ], + ]); + + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); + + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); + $this->assertSame("

Test

", $entry->getContent()); + $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame(0.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); + } + public function testWithContentAndBadLanguage() { $tagger = $this->getTaggerMock(); -- cgit v1.2.3 From d99e6423f4bd54595a8a805dd1efd0bd94e8bb09 Mon Sep 17 00:00:00 2001 From: nicofrand Date: Tue, 21 May 2019 20:10:57 +0200 Subject: [tests] Fix pre-existing tests (preview now imported + records added) --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 2 +- tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 8ed7fa5f..c7caac1d 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -499,7 +499,7 @@ class ContentProxyTest extends TestCase $records = $handler->getRecords(); - $this->assertCount(1, $records); + $this->assertCount(3, $records); $this->assertContains('Error while defining date', $records[0]['message']); } diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 1f57939d..2a8e7c89 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -121,7 +121,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is empty'); - $this->assertEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is empty'); + $this->assertSame($content->getPreviewPicture(), 'http://www.framablog.org/public/_img/framablog/wallaby_baby.jpg'); $this->assertEmpty($content->getLanguage(), 'Language for http://www.framablog.org is empty'); $tags = $content->getTags(); -- cgit v1.2.3 From bf9ace0643f654e7ccd9c020b8b501ad56cd19de Mon Sep 17 00:00:00 2001 From: adev Date: Tue, 24 Oct 2017 22:55:40 +0200 Subject: Use httplug --- .../CoreBundle/Helper/DownloadImagesTest.php | 79 ++-- .../ImportBundle/Import/PocketImportTest.php | 404 +++++++++------------ 2 files changed, 204 insertions(+), 279 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index cda5f843..53758364 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -3,9 +3,10 @@ namespace Tests\Wallabag\CoreBundle\Helper; use GuzzleHttp\Client; -use GuzzleHttp\Message\Response; use GuzzleHttp\Stream\Stream; use GuzzleHttp\Subscriber\Mock; +use Http\Mock\Client as HttpMockClient; +use GuzzleHttp\Psr7\Response; use Monolog\Handler\TestHandler; use Monolog\Logger; use PHPUnit\Framework\TestCase; @@ -32,18 +33,14 @@ class DownloadImagesTest extends TestCase */ public function testProcessHtml($html, $url) { - $client = new Client(); + $httpMockClient = new HttpMockClient(); - $mock = new Mock([ - new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processHtml(123, $html, $url); @@ -53,18 +50,13 @@ class DownloadImagesTest extends TestCase public function testProcessHtmlWithBadImage() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => 'application/json'], Stream::factory('')), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => 'application/json'], '')); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processHtml(123, '
', 'http://imgur.com/gallery/WxtWY'); $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); @@ -85,18 +77,13 @@ class DownloadImagesTest extends TestCase */ public function testProcessSingleImage($header, $extension) { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => $header], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); @@ -104,18 +91,13 @@ class DownloadImagesTest extends TestCase public function testProcessSingleImageWithBadUrl() { - $client = new Client(); - - $mock = new Mock([ - new Response(404, []), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(404, [])); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); @@ -123,18 +105,13 @@ class DownloadImagesTest extends TestCase public function testProcessSingleImageWithBadImage() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => 'image/png'], Stream::factory('')), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], '')); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); @@ -142,18 +119,13 @@ class DownloadImagesTest extends TestCase public function testProcessSingleImageFailAbsolute() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); @@ -161,18 +133,13 @@ class DownloadImagesTest extends TestCase public function testProcessRealImage() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage( 123, diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 8083f1a8..ec76f168 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -2,10 +2,8 @@ namespace Tests\Wallabag\ImportBundle\Import; -use GuzzleHttp\Client; -use GuzzleHttp\Message\Response; -use GuzzleHttp\Stream\Stream; -use GuzzleHttp\Subscriber\Mock; +use Http\Mock\Client as HttpMockClient; +use GuzzleHttp\Psr7\Response; use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; use Monolog\Logger; @@ -38,16 +36,11 @@ class PocketImportTest extends TestCase public function testOAuthRequest() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['code' => 'wunderbar_code']))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['code' => 'wunderbar_code']))); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); @@ -56,16 +49,11 @@ class PocketImportTest extends TestCase public function testOAuthRequestBadResponse() { - $client = new Client(); - - $mock = new Mock([ - new Response(403), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(403)); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); @@ -78,16 +66,11 @@ class PocketImportTest extends TestCase public function testOAuthAuthorize() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $res = $pocketImport->authorize('wunderbar_code'); @@ -97,16 +80,11 @@ class PocketImportTest extends TestCase public function testOAuthAuthorizeBadResponse() { - $client = new Client(); - - $mock = new Mock([ - new Response(403), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(403)); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $res = $pocketImport->authorize('wunderbar_code'); @@ -122,94 +100,90 @@ class PocketImportTest extends TestCase */ public function testImport() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' - { - "status": 1, - "list": { - "229279689": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "1", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "resolved_title": "The Massive Ryder Cup Preview", - "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "is_index": "0", - "has_video": "1", - "has_image": "1", - "word_count": "3197", - "images": { - "1": { - "item_id": "229279689", - "image_id": "1", - "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360", - "width": "0", - "height": "0", - "credit": "Jamie Squire/Getty Images", - "caption": "" - } - }, - "videos": { - "1": { - "item_id": "229279689", - "video_id": "1", - "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0", - "width": "420", - "height": "315", - "type": "1", - "vid": "Er34PbFkVGk" - } - }, - "tags": { - "grantland": { - "item_id": "1147652870", - "tag": "grantland" - }, - "Ryder Cup": { - "item_id": "1147652870", - "tag": "Ryder Cup" - } + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' + { + "status": 1, + "list": { + "229279689": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "is_index": "0", + "has_video": "1", + "has_image": "1", + "word_count": "3197", + "images": { + "1": { + "item_id": "229279689", + "image_id": "1", + "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360", + "width": "0", + "height": "0", + "credit": "Jamie Squire/Getty Images", + "caption": "" } }, - "229279690": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "1", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 1, - "resolved_title": "The Massive Ryder Cup Preview", - "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "is_index": "0", - "has_video": "0", - "has_image": "0", - "word_count": "3197" + "videos": { + "1": { + "item_id": "229279689", + "video_id": "1", + "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0", + "width": "420", + "height": "315", + "type": "1", + "vid": "Er34PbFkVGk" + } + }, + "tags": { + "grantland": { + "item_id": "1147652870", + "tag": "grantland" + }, + "Ryder Cup": { + "item_id": "1147652870", + "tag": "Ryder Cup" + } } + }, + "229279690": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "0", + "word_count": "3197" } } - ')), - ]); - - $client->getEmitter()->attach($mock); + } +JSON +)); $pocketImport = $this->getPocketImport('ConsumerKey', 1); @@ -240,7 +214,7 @@ class PocketImportTest extends TestCase ->method('updateEntry') ->willReturn($entry); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->import(); @@ -254,56 +228,52 @@ class PocketImportTest extends TestCase */ public function testImportAndMarkAllAsRead() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' - { - "status": 1, - "list": { - "229279689": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "1", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "has_video": "1", - "has_image": "1", - "word_count": "3197" - }, - "229279690": { - "item_id": "229279689", - "resolved_id": "229279689", - "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", - "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", - "favorite": "1", - "status": "0", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 1, - "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", - "is_article": "1", - "has_video": "0", - "has_image": "0", - "word_count": "3197" - } + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' + { + "status": 1, + "list": { + "229279689": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "1", + "has_image": "1", + "word_count": "3197" + }, + "229279690": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" } } - ')), - ]); - - $client->getEmitter()->attach($mock); + } +JSON +)); $pocketImport = $this->getPocketImport('ConsumerKey', 2); @@ -335,7 +305,7 @@ class PocketImportTest extends TestCase ->method('updateEntry') ->willReturn($entry); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->setMarkAsRead(true)->import(); @@ -349,7 +319,7 @@ class PocketImportTest extends TestCase */ public function testImportWithRabbit() { - $client = new Client(); + $httpMockClient = new HttpMockClient(); $body = <<<'JSON' { @@ -374,19 +344,16 @@ class PocketImportTest extends TestCase } JSON; - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' - { - "status": 1, - "list": { - "229279690": ' . $body . ' - } + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<getEmitter()->attach($mock); + } +JSON + )); $pocketImport = $this->getPocketImport(); @@ -420,7 +387,7 @@ JSON; ->method('publish') ->with(json_encode($bodyAsArray)); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->setProducer($producer); $pocketImport->authorize('wunderbar_code'); @@ -435,7 +402,7 @@ JSON; */ public function testImportWithRedis() { - $client = new Client(); + $httpMockClient = new HttpMockClient(); $body = <<<'JSON' { @@ -460,19 +427,16 @@ JSON; } JSON; - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' - { - "status": 1, - "list": { - "229279690": ' . $body . ' - } + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<getEmitter()->attach($mock); + } +JSON + )); $pocketImport = $this->getPocketImport(); @@ -499,7 +463,7 @@ JSON; $queue = new RedisQueue($redisMock, 'pocket'); $producer = new Producer($queue); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->setProducer($producer); $pocketImport->authorize('wunderbar_code'); @@ -513,17 +477,13 @@ JSON; public function testImportBadResponse() { - $client = new Client(); + $httpMockClient = new HttpMockClient(); - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(403), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(403)); $pocketImport = $this->getPocketImport(); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->import(); @@ -537,25 +497,23 @@ JSON; public function testImportWithExceptionFromGraby() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), - new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' - { - "status": 1, - "list": { - "229279689": { - "status": "1", - "favorite": "1", - "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" - } + $httpMockClient = new HttpMockClient(); + + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); + $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' + { + "status": 1, + "list": { + "229279689": { + "status": "1", + "favorite": "1", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" } } - ')), - ]); - - $client->getEmitter()->attach($mock); + } + +JSON + )); $pocketImport = $this->getPocketImport('ConsumerKey', 1); @@ -579,7 +537,7 @@ JSON; ->method('updateEntry') ->will($this->throwException(new \Exception())); - $pocketImport->setClient($client); + $pocketImport->setClient($httpMockClient); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->import(); -- cgit v1.2.3 From 5f08426201c336f96d593954fb45b284d7e60f4a Mon Sep 17 00:00:00 2001 From: adev Date: Sat, 11 Nov 2017 20:04:15 +0100 Subject: Fix because of some breaking changes of Graby 2.0 --- .../CoreBundle/Helper/ContentProxyTest.php | 70 ++++++++++++---------- 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index c7caac1d..40a6cc80 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -104,15 +104,12 @@ class ContentProxyTest extends TestCase ->method('fetchContent') ->willReturn([ 'html' => false, - 'title' => '', + 'title' => 'my title', 'url' => '', 'content_type' => '', 'language' => '', 'status' => '', - 'open_graph' => [ - 'og_title' => 'my title', - 'og_description' => 'desc', - ], + 'description' => 'desc', ]); $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); @@ -147,13 +144,12 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', 'status' => '200', - 'open_graph' => [ - 'og_title' => 'my OG title', - 'og_description' => 'OG desc', - 'og_image' => 'http://3.3.3.3/cover.jpg', + 'description' => 'OG desc', + 'image' => 'http://3.3.3.3/cover.jpg', + 'headers' => [ + 'content-type' => 'text/html', ], ]); @@ -189,13 +185,12 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', 'status' => '200', - 'open_graph' => [ - 'og_title' => 'my OG title', - 'og_description' => 'OG desc', - 'og_image' => null, + 'description' => 'OG desc', + 'image' => null, + 'headers' => [ + 'content-type' => 'text/html', ], ]); @@ -320,9 +315,11 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'dontexist', 'status' => '200', + 'headers' => [ + 'content-type' => 'text/html', + ], ]); $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); @@ -367,10 +364,10 @@ class ContentProxyTest extends TestCase 'content_type' => 'text/html', 'language' => 'fr', 'status' => '200', - 'open_graph' => [ - 'og_title' => 'my OG title', - 'og_description' => 'OG desc', - 'og_image' => 'https://', + 'description' => 'OG desc', + 'image' => 'https://', + 'headers' => [ + 'content-type' => 'text/html', ], ]); @@ -404,12 +401,12 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', 'date' => '1395635872', 'authors' => ['Jeremy', 'Nico', 'Thomas'], - 'all_headers' => [ - 'Cache-Control' => 'no-cache', + 'headers' => [ + 'cache-control' => 'no-cache', + 'content-type' => 'text/html', ], ] ); @@ -447,9 +444,11 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', 'date' => '2016-09-08T11:55:58+0200', + 'headers' => [ + 'content-type' => 'text/html', + ], ] ); @@ -482,9 +481,11 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', 'date' => '01 02 2012', + 'headers' => [ + 'content-type' => 'text/html', + ], ] ); @@ -519,8 +520,10 @@ class ContentProxyTest extends TestCase 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', + 'headers' => [ + 'content-type' => 'text/html', + ], ] ); @@ -559,13 +562,13 @@ class ContentProxyTest extends TestCase 'html' => $html, 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', 'language' => 'fr', 'status' => '200', - 'open_graph' => [ - 'og_title' => 'my OG title', - 'og_description' => 'OG desc', - 'og_image' => 'http://3.3.3.3/cover.jpg', + //'og_title' => 'my OG title', + 'description' => 'OG desc', + 'image' => 'http://3.3.3.3/cover.jpg', + 'headers' => [ + 'content-type' => 'text/html', ], ] ); @@ -597,9 +600,10 @@ class ContentProxyTest extends TestCase 'html' => '

', 'title' => 'this is my title', 'url' => 'http://1.1.1.1/image.jpg', - 'content_type' => 'image/jpeg', 'status' => '200', - 'open_graph' => [], + 'headers' => [ + 'content-type' => 'image/jpeg', + ], ]); $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); -- cgit v1.2.3 From 448d99f84e93697ce49ec31224addb1da1a37a9f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 28 Jan 2019 06:10:26 +0100 Subject: CS --- tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | 2 +- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 53758364..0199b3e4 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -3,10 +3,10 @@ namespace Tests\Wallabag\CoreBundle\Helper; use GuzzleHttp\Client; +use GuzzleHttp\Psr7\Response; use GuzzleHttp\Stream\Stream; use GuzzleHttp\Subscriber\Mock; use Http\Mock\Client as HttpMockClient; -use GuzzleHttp\Psr7\Response; use Monolog\Handler\TestHandler; use Monolog\Logger; use PHPUnit\Framework\TestCase; diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index ec76f168..40e1626b 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -2,8 +2,8 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Http\Mock\Client as HttpMockClient; use GuzzleHttp\Psr7\Response; +use Http\Mock\Client as HttpMockClient; use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; use Monolog\Logger; -- cgit v1.2.3 From b6c1e1bacc59ba761d1b47ac6611d1db800f7252 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 7 Feb 2019 17:56:05 +0100 Subject: Fix some tests --- .../CoreBundle/Helper/DownloadImagesTest.php | 44 +++++++--------------- 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 0199b3e4..3c720425 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -2,10 +2,7 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Response; -use GuzzleHttp\Stream\Stream; -use GuzzleHttp\Subscriber\Mock; use Http\Mock\Client as HttpMockClient; use Monolog\Handler\TestHandler; use Monolog\Logger; @@ -153,20 +150,15 @@ class DownloadImagesTest extends TestCase public function testProcessImageWithSrcset() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processHtml(123, '

', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); @@ -174,20 +166,15 @@ class DownloadImagesTest extends TestCase public function testProcessImageWithTrickySrcset() { - $client = new Client(); - - $mock = new Mock([ - new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), - ]); - - $client->getEmitter()->attach($mock); + $httpMockClient = new HttpMockClient(); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); + $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processHtml(123, '
Test

", 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', + 'headers' => [ + 'content-type' => 'text/html', + ], 'language' => 'fr', 'status' => '200', - 'open_graph' => [ - 'og_title' => 'my OG title', - 'og_description' => 'OG desc', - 'og_image' => null, - ], + 'image' => null, ]); $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); @@ -274,14 +272,12 @@ class ContentProxyTest extends TestCase 'html' => "

Test

", 'title' => 'this is my title', 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', + 'headers' => [ + 'content-type' => 'text/html', + ], 'language' => 'fr', 'status' => '200', - 'open_graph' => [ - 'og_title' => 'my OG title', - 'og_description' => 'OG desc', - 'og_image' => 'http://3.3.3.3/cover.jpg', - ], + 'image' => 'http://3.3.3.3/cover.jpg', ]); $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); -- cgit v1.2.3