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/CoreBundle/Controller/ConfigControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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/Wallabag/CoreBundle') 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 --- tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php | 6 +++--- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 12 +++++++----- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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 ++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'tests/Wallabag/CoreBundle') 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')); + } } -- 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/Wallabag/CoreBundle') 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/Wallabag/CoreBundle') 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 1e0d8ad7b728f6fb2cd886526b0fb84ef803e84f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 17 Jan 2019 14:28:05 +0100 Subject: Enable PHPStan - Fix error for level 0 & 1 (level 7 has 699 errors...) - Add `updated_at` to site_credential (so the `timestamps()` method applies correctly) --- tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 11 +++++------ tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 3 +++ .../ParamConverter/UsernameRssTokenConverterTest.php | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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 @@ 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/Wallabag/CoreBundle') 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 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 +++-- 3 files changed, 135 insertions(+), 9 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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() -- 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/Wallabag/CoreBundle') 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/Wallabag/CoreBundle') 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/Wallabag/CoreBundle') 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 --- .../Command/GenerateUrlHashesCommandTest.php | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php (limited to 'tests/Wallabag/CoreBundle') 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 --- .../Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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`. --- tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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 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 +++ 7 files changed, 488 insertions(+), 456 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/Wallabag/CoreBundle') 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') -- 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/Wallabag/CoreBundle') 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/Wallabag/CoreBundle') 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 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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); -- 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/Wallabag/CoreBundle') 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 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/Wallabag/CoreBundle') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') 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']); } -- 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 +++++++--------------- 1 file changed, 23 insertions(+), 56 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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, -- 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/Wallabag/CoreBundle') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') 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; -- 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/Wallabag/CoreBundle') 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