diff options
Diffstat (limited to 'tests/Wallabag')
13 files changed, 433 insertions, 265 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 6659443b..d37cbbf9 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | 3 | namespace Tests\Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\ApiBundle\Entity\Client; | ||
6 | 7 | ||
7 | class DeveloperControllerTest extends WallabagCoreTestCase | 8 | class DeveloperControllerTest extends WallabagCoreTestCase |
8 | { | 9 | { |
@@ -33,14 +34,10 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
33 | $this->assertContains('My app', $alert[0]); | 34 | $this->assertContains('My app', $alert[0]); |
34 | } | 35 | } |
35 | 36 | ||
36 | /** | ||
37 | * @depends testCreateClient | ||
38 | */ | ||
39 | public function testCreateToken() | 37 | public function testCreateToken() |
40 | { | 38 | { |
41 | $client = $this->getClient(); | 39 | $client = $this->getClient(); |
42 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 40 | $apiClient = $this->createApiClientForUser('admin'); |
43 | $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); | ||
44 | 41 | ||
45 | $client->request('POST', '/oauth/v2/token', [ | 42 | $client->request('POST', '/oauth/v2/token', [ |
46 | 'grant_type' => 'password', | 43 | 'grant_type' => 'password', |
@@ -83,6 +80,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
83 | public function testRemoveClient() | 80 | public function testRemoveClient() |
84 | { | 81 | { |
85 | $client = $this->getClient(); | 82 | $client = $this->getClient(); |
83 | $adminApiClient = $this->createApiClientForUser('admin'); | ||
86 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 84 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
87 | 85 | ||
88 | // Try to remove an admin's client with a wrong user | 86 | // Try to remove an admin's client with a wrong user |
@@ -90,12 +88,8 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
90 | $client->request('GET', '/developer'); | 88 | $client->request('GET', '/developer'); |
91 | $this->assertContains('no_client', $client->getResponse()->getContent()); | 89 | $this->assertContains('no_client', $client->getResponse()->getContent()); |
92 | 90 | ||
93 | // get an ID of a admin's client | ||
94 | $this->logInAs('admin'); | ||
95 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); | ||
96 | |||
97 | $this->logInAs('bob'); | 91 | $this->logInAs('bob'); |
98 | $client->request('GET', '/developer/client/delete/'.$nbClients[0]->getId()); | 92 | $client->request('GET', '/developer/client/delete/'.$adminApiClient->getId()); |
99 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 93 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); |
100 | 94 | ||
101 | // Try to remove the admin's client with the good user | 95 | // Try to remove the admin's client with the good user |
@@ -111,7 +105,29 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
111 | $client->click($link); | 105 | $client->click($link); |
112 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 106 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
113 | 107 | ||
114 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); | 108 | $this->assertNull( |
115 | $this->assertGreaterThan(count($newNbClients), count($nbClients)); | 109 | $em->getRepository('WallabagApiBundle:Client')->find($adminApiClient->getId()), |
110 | 'The client should have been removed' | ||
111 | ); | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * @param string $username | ||
116 | * | ||
117 | * @return Client | ||
118 | */ | ||
119 | private function createApiClientForUser($username) | ||
120 | { | ||
121 | $client = $this->getClient(); | ||
122 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
123 | $userManager = $client->getContainer()->get('fos_user.user_manager'); | ||
124 | $user = $userManager->findUserBy(array('username' => $username)); | ||
125 | $apiClient = new Client($user); | ||
126 | $apiClient->setName('My app'); | ||
127 | $apiClient->setAllowedGrantTypes(['password']); | ||
128 | $em->persist($apiClient); | ||
129 | $em->flush(); | ||
130 | |||
131 | return $apiClient; | ||
116 | } | 132 | } |
117 | } | 133 | } |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index bf7d373a..1ecd03fb 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -3,8 +3,10 @@ | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | 3 | namespace Tests\Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | 5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | use Wallabag\CoreBundle\Helper\ContentProxy; | 8 | use Wallabag\CoreBundle\Helper\ContentProxy; |
9 | use Wallabag\UserBundle\Entity\User; | ||
8 | 10 | ||
9 | class EntryRestControllerTest extends WallabagApiTestCase | 11 | class EntryRestControllerTest extends WallabagApiTestCase |
10 | { | 12 | { |
@@ -801,22 +803,28 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
801 | 803 | ||
802 | public function testDeleteEntriesTagsListAction() | 804 | public function testDeleteEntriesTagsListAction() |
803 | { | 805 | { |
804 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 806 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
805 | ->getRepository('WallabagCoreBundle:Entry') | 807 | $entry = new Entry($em->getReference(User::class, 1)); |
806 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 808 | $entry->setUrl('http://0.0.0.0/test-entry'); |
809 | $entry->addTag((new Tag())->setLabel('foo-tag')); | ||
810 | $entry->addTag((new Tag())->setLabel('bar-tag')); | ||
811 | $em->persist($entry); | ||
812 | $em->flush(); | ||
807 | 813 | ||
808 | $tags = $entry->getTags(); | 814 | $em->clear(); |
809 | |||
810 | $this->assertCount(4, $tags); | ||
811 | 815 | ||
812 | $list = [ | 816 | $list = [ |
813 | [ | 817 | [ |
814 | 'url' => 'http://0.0.0.0/entry4', | 818 | 'url' => 'http://0.0.0.0/test-entry', |
815 | 'tags' => 'new tag 1, new tag 2', | 819 | 'tags' => 'foo-tag, bar-tag', |
816 | ], | 820 | ], |
817 | ]; | 821 | ]; |
818 | 822 | ||
819 | $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); | 823 | $this->client->request('DELETE', '/api/entries/tags/list?list='.json_encode($list)); |
824 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
825 | |||
826 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId()); | ||
827 | $this->assertCount(0, $entry->getTags()); | ||
820 | } | 828 | } |
821 | 829 | ||
822 | public function testPostEntriesListAction() | 830 | public function testPostEntriesListAction() |
@@ -841,9 +849,14 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
841 | 849 | ||
842 | public function testDeleteEntriesListAction() | 850 | public function testDeleteEntriesListAction() |
843 | { | 851 | { |
852 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
853 | $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); | ||
854 | |||
855 | $em->flush(); | ||
856 | $em->clear(); | ||
844 | $list = [ | 857 | $list = [ |
845 | 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', | 858 | 'http://0.0.0.0/test-entry1', |
846 | 'http://0.0.0.0/entry3', | 859 | 'http://0.0.0.0/test-entry-not-exist', |
847 | ]; | 860 | ]; |
848 | 861 | ||
849 | $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); | 862 | $this->client->request('DELETE', '/api/entries/list?urls='.json_encode($list)); |
@@ -853,10 +866,10 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
853 | $content = json_decode($this->client->getResponse()->getContent(), true); | 866 | $content = json_decode($this->client->getResponse()->getContent(), true); |
854 | 867 | ||
855 | $this->assertTrue($content[0]['entry']); | 868 | $this->assertTrue($content[0]['entry']); |
856 | $this->assertEquals('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']); | 869 | $this->assertEquals('http://0.0.0.0/test-entry1', $content[0]['url']); |
857 | 870 | ||
858 | $this->assertFalse($content[1]['entry']); | 871 | $this->assertFalse($content[1]['entry']); |
859 | $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); | 872 | $this->assertEquals('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); |
860 | } | 873 | } |
861 | 874 | ||
862 | public function testLimitBulkAction() | 875 | public function testLimitBulkAction() |
diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 90b132eb..7f69bd67 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | |||
@@ -22,36 +22,35 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
22 | return end($content); | 22 | return end($content); |
23 | } | 23 | } |
24 | 24 | ||
25 | /** | 25 | public function testDeleteUserTag() |
26 | * @depends testGetUserTags | ||
27 | */ | ||
28 | public function testDeleteUserTag($tag) | ||
29 | { | 26 | { |
30 | $tagName = $tag['label']; | 27 | $tagLabel = 'tagtest'; |
28 | $tag = new Tag(); | ||
29 | $tag->setLabel($tagLabel); | ||
30 | |||
31 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
32 | $em->persist($tag); | ||
33 | $em->flush(); | ||
34 | $em->clear(); | ||
31 | 35 | ||
32 | $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); | 36 | $this->client->request('DELETE', '/api/tags/'.$tag->getId().'.json'); |
33 | 37 | ||
34 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 38 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
35 | 39 | ||
36 | $content = json_decode($this->client->getResponse()->getContent(), true); | 40 | $content = json_decode($this->client->getResponse()->getContent(), true); |
37 | 41 | ||
38 | $this->assertArrayHasKey('label', $content); | 42 | $this->assertArrayHasKey('label', $content); |
39 | $this->assertEquals($tag['label'], $content['label']); | 43 | $this->assertEquals($tag->getLabel(), $content['label']); |
40 | $this->assertEquals($tag['slug'], $content['slug']); | 44 | $this->assertEquals($tag->getSlug(), $content['slug']); |
41 | 45 | ||
42 | $entries = $this->client->getContainer() | 46 | $entries = $em->getRepository('WallabagCoreBundle:Entry') |
43 | ->get('doctrine.orm.entity_manager') | 47 | ->findAllByTagId($this->user->getId(), $tag->getId()); |
44 | ->getRepository('WallabagCoreBundle:Entry') | ||
45 | ->findAllByTagId($this->user->getId(), $tag['id']); | ||
46 | 48 | ||
47 | $this->assertCount(0, $entries); | 49 | $this->assertCount(0, $entries); |
48 | 50 | ||
49 | $tag = $this->client->getContainer() | 51 | $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); |
50 | ->get('doctrine.orm.entity_manager') | ||
51 | ->getRepository('WallabagCoreBundle:Tag') | ||
52 | ->findOneByLabel($tagName); | ||
53 | 52 | ||
54 | $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); | 53 | $this->assertNull($tag, $tagLabel.' was removed because it begun an orphan tag'); |
55 | } | 54 | } |
56 | 55 | ||
57 | public function dataForDeletingTagByLabel() | 56 | public function dataForDeletingTagByLabel() |
diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index a67655c8..8709da70 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php | |||
@@ -8,7 +8,7 @@ use Symfony\Component\BrowserKit\Cookie; | |||
8 | abstract class WallabagApiTestCase extends WebTestCase | 8 | abstract class WallabagApiTestCase extends WebTestCase |
9 | { | 9 | { |
10 | /** | 10 | /** |
11 | * @var Client | 11 | * @var \Symfony\Bundle\FrameworkBundle\Client |
12 | */ | 12 | */ |
13 | protected $client = null; | 13 | protected $client = null; |
14 | 14 | ||
@@ -23,7 +23,7 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
23 | } | 23 | } |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * @return Client | 26 | * @return \Symfony\Bundle\FrameworkBundle\Client |
27 | */ | 27 | */ |
28 | protected function createAuthorizedClient() | 28 | protected function createAuthorizedClient() |
29 | { | 29 | { |
diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 284efac4..2eebf39b 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php | |||
@@ -55,7 +55,7 @@ class ExportCommandTest extends WallabagCoreTestCase | |||
55 | 'username' => 'admin', | 55 | 'username' => 'admin', |
56 | ]); | 56 | ]); |
57 | 57 | ||
58 | $this->assertContains('Exporting 6 entrie(s) for user « admin »... Done', $tester->getDisplay()); | 58 | $this->assertContains('Exporting 5 entrie(s) for user « admin »... Done', $tester->getDisplay()); |
59 | $this->assertFileExists('admin-export.json'); | 59 | $this->assertFileExists('admin-export.json'); |
60 | } | 60 | } |
61 | 61 | ||
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 71c2ffc6..94fc0b94 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -2,8 +2,11 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Command; | 3 | namespace Tests\Wallabag\CoreBundle\Command; |
4 | 4 | ||
5 | use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; | ||
5 | use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; | 6 | use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; |
6 | use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; | 7 | use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; |
8 | use Doctrine\DBAL\Platforms\PostgreSqlPlatform; | ||
9 | use Doctrine\DBAL\Platforms\SqlitePlatform; | ||
7 | use Symfony\Bundle\FrameworkBundle\Console\Application; | 10 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
8 | use Symfony\Component\Console\Input\ArrayInput; | 11 | use Symfony\Component\Console\Input\ArrayInput; |
9 | use Symfony\Component\Console\Output\NullOutput; | 12 | use Symfony\Component\Console\Output\NullOutput; |
@@ -18,7 +21,9 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
18 | { | 21 | { |
19 | parent::setUp(); | 22 | parent::setUp(); |
20 | 23 | ||
21 | if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { | 24 | /** @var \Doctrine\DBAL\Connection $connection */ |
25 | $connection = $this->getClient()->getContainer()->get('doctrine')->getConnection(); | ||
26 | if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { | ||
22 | /* | 27 | /* |
23 | * LOG: statement: CREATE DATABASE "wallabag" | 28 | * LOG: statement: CREATE DATABASE "wallabag" |
24 | * ERROR: source database "template1" is being accessed by other users | 29 | * ERROR: source database "template1" is being accessed by other users |
@@ -30,34 +35,44 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
30 | */ | 35 | */ |
31 | $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); | 36 | $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); |
32 | } | 37 | } |
33 | } | ||
34 | 38 | ||
35 | /** | 39 | if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { |
36 | * Ensure next tests will have a clean database. | 40 | // Environnement variable useful only for sqlite to avoid the error "attempt to write a readonly database" |
37 | */ | 41 | // We can't define always this environnement variable because pdo_mysql seems to use it |
38 | public static function tearDownAfterClass() | 42 | // and we have the error: |
39 | { | 43 | // SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; |
40 | $application = new Application(static::$kernel); | 44 | // check the manual that corresponds to your MariaDB server version for the right syntax to use |
41 | $application->setAutoExit(false); | 45 | // near '/tmp/wallabag_testTYj1kp' at line 1 |
46 | $databasePath = tempnam(sys_get_temp_dir(), 'wallabag_test'); | ||
47 | putenv("TEST_DATABASE_PATH=$databasePath"); | ||
48 | |||
49 | // The environnement has been changed, recreate the client in order to update connection | ||
50 | parent::setUp(); | ||
51 | } | ||
42 | 52 | ||
43 | $application->run(new ArrayInput([ | 53 | // disable doctrine-test-bundle |
44 | 'command' => 'doctrine:schema:drop', | 54 | StaticDriver::setKeepStaticConnections(false); |
45 | '--no-interaction' => true, | ||
46 | '--force' => true, | ||
47 | '--env' => 'test', | ||
48 | ]), new NullOutput()); | ||
49 | 55 | ||
50 | $application->run(new ArrayInput([ | 56 | $this->resetDatabase($this->getClient()); |
51 | 'command' => 'doctrine:schema:create', | 57 | } |
52 | '--no-interaction' => true, | ||
53 | '--env' => 'test', | ||
54 | ]), new NullOutput()); | ||
55 | 58 | ||
56 | $application->run(new ArrayInput([ | 59 | public function tearDown() |
57 | 'command' => 'doctrine:fixtures:load', | 60 | { |
58 | '--no-interaction' => true, | 61 | $databasePath = getenv('TEST_DATABASE_PATH'); |
59 | '--env' => 'test', | 62 | // Remove variable environnement |
60 | ]), new NullOutput()); | 63 | putenv('TEST_DATABASE_PATH'); |
64 | if ($databasePath && file_exists($databasePath)) { | ||
65 | unlink($databasePath); | ||
66 | } else { | ||
67 | // Create a new client to avoid the error: | ||
68 | // Transaction commit failed because the transaction has been marked for rollback only. | ||
69 | $client = static::createClient(); | ||
70 | $this->resetDatabase($client); | ||
71 | } | ||
72 | |||
73 | // enable doctrine-test-bundle | ||
74 | StaticDriver::setKeepStaticConnections(true); | ||
75 | parent::tearDown(); | ||
61 | } | 76 | } |
62 | 77 | ||
63 | public function testRunInstallCommand() | 78 | public function testRunInstallCommand() |
@@ -120,7 +135,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
120 | { | 135 | { |
121 | // skipped SQLite check when database is removed because while testing for the connection, | 136 | // skipped SQLite check when database is removed because while testing for the connection, |
122 | // the driver will create the file (so the database) before testing if database exist | 137 | // the driver will create the file (so the database) before testing if database exist |
123 | if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { | 138 | if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { |
124 | $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); | 139 | $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); |
125 | } | 140 | } |
126 | 141 | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 35888f16..5bc815ee 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -67,8 +67,17 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
67 | public function testChangeReadingSpeed() | 67 | public function testChangeReadingSpeed() |
68 | { | 68 | { |
69 | $this->logInAs('admin'); | 69 | $this->logInAs('admin'); |
70 | $this->useTheme('baggy'); | ||
70 | $client = $this->getClient(); | 71 | $client = $this->getClient(); |
71 | 72 | ||
73 | $entry = new Entry($this->getLoggedInUser()); | ||
74 | $entry->setUrl('http://0.0.0.0/test-entry1') | ||
75 | ->setReadingTime(22); | ||
76 | $this->getEntityManager()->persist($entry); | ||
77 | |||
78 | $this->getEntityManager()->flush(); | ||
79 | $this->getEntityManager()->clear(); | ||
80 | |||
72 | $crawler = $client->request('GET', '/unread/list'); | 81 | $crawler = $client->request('GET', '/unread/list'); |
73 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 82 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
74 | $dataFilters = [ | 83 | $dataFilters = [ |
@@ -409,6 +418,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
409 | public function testTaggingRuleCreation() | 418 | public function testTaggingRuleCreation() |
410 | { | 419 | { |
411 | $this->logInAs('admin'); | 420 | $this->logInAs('admin'); |
421 | $this->useTheme('baggy'); | ||
412 | $client = $this->getClient(); | 422 | $client = $this->getClient(); |
413 | 423 | ||
414 | $crawler = $client->request('GET', '/config'); | 424 | $crawler = $client->request('GET', '/config'); |
@@ -939,6 +949,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
939 | public function testSwitchViewMode() | 949 | public function testSwitchViewMode() |
940 | { | 950 | { |
941 | $this->logInAs('admin'); | 951 | $this->logInAs('admin'); |
952 | $this->useTheme('baggy'); | ||
942 | $client = $this->getClient(); | 953 | $client = $this->getClient(); |
943 | 954 | ||
944 | $client->request('GET', '/unread/list'); | 955 | $client->request('GET', '/unread/list'); |
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 116e5f32..cc7b3672 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -71,6 +71,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
71 | public function testGetNew() | 71 | public function testGetNew() |
72 | { | 72 | { |
73 | $this->logInAs('admin'); | 73 | $this->logInAs('admin'); |
74 | $this->useTheme('baggy'); | ||
74 | $client = $this->getClient(); | 75 | $client = $this->getClient(); |
75 | 76 | ||
76 | $crawler = $client->request('GET', '/new'); | 77 | $crawler = $client->request('GET', '/new'); |
@@ -84,6 +85,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
84 | public function testPostNewViaBookmarklet() | 85 | public function testPostNewViaBookmarklet() |
85 | { | 86 | { |
86 | $this->logInAs('admin'); | 87 | $this->logInAs('admin'); |
88 | $this->useTheme('baggy'); | ||
87 | $client = $this->getClient(); | 89 | $client = $this->getClient(); |
88 | 90 | ||
89 | $crawler = $client->request('GET', '/'); | 91 | $crawler = $client->request('GET', '/'); |
@@ -195,6 +197,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
195 | public function testPostNewOkUrlExist() | 197 | public function testPostNewOkUrlExist() |
196 | { | 198 | { |
197 | $this->logInAs('admin'); | 199 | $this->logInAs('admin'); |
200 | |||
201 | $entry = new Entry($this->getLoggedInUser()); | ||
202 | $entry->setUrl($this->url); | ||
203 | $this->getEntityManager()->persist($entry); | ||
204 | $this->getEntityManager()->flush(); | ||
205 | |||
198 | $client = $this->getClient(); | 206 | $client = $this->getClient(); |
199 | 207 | ||
200 | $crawler = $client->request('GET', '/new'); | 208 | $crawler = $client->request('GET', '/new'); |
@@ -288,7 +296,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
288 | $tags = $entry->getTags(); | 296 | $tags = $entry->getTags(); |
289 | 297 | ||
290 | $this->assertCount(2, $tags); | 298 | $this->assertCount(2, $tags); |
291 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 299 | $this->assertContains('wallabag', $tags); |
292 | 300 | ||
293 | $em->remove($entry); | 301 | $em->remove($entry); |
294 | $em->flush(); | 302 | $em->flush(); |
@@ -317,7 +325,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
317 | $tags = $entry->getTags(); | 325 | $tags = $entry->getTags(); |
318 | 326 | ||
319 | $this->assertCount(2, $tags); | 327 | $this->assertCount(2, $tags); |
320 | $this->assertEquals('wallabag', $tags[1]->getLabel()); | 328 | $this->assertContains('wallabag', $tags); |
321 | 329 | ||
322 | $em->remove($entry); | 330 | $em->remove($entry); |
323 | $em->flush(); | 331 | $em->flush(); |
@@ -364,24 +372,23 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
364 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | 372 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); |
365 | } | 373 | } |
366 | 374 | ||
367 | /** | ||
368 | * @depends testPostNewOk | ||
369 | */ | ||
370 | public function testView() | 375 | public function testView() |
371 | { | 376 | { |
372 | $this->logInAs('admin'); | 377 | $this->logInAs('admin'); |
373 | $client = $this->getClient(); | 378 | $client = $this->getClient(); |
374 | 379 | ||
375 | $content = $client->getContainer() | 380 | $entry = new Entry($this->getLoggedInUser()); |
376 | ->get('doctrine.orm.entity_manager') | 381 | $entry->setUrl('http://example.com/foo'); |
377 | ->getRepository('WallabagCoreBundle:Entry') | 382 | $entry->setTitle('title foo'); |
378 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 383 | $entry->setContent('foo bar baz'); |
384 | $this->getEntityManager()->persist($entry); | ||
385 | $this->getEntityManager()->flush(); | ||
379 | 386 | ||
380 | $crawler = $client->request('GET', '/view/'.$content->getId()); | 387 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
381 | 388 | ||
382 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 389 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
383 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 390 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
384 | $this->assertContains($content->getTitle(), $body[0]); | 391 | $this->assertContains($entry->getTitle(), $body[0]); |
385 | } | 392 | } |
386 | 393 | ||
387 | /** | 394 | /** |
@@ -394,27 +401,23 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
394 | $this->logInAs('admin'); | 401 | $this->logInAs('admin'); |
395 | $client = $this->getClient(); | 402 | $client = $this->getClient(); |
396 | 403 | ||
397 | $em = $client->getContainer() | 404 | $entry = new Entry($this->getLoggedInUser()); |
398 | ->get('doctrine.orm.entity_manager'); | 405 | $entry->setUrl($this->url); |
406 | $entry->setTitle('title foo'); | ||
407 | $entry->setContent(''); | ||
408 | $this->getEntityManager()->persist($entry); | ||
409 | $this->getEntityManager()->flush(); | ||
410 | $this->getEntityManager()->clear(); | ||
399 | 411 | ||
400 | $content = $em | 412 | $client->request('GET', '/reload/'.$entry->getId()); |
401 | ->getRepository('WallabagCoreBundle:Entry') | ||
402 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
403 | |||
404 | // empty content | ||
405 | $content->setContent(''); | ||
406 | $em->persist($content); | ||
407 | $em->flush(); | ||
408 | |||
409 | $client->request('GET', '/reload/'.$content->getId()); | ||
410 | 413 | ||
411 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 414 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
412 | 415 | ||
413 | $content = $em | 416 | $entry = $this->getEntityManager() |
414 | ->getRepository('WallabagCoreBundle:Entry') | 417 | ->getRepository('WallabagCoreBundle:Entry') |
415 | ->find($content->getId()); | 418 | ->find($entry->getId()); |
416 | 419 | ||
417 | $this->assertNotEmpty($content->getContent()); | 420 | $this->assertNotEmpty($entry->getContent()); |
418 | } | 421 | } |
419 | 422 | ||
420 | /** | 423 | /** |
@@ -425,32 +428,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
425 | $this->logInAs('admin'); | 428 | $this->logInAs('admin'); |
426 | $client = $this->getClient(); | 429 | $client = $this->getClient(); |
427 | 430 | ||
428 | $em = $client->getContainer() | 431 | $entry = new Entry($this->getLoggedInUser()); |
429 | ->get('doctrine.orm.entity_manager'); | 432 | $entry->setUrl('http://0.0.0.0/failed.html'); |
430 | 433 | $this->getEntityManager()->persist($entry); | |
431 | $content = $em | 434 | $this->getEntityManager()->flush(); |
432 | ->getRepository('WallabagCoreBundle:Entry') | ||
433 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
434 | |||
435 | // put a known failed url | ||
436 | $content->setUrl('http://0.0.0.0/failed.html'); | ||
437 | $em->persist($content); | ||
438 | $em->flush(); | ||
439 | 435 | ||
440 | $client->request('GET', '/reload/'.$content->getId()); | 436 | $client->request('GET', '/reload/'.$entry->getId()); |
441 | 437 | ||
442 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 438 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
443 | 439 | ||
444 | // force EntityManager to clear previous entity | 440 | // force EntityManager to clear previous entity |
445 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | 441 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 |
446 | $em->clear(); | 442 | $this->getEntityManager()->clear(); |
447 | $newContent = $em | 443 | $newContent = $this->getEntityManager() |
448 | ->getRepository('WallabagCoreBundle:Entry') | 444 | ->getRepository('WallabagCoreBundle:Entry') |
449 | ->find($content->getId()); | 445 | ->find($entry->getId()); |
450 | |||
451 | $newContent->setUrl($this->url); | ||
452 | $em->persist($newContent); | ||
453 | $em->flush(); | ||
454 | 446 | ||
455 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | 447 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); |
456 | } | 448 | } |
@@ -460,12 +452,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
460 | $this->logInAs('admin'); | 452 | $this->logInAs('admin'); |
461 | $client = $this->getClient(); | 453 | $client = $this->getClient(); |
462 | 454 | ||
463 | $content = $client->getContainer() | 455 | $entry = new Entry($this->getLoggedInUser()); |
464 | ->get('doctrine.orm.entity_manager') | 456 | $entry->setUrl($this->url); |
465 | ->getRepository('WallabagCoreBundle:Entry') | 457 | $this->getEntityManager()->persist($entry); |
466 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 458 | $this->getEntityManager()->flush(); |
467 | 459 | ||
468 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 460 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
469 | 461 | ||
470 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 462 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
471 | 463 | ||
@@ -478,12 +470,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
478 | $this->logInAs('admin'); | 470 | $this->logInAs('admin'); |
479 | $client = $this->getClient(); | 471 | $client = $this->getClient(); |
480 | 472 | ||
481 | $content = $client->getContainer() | 473 | $entry = new Entry($this->getLoggedInUser()); |
482 | ->get('doctrine.orm.entity_manager') | 474 | $entry->setUrl($this->url); |
483 | ->getRepository('WallabagCoreBundle:Entry') | 475 | $this->getEntityManager()->persist($entry); |
484 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 476 | $this->getEntityManager()->flush(); |
485 | 477 | ||
486 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 478 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
487 | 479 | ||
488 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 480 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
489 | 481 | ||
@@ -508,19 +500,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
508 | $this->logInAs('admin'); | 500 | $this->logInAs('admin'); |
509 | $client = $this->getClient(); | 501 | $client = $this->getClient(); |
510 | 502 | ||
511 | $content = $client->getContainer() | 503 | $entry = new Entry($this->getLoggedInUser()); |
512 | ->get('doctrine.orm.entity_manager') | 504 | $entry->setUrl($this->url); |
513 | ->getRepository('WallabagCoreBundle:Entry') | 505 | $this->getEntityManager()->persist($entry); |
514 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 506 | $this->getEntityManager()->flush(); |
507 | $this->getEntityManager()->clear(); | ||
515 | 508 | ||
516 | $client->request('GET', '/archive/'.$content->getId()); | 509 | $client->request('GET', '/archive/'.$entry->getId()); |
517 | 510 | ||
518 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 511 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
519 | 512 | ||
520 | $res = $client->getContainer() | 513 | $res = $client->getContainer() |
521 | ->get('doctrine.orm.entity_manager') | 514 | ->get('doctrine.orm.entity_manager') |
522 | ->getRepository('WallabagCoreBundle:Entry') | 515 | ->getRepository('WallabagCoreBundle:Entry') |
523 | ->find($content->getId()); | 516 | ->find($entry->getId()); |
524 | 517 | ||
525 | $this->assertEquals($res->isArchived(), true); | 518 | $this->assertEquals($res->isArchived(), true); |
526 | } | 519 | } |
@@ -530,19 +523,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
530 | $this->logInAs('admin'); | 523 | $this->logInAs('admin'); |
531 | $client = $this->getClient(); | 524 | $client = $this->getClient(); |
532 | 525 | ||
533 | $content = $client->getContainer() | 526 | $entry = new Entry($this->getLoggedInUser()); |
534 | ->get('doctrine.orm.entity_manager') | 527 | $entry->setUrl($this->url); |
535 | ->getRepository('WallabagCoreBundle:Entry') | 528 | $this->getEntityManager()->persist($entry); |
536 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 529 | $this->getEntityManager()->flush(); |
530 | $this->getEntityManager()->clear(); | ||
537 | 531 | ||
538 | $client->request('GET', '/star/'.$content->getId()); | 532 | $client->request('GET', '/star/'.$entry->getId()); |
539 | 533 | ||
540 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 534 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
541 | 535 | ||
542 | $res = $client->getContainer() | 536 | $res = $client->getContainer() |
543 | ->get('doctrine.orm.entity_manager') | 537 | ->get('doctrine.orm.entity_manager') |
544 | ->getRepository('WallabagCoreBundle:Entry') | 538 | ->getRepository('WallabagCoreBundle:Entry') |
545 | ->findOneById($content->getId()); | 539 | ->findOneById($entry->getId()); |
546 | 540 | ||
547 | $this->assertEquals($res->isStarred(), true); | 541 | $this->assertEquals($res->isStarred(), true); |
548 | } | 542 | } |
@@ -552,16 +546,16 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
552 | $this->logInAs('admin'); | 546 | $this->logInAs('admin'); |
553 | $client = $this->getClient(); | 547 | $client = $this->getClient(); |
554 | 548 | ||
555 | $content = $client->getContainer() | 549 | $entry = new Entry($this->getLoggedInUser()); |
556 | ->get('doctrine.orm.entity_manager') | 550 | $entry->setUrl($this->url); |
557 | ->getRepository('WallabagCoreBundle:Entry') | 551 | $this->getEntityManager()->persist($entry); |
558 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 552 | $this->getEntityManager()->flush(); |
559 | 553 | ||
560 | $client->request('GET', '/delete/'.$content->getId()); | 554 | $client->request('GET', '/delete/'.$entry->getId()); |
561 | 555 | ||
562 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 556 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
563 | 557 | ||
564 | $client->request('GET', '/delete/'.$content->getId()); | 558 | $client->request('GET', '/delete/'.$entry->getId()); |
565 | 559 | ||
566 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 560 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
567 | } | 561 | } |
@@ -627,7 +621,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
627 | public function testFilterOnReadingTime() | 621 | public function testFilterOnReadingTime() |
628 | { | 622 | { |
629 | $this->logInAs('admin'); | 623 | $this->logInAs('admin'); |
624 | $this->useTheme('baggy'); | ||
630 | $client = $this->getClient(); | 625 | $client = $this->getClient(); |
626 | $entry = new Entry($this->getLoggedInUser()); | ||
627 | $entry->setUrl($this->url); | ||
628 | $entry->setReadingTime(22); | ||
629 | $this->getEntityManager()->persist($entry); | ||
630 | $this->getEntityManager()->flush(); | ||
631 | 631 | ||
632 | $crawler = $client->request('GET', '/unread/list'); | 632 | $crawler = $client->request('GET', '/unread/list'); |
633 | 633 | ||
@@ -666,9 +666,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
666 | public function testFilterOnReadingTimeOnlyUpper() | 666 | public function testFilterOnReadingTimeOnlyUpper() |
667 | { | 667 | { |
668 | $this->logInAs('admin'); | 668 | $this->logInAs('admin'); |
669 | $this->useTheme('baggy'); | ||
669 | $client = $this->getClient(); | 670 | $client = $this->getClient(); |
670 | 671 | ||
671 | $crawler = $client->request('GET', '/unread/list'); | 672 | $crawler = $client->request('GET', '/all/list'); |
673 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
674 | |||
675 | $entry = new Entry($this->getLoggedInUser()); | ||
676 | $entry->setUrl($this->url); | ||
677 | $entry->setReadingTime(23); | ||
678 | $this->getEntityManager()->persist($entry); | ||
679 | $this->getEntityManager()->flush(); | ||
680 | |||
681 | $crawler = $client->request('GET', '/all/list'); | ||
682 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | ||
672 | 683 | ||
673 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 684 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
674 | 685 | ||
@@ -678,12 +689,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
678 | 689 | ||
679 | $crawler = $client->submit($form, $data); | 690 | $crawler = $client->submit($form, $data); |
680 | 691 | ||
681 | $this->assertCount(3, $crawler->filter('div[class=entry]')); | 692 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
682 | } | 693 | } |
683 | 694 | ||
684 | public function testFilterOnReadingTimeOnlyLower() | 695 | public function testFilterOnReadingTimeOnlyLower() |
685 | { | 696 | { |
686 | $this->logInAs('admin'); | 697 | $this->logInAs('admin'); |
698 | $this->useTheme('baggy'); | ||
687 | $client = $this->getClient(); | 699 | $client = $this->getClient(); |
688 | 700 | ||
689 | $crawler = $client->request('GET', '/unread/list'); | 701 | $crawler = $client->request('GET', '/unread/list'); |
@@ -696,12 +708,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
696 | 708 | ||
697 | $crawler = $client->submit($form, $data); | 709 | $crawler = $client->submit($form, $data); |
698 | 710 | ||
699 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 711 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
712 | |||
713 | $entry = new Entry($this->getLoggedInUser()); | ||
714 | $entry->setUrl($this->url); | ||
715 | $entry->setReadingTime(23); | ||
716 | $this->getEntityManager()->persist($entry); | ||
717 | $this->getEntityManager()->flush(); | ||
718 | |||
719 | $crawler = $client->submit($form, $data); | ||
720 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | ||
700 | } | 721 | } |
701 | 722 | ||
702 | public function testFilterOnUnreadStatus() | 723 | public function testFilterOnUnreadStatus() |
703 | { | 724 | { |
704 | $this->logInAs('admin'); | 725 | $this->logInAs('admin'); |
726 | $this->useTheme('baggy'); | ||
705 | $client = $this->getClient(); | 727 | $client = $this->getClient(); |
706 | 728 | ||
707 | $crawler = $client->request('GET', '/all/list'); | 729 | $crawler = $client->request('GET', '/all/list'); |
@@ -714,12 +736,23 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
714 | 736 | ||
715 | $crawler = $client->submit($form, $data); | 737 | $crawler = $client->submit($form, $data); |
716 | 738 | ||
739 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | ||
740 | |||
741 | $entry = new Entry($this->getLoggedInUser()); | ||
742 | $entry->setUrl($this->url); | ||
743 | $entry->setArchived(false); | ||
744 | $this->getEntityManager()->persist($entry); | ||
745 | $this->getEntityManager()->flush(); | ||
746 | |||
747 | $crawler = $client->submit($form, $data); | ||
748 | |||
717 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 749 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
718 | } | 750 | } |
719 | 751 | ||
720 | public function testFilterOnCreationDate() | 752 | public function testFilterOnCreationDate() |
721 | { | 753 | { |
722 | $this->logInAs('admin'); | 754 | $this->logInAs('admin'); |
755 | $this->useTheme('baggy'); | ||
723 | $client = $this->getClient(); | 756 | $client = $this->getClient(); |
724 | 757 | ||
725 | $crawler = $client->request('GET', '/unread/list'); | 758 | $crawler = $client->request('GET', '/unread/list'); |
@@ -733,7 +766,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
733 | 766 | ||
734 | $crawler = $client->submit($form, $data); | 767 | $crawler = $client->submit($form, $data); |
735 | 768 | ||
736 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | 769 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
737 | 770 | ||
738 | $data = [ | 771 | $data = [ |
739 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | 772 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
@@ -742,7 +775,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
742 | 775 | ||
743 | $crawler = $client->submit($form, $data); | 776 | $crawler = $client->submit($form, $data); |
744 | 777 | ||
745 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | 778 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
746 | 779 | ||
747 | $data = [ | 780 | $data = [ |
748 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | 781 | 'entry_filter[createdAt][left_date]' => '01/01/1970', |
@@ -786,6 +819,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
786 | public function testFilterOnDomainName() | 819 | public function testFilterOnDomainName() |
787 | { | 820 | { |
788 | $this->logInAs('admin'); | 821 | $this->logInAs('admin'); |
822 | $this->useTheme('baggy'); | ||
789 | $client = $this->getClient(); | 823 | $client = $this->getClient(); |
790 | 824 | ||
791 | $crawler = $client->request('GET', '/unread/list'); | 825 | $crawler = $client->request('GET', '/unread/list'); |
@@ -818,6 +852,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
818 | public function testFilterOnStatus() | 852 | public function testFilterOnStatus() |
819 | { | 853 | { |
820 | $this->logInAs('admin'); | 854 | $this->logInAs('admin'); |
855 | $this->useTheme('baggy'); | ||
821 | $client = $this->getClient(); | 856 | $client = $this->getClient(); |
822 | 857 | ||
823 | $crawler = $client->request('GET', '/unread/list'); | 858 | $crawler = $client->request('GET', '/unread/list'); |
@@ -839,6 +874,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
839 | public function testPreviewPictureFilter() | 874 | public function testPreviewPictureFilter() |
840 | { | 875 | { |
841 | $this->logInAs('admin'); | 876 | $this->logInAs('admin'); |
877 | $this->useTheme('baggy'); | ||
842 | $client = $this->getClient(); | 878 | $client = $this->getClient(); |
843 | 879 | ||
844 | $crawler = $client->request('GET', '/unread/list'); | 880 | $crawler = $client->request('GET', '/unread/list'); |
@@ -846,14 +882,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
846 | $form['entry_filter[previewPicture]']->tick(); | 882 | $form['entry_filter[previewPicture]']->tick(); |
847 | 883 | ||
848 | $crawler = $client->submit($form); | 884 | $crawler = $client->submit($form); |
849 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 885 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
850 | } | 886 | } |
851 | 887 | ||
852 | public function testFilterOnLanguage() | 888 | public function testFilterOnLanguage() |
853 | { | 889 | { |
854 | $this->logInAs('admin'); | 890 | $this->logInAs('admin'); |
891 | $this->useTheme('baggy'); | ||
855 | $client = $this->getClient(); | 892 | $client = $this->getClient(); |
856 | 893 | ||
894 | $entry = new Entry($this->getLoggedInUser()); | ||
895 | $entry->setUrl($this->url); | ||
896 | $entry->setLanguage('fr'); | ||
897 | $this->getEntityManager()->persist($entry); | ||
898 | $this->getEntityManager()->flush(); | ||
899 | |||
857 | $crawler = $client->request('GET', '/unread/list'); | 900 | $crawler = $client->request('GET', '/unread/list'); |
858 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 901 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
859 | $data = [ | 902 | $data = [ |
@@ -877,10 +920,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
877 | $this->logInAs('admin'); | 920 | $this->logInAs('admin'); |
878 | $client = $this->getClient(); | 921 | $client = $this->getClient(); |
879 | 922 | ||
880 | $content = $client->getContainer() | 923 | // sharing is enabled |
881 | ->get('doctrine.orm.entity_manager') | 924 | $client->getContainer()->get('craue_config')->set('share_public', 1); |
882 | ->getRepository('WallabagCoreBundle:Entry') | 925 | |
883 | ->findOneByUser($this->getLoggedInUserId()); | 926 | $content = new Entry($this->getLoggedInUser()); |
927 | $content->setUrl($this->url); | ||
928 | $this->getEntityManager()->persist($content); | ||
929 | $this->getEntityManager()->flush(); | ||
930 | $this->getEntityManager()->clear(); | ||
884 | 931 | ||
885 | // no uid | 932 | // no uid |
886 | $client->request('GET', '/share/'.$content->getUid()); | 933 | $client->request('GET', '/share/'.$content->getUid()); |
@@ -970,6 +1017,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
970 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | 1017 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; |
971 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | 1018 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
972 | 1019 | ||
1020 | $crawler = $client->request('GET', '/new'); | ||
1021 | |||
1022 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1023 | |||
1024 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1025 | |||
1026 | $data = [ | ||
1027 | 'entry[url]' => $url, | ||
1028 | ]; | ||
1029 | |||
1030 | $client->submit($form, $data); | ||
1031 | |||
1032 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1033 | |||
973 | $content = $client->getContainer() | 1034 | $content = $client->getContainer() |
974 | ->get('doctrine.orm.entity_manager') | 1035 | ->get('doctrine.orm.entity_manager') |
975 | ->getRepository('WallabagCoreBundle:Entry') | 1036 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -987,28 +1048,19 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
987 | $this->logInAs('empty'); | 1048 | $this->logInAs('empty'); |
988 | $client = $this->getClient(); | 1049 | $client = $this->getClient(); |
989 | 1050 | ||
990 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
991 | $user = $em | ||
992 | ->getRepository('WallabagUserBundle:User') | ||
993 | ->find($this->getLoggedInUserId()); | ||
994 | |||
995 | if (!$user) { | ||
996 | $this->markTestSkipped('No user found in db.'); | ||
997 | } | ||
998 | |||
999 | // Redirect to homepage | 1051 | // Redirect to homepage |
1000 | $config = $user->getConfig(); | 1052 | $config = $this->getLoggedInUser()->getConfig(); |
1001 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | 1053 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
1002 | $em->persist($config); | 1054 | $this->getEntityManager()->persist($config); |
1003 | $em->flush(); | ||
1004 | 1055 | ||
1005 | $content = $client->getContainer() | 1056 | $entry = new Entry($this->getLoggedInUser()); |
1006 | ->get('doctrine.orm.entity_manager') | 1057 | $entry->setUrl($this->url); |
1007 | ->getRepository('WallabagCoreBundle:Entry') | 1058 | $this->getEntityManager()->persist($entry); |
1008 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
1009 | 1059 | ||
1010 | $client->request('GET', '/view/'.$content->getId()); | 1060 | $this->getEntityManager()->flush(); |
1011 | $client->request('GET', '/archive/'.$content->getId()); | 1061 | |
1062 | $client->request('GET', '/view/'.$entry->getId()); | ||
1063 | $client->request('GET', '/archive/'.$entry->getId()); | ||
1012 | 1064 | ||
1013 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1065 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
1014 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | 1066 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); |
@@ -1019,46 +1071,36 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1019 | $this->logInAs('empty'); | 1071 | $this->logInAs('empty'); |
1020 | $client = $this->getClient(); | 1072 | $client = $this->getClient(); |
1021 | 1073 | ||
1022 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
1023 | $user = $em | ||
1024 | ->getRepository('WallabagUserBundle:User') | ||
1025 | ->find($this->getLoggedInUserId()); | ||
1026 | |||
1027 | if (!$user) { | ||
1028 | $this->markTestSkipped('No user found in db.'); | ||
1029 | } | ||
1030 | |||
1031 | // Redirect to current page | 1074 | // Redirect to current page |
1032 | $config = $user->getConfig(); | 1075 | $config = $this->getLoggedInUser()->getConfig(); |
1033 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | 1076 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
1034 | $em->persist($config); | 1077 | $this->getEntityManager()->persist($config); |
1035 | $em->flush(); | ||
1036 | 1078 | ||
1037 | $content = $client->getContainer() | 1079 | $entry = new Entry($this->getLoggedInUser()); |
1038 | ->get('doctrine.orm.entity_manager') | 1080 | $entry->setUrl($this->url); |
1039 | ->getRepository('WallabagCoreBundle:Entry') | 1081 | $this->getEntityManager()->persist($entry); |
1040 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
1041 | 1082 | ||
1042 | $client->request('GET', '/view/'.$content->getId()); | 1083 | $this->getEntityManager()->flush(); |
1043 | $client->request('GET', '/archive/'.$content->getId()); | 1084 | |
1085 | $client->request('GET', '/view/'.$entry->getId()); | ||
1086 | $client->request('GET', '/archive/'.$entry->getId()); | ||
1044 | 1087 | ||
1045 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1088 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
1046 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | 1089 | $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); |
1047 | } | 1090 | } |
1048 | 1091 | ||
1049 | public function testFilterOnHttpStatus() | 1092 | public function testFilterOnHttpStatus() |
1050 | { | 1093 | { |
1051 | $this->logInAs('admin'); | 1094 | $this->logInAs('admin'); |
1095 | $this->useTheme('baggy'); | ||
1052 | $client = $this->getClient(); | 1096 | $client = $this->getClient(); |
1053 | 1097 | ||
1054 | $crawler = $client->request('GET', '/new'); | 1098 | $entry = new Entry($this->getLoggedInUser()); |
1055 | $form = $crawler->filter('form[name=entry]')->form(); | 1099 | $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); |
1100 | $entry->setHttpStatus(404); | ||
1101 | $this->getEntityManager()->persist($entry); | ||
1056 | 1102 | ||
1057 | $data = [ | 1103 | $this->getEntityManager()->flush(); |
1058 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | ||
1059 | ]; | ||
1060 | |||
1061 | $client->submit($form, $data); | ||
1062 | 1104 | ||
1063 | $crawler = $client->request('GET', '/all/list'); | 1105 | $crawler = $client->request('GET', '/all/list'); |
1064 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1106 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1071,14 +1113,17 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1071 | 1113 | ||
1072 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1114 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1073 | 1115 | ||
1074 | $crawler = $client->request('GET', '/new'); | 1116 | $entry = new Entry($this->getLoggedInUser()); |
1075 | $form = $crawler->filter('form[name=entry]')->form(); | 1117 | $entry->setUrl($this->url); |
1118 | $entry->setHttpStatus(200); | ||
1119 | $this->getEntityManager()->persist($entry); | ||
1076 | 1120 | ||
1077 | $data = [ | 1121 | $entry = new Entry($this->getLoggedInUser()); |
1078 | 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', | 1122 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); |
1079 | ]; | 1123 | $entry->setHttpStatus(200); |
1124 | $this->getEntityManager()->persist($entry); | ||
1080 | 1125 | ||
1081 | $client->submit($form, $data); | 1126 | $this->getEntityManager()->flush(); |
1082 | 1127 | ||
1083 | $crawler = $client->request('GET', '/all/list'); | 1128 | $crawler = $client->request('GET', '/all/list'); |
1084 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1129 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1106,8 +1151,15 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1106 | public function testSearch() | 1151 | public function testSearch() |
1107 | { | 1152 | { |
1108 | $this->logInAs('admin'); | 1153 | $this->logInAs('admin'); |
1154 | $this->useTheme('baggy'); | ||
1109 | $client = $this->getClient(); | 1155 | $client = $this->getClient(); |
1110 | 1156 | ||
1157 | $entry = new Entry($this->getLoggedInUser()); | ||
1158 | $entry->setUrl($this->url); | ||
1159 | $entry->setTitle('test'); | ||
1160 | $this->getEntityManager()->persist($entry); | ||
1161 | $this->getEntityManager()->flush(); | ||
1162 | |||
1111 | // Search on unread list | 1163 | // Search on unread list |
1112 | $crawler = $client->request('GET', '/unread/list'); | 1164 | $crawler = $client->request('GET', '/unread/list'); |
1113 | 1165 | ||
@@ -1118,35 +1170,37 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1118 | 1170 | ||
1119 | $crawler = $client->submit($form, $data); | 1171 | $crawler = $client->submit($form, $data); |
1120 | 1172 | ||
1121 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 1173 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
1122 | 1174 | ||
1123 | // Search on starred list | 1175 | // Search on starred list |
1124 | $crawler = $client->request('GET', '/starred/list'); | 1176 | $crawler = $client->request('GET', '/starred/list'); |
1125 | 1177 | ||
1178 | $entry = new Entry($this->getLoggedInUser()); | ||
1179 | $entry->setUrl('http://localhost/foo/bar'); | ||
1180 | $entry->setTitle('testeur'); | ||
1181 | $entry->setStarred(true); | ||
1182 | $this->getEntityManager()->persist($entry); | ||
1183 | $this->getEntityManager()->flush(); | ||
1184 | |||
1126 | $form = $crawler->filter('form[name=search]')->form(); | 1185 | $form = $crawler->filter('form[name=search]')->form(); |
1127 | $data = [ | 1186 | $data = [ |
1128 | 'search_entry[term]' => 'title', | 1187 | 'search_entry[term]' => 'testeur', |
1129 | ]; | 1188 | ]; |
1130 | 1189 | ||
1131 | $crawler = $client->submit($form, $data); | 1190 | $crawler = $client->submit($form, $data); |
1132 | 1191 | ||
1133 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1192 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1134 | 1193 | ||
1135 | // Added new article to test on archive list | ||
1136 | $crawler = $client->request('GET', '/new'); | ||
1137 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1138 | $data = [ | ||
1139 | 'entry[url]' => $this->url, | ||
1140 | ]; | ||
1141 | $client->submit($form, $data); | ||
1142 | $content = $client->getContainer() | ||
1143 | ->get('doctrine.orm.entity_manager') | ||
1144 | ->getRepository('WallabagCoreBundle:Entry') | ||
1145 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
1146 | $client->request('GET', '/archive/'.$content->getId()); | ||
1147 | |||
1148 | $crawler = $client->request('GET', '/archive/list'); | 1194 | $crawler = $client->request('GET', '/archive/list'); |
1149 | 1195 | ||
1196 | // Added new article to test on archive list | ||
1197 | $entry = new Entry($this->getLoggedInUser()); | ||
1198 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | ||
1199 | $entry->setTitle('Le manège'); | ||
1200 | $entry->setArchived(true); | ||
1201 | $this->getEntityManager()->persist($entry); | ||
1202 | $this->getEntityManager()->flush(); | ||
1203 | |||
1150 | $form = $crawler->filter('form[name=search]')->form(); | 1204 | $form = $crawler->filter('form[name=search]')->form(); |
1151 | $data = [ | 1205 | $data = [ |
1152 | 'search_entry[term]' => 'manège', | 1206 | 'search_entry[term]' => 'manège', |
@@ -1155,7 +1209,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1155 | $crawler = $client->submit($form, $data); | 1209 | $crawler = $client->submit($form, $data); |
1156 | 1210 | ||
1157 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1211 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1158 | $client->request('GET', '/delete/'.$content->getId()); | 1212 | $client->request('GET', '/delete/'.$entry->getId()); |
1159 | 1213 | ||
1160 | // test on list of all articles | 1214 | // test on list of all articles |
1161 | $crawler = $client->request('GET', '/all/list'); | 1215 | $crawler = $client->request('GET', '/all/list'); |
@@ -1170,6 +1224,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1170 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | 1224 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
1171 | 1225 | ||
1172 | // test url search on list of all articles | 1226 | // test url search on list of all articles |
1227 | $entry = new Entry($this->getLoggedInUser()); | ||
1228 | $entry->setUrl('http://domain/qux'); | ||
1229 | $entry->setTitle('Le manège'); | ||
1230 | $entry->setArchived(true); | ||
1231 | $this->getEntityManager()->persist($entry); | ||
1232 | $this->getEntityManager()->flush(); | ||
1233 | |||
1173 | $crawler = $client->request('GET', '/all/list'); | 1234 | $crawler = $client->request('GET', '/all/list'); |
1174 | 1235 | ||
1175 | $form = $crawler->filter('form[name=search]')->form(); | 1236 | $form = $crawler->filter('form[name=search]')->form(); |
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 63f2c829..b38961d3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | |||
@@ -239,7 +239,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
239 | $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); | 239 | $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); |
240 | $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); | 240 | $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); |
241 | $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); | 241 | $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); |
242 | $this->assertEquals(['foo bar', 'baz', 'foot'], $content[0]['tags']); | 242 | $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']); |
243 | } | 243 | } |
244 | 244 | ||
245 | public function testXmlExport() | 245 | public function testXmlExport() |
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 80611a87..f9bf7b87 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | 8 | ||
8 | class TagControllerTest extends WallabagCoreTestCase | 9 | class TagControllerTest extends WallabagCoreTestCase |
@@ -24,10 +25,11 @@ class TagControllerTest extends WallabagCoreTestCase | |||
24 | $this->logInAs('admin'); | 25 | $this->logInAs('admin'); |
25 | $client = $this->getClient(); | 26 | $client = $this->getClient(); |
26 | 27 | ||
27 | $entry = $client->getContainer() | 28 | $entry = new Entry($this->getLoggedInUser()); |
28 | ->get('doctrine.orm.entity_manager') | 29 | $entry->setUrl('http://0.0.0.0/foo'); |
29 | ->getRepository('WallabagCoreBundle:Entry') | 30 | $this->getEntityManager()->persist($entry); |
30 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 31 | $this->getEntityManager()->flush(); |
32 | $this->getEntityManager()->clear(); | ||
31 | 33 | ||
32 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 34 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
33 | 35 | ||
@@ -41,23 +43,15 @@ class TagControllerTest extends WallabagCoreTestCase | |||
41 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 43 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
42 | 44 | ||
43 | // be sure to reload the entry | 45 | // be sure to reload the entry |
44 | $entry = $client->getContainer() | 46 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
45 | ->get('doctrine.orm.entity_manager') | 47 | $this->assertCount(1, $entry->getTags()); |
46 | ->getRepository('WallabagCoreBundle:Entry') | ||
47 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | ||
48 | |||
49 | $this->assertEquals(4, count($entry->getTags())); | ||
50 | 48 | ||
51 | // tag already exists and already assigned | 49 | // tag already exists and already assigned |
52 | $client->submit($form, $data); | 50 | $client->submit($form, $data); |
53 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 51 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
54 | 52 | ||
55 | $newEntry = $client->getContainer() | 53 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
56 | ->get('doctrine.orm.entity_manager') | 54 | $this->assertCount(1, $entry->getTags()); |
57 | ->getRepository('WallabagCoreBundle:Entry') | ||
58 | ->find($entry->getId()); | ||
59 | |||
60 | $this->assertEquals(4, count($newEntry->getTags())); | ||
61 | 55 | ||
62 | // tag already exists but still not assigned to this entry | 56 | // tag already exists but still not assigned to this entry |
63 | $data = [ | 57 | $data = [ |
@@ -67,12 +61,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
67 | $client->submit($form, $data); | 61 | $client->submit($form, $data); |
68 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 62 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
69 | 63 | ||
70 | $newEntry = $client->getContainer() | 64 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
71 | ->get('doctrine.orm.entity_manager') | 65 | $this->assertCount(2, $entry->getTags()); |
72 | ->getRepository('WallabagCoreBundle:Entry') | ||
73 | ->find($entry->getId()); | ||
74 | |||
75 | $this->assertEquals(4, count($newEntry->getTags())); | ||
76 | } | 66 | } |
77 | 67 | ||
78 | public function testAddMultipleTagToEntry() | 68 | public function testAddMultipleTagToEntry() |
@@ -116,15 +106,14 @@ class TagControllerTest extends WallabagCoreTestCase | |||
116 | $this->logInAs('admin'); | 106 | $this->logInAs('admin'); |
117 | $client = $this->getClient(); | 107 | $client = $this->getClient(); |
118 | 108 | ||
119 | $entry = $client->getContainer() | 109 | $tag = new Tag(); |
120 | ->get('doctrine.orm.entity_manager') | 110 | $tag->setLabel($this->tagName); |
121 | ->getRepository('WallabagCoreBundle:Entry') | 111 | $entry = new Entry($this->getLoggedInUser()); |
122 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 112 | $entry->setUrl('http://0.0.0.0/foo'); |
123 | 113 | $entry->addTag($tag); | |
124 | $tag = $client->getContainer() | 114 | $this->getEntityManager()->persist($entry); |
125 | ->get('doctrine.orm.entity_manager') | 115 | $this->getEntityManager()->flush(); |
126 | ->getRepository('WallabagCoreBundle:Tag') | 116 | $this->getEntityManager()->clear(); |
127 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | ||
128 | 117 | ||
129 | // We make a first request to set an history and test redirection after tag deletion | 118 | // We make a first request to set an history and test redirection after tag deletion |
130 | $client->request('GET', '/view/'.$entry->getId()); | 119 | $client->request('GET', '/view/'.$entry->getId()); |
@@ -134,12 +123,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
134 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
135 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); | 124 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); |
136 | 125 | ||
137 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) | 126 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) |
138 | $entry = $client->getContainer() | 127 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
139 | ->get('doctrine.orm.entity_manager') | ||
140 | ->getRepository('WallabagCoreBundle:Entry') | ||
141 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | ||
142 | |||
143 | $this->assertNotContains($this->tagName, $entry->getTags()); | 128 | $this->assertNotContains($this->tagName, $entry->getTags()); |
144 | 129 | ||
145 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 130 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 7bf4b43c..eec6939d 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | |||
@@ -2,11 +2,20 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle; | 3 | namespace Tests\Wallabag\CoreBundle; |
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Client; | ||
6 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 7 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6 | use Symfony\Component\BrowserKit\Cookie; | 8 | use Symfony\Component\BrowserKit\Cookie; |
9 | use Symfony\Component\Console\Input\ArrayInput; | ||
10 | use Symfony\Component\Console\Output\NullOutput; | ||
11 | use Wallabag\CoreBundle\Entity\Config; | ||
12 | use Wallabag\UserBundle\Entity\User; | ||
7 | 13 | ||
8 | abstract class WallabagCoreTestCase extends WebTestCase | 14 | abstract class WallabagCoreTestCase extends WebTestCase |
9 | { | 15 | { |
16 | /** | ||
17 | * @var Client|null | ||
18 | */ | ||
10 | private $client = null; | 19 | private $client = null; |
11 | 20 | ||
12 | public function getClient() | 21 | public function getClient() |
@@ -21,6 +30,44 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
21 | $this->client = static::createClient(); | 30 | $this->client = static::createClient(); |
22 | } | 31 | } |
23 | 32 | ||
33 | public function resetDatabase(Client $client) | ||
34 | { | ||
35 | $application = new Application($client->getKernel()); | ||
36 | $application->setAutoExit(false); | ||
37 | |||
38 | $application->run(new ArrayInput([ | ||
39 | 'command' => 'doctrine:schema:drop', | ||
40 | '--no-interaction' => true, | ||
41 | '--force' => true, | ||
42 | '--env' => 'test', | ||
43 | ]), new NullOutput()); | ||
44 | |||
45 | $application->run(new ArrayInput([ | ||
46 | 'command' => 'doctrine:schema:create', | ||
47 | '--no-interaction' => true, | ||
48 | '--env' => 'test', | ||
49 | ]), new NullOutput()); | ||
50 | |||
51 | $application->run(new ArrayInput([ | ||
52 | 'command' => 'doctrine:fixtures:load', | ||
53 | '--no-interaction' => true, | ||
54 | '--env' => 'test', | ||
55 | ]), new NullOutput()); | ||
56 | |||
57 | /* | ||
58 | * Recreate client to avoid error: | ||
59 | * | ||
60 | * [Doctrine\DBAL\ConnectionException] | ||
61 | * Transaction commit failed because the transaction has been marked for rollback only. | ||
62 | */ | ||
63 | $this->client = static::createClient(); | ||
64 | } | ||
65 | |||
66 | public function getEntityManager() | ||
67 | { | ||
68 | return $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
69 | } | ||
70 | |||
24 | /** | 71 | /** |
25 | * Login a user without making a HTTP request. | 72 | * Login a user without making a HTTP request. |
26 | * If we make a HTTP request we lose ability to mock service in the container. | 73 | * If we make a HTTP request we lose ability to mock service in the container. |
@@ -37,7 +84,7 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
37 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 84 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
38 | 85 | ||
39 | $user = $userManager->findUserBy(array('username' => $username)); | 86 | $user = $userManager->findUserBy(array('username' => $username)); |
40 | $loginManager->loginUser($firewallName, $user); | 87 | $loginManager->logInUser($firewallName, $user); |
41 | 88 | ||
42 | $session->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); | 89 | $session->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); |
43 | $session->save(); | 90 | $session->save(); |
@@ -65,23 +112,42 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
65 | } | 112 | } |
66 | 113 | ||
67 | /** | 114 | /** |
68 | * Return the user id of the logged in user. | 115 | * Return the user of the logged in user. |
69 | * You should be sure that you called `logInAs` before. | 116 | * You should be sure that you called `logInAs` before. |
70 | * | 117 | * |
71 | * @return int | 118 | * @return User |
72 | */ | 119 | */ |
73 | public function getLoggedInUserId() | 120 | public function getLoggedInUser() |
74 | { | 121 | { |
75 | $token = static::$kernel->getContainer()->get('security.token_storage')->getToken(); | 122 | $token = static::$kernel->getContainer()->get('security.token_storage')->getToken(); |
76 | 123 | ||
77 | if (null !== $token) { | 124 | if (null !== $token) { |
78 | return $token->getUser()->getId(); | 125 | return $token->getUser(); |
79 | } | 126 | } |
80 | 127 | ||
81 | throw new \RuntimeException('No logged in User.'); | 128 | throw new \RuntimeException('No logged in User.'); |
82 | } | 129 | } |
83 | 130 | ||
84 | /** | 131 | /** |
132 | * Return the user id of the logged in user. | ||
133 | * You should be sure that you called `logInAs` before. | ||
134 | * | ||
135 | * @return int | ||
136 | */ | ||
137 | public function getLoggedInUserId() | ||
138 | { | ||
139 | return $this->getLoggedInUser()->getId(); | ||
140 | } | ||
141 | |||
142 | public function useTheme($theme) | ||
143 | { | ||
144 | $config = $this->getEntityManager()->getRepository(Config::class)->findOneByUser($this->getLoggedInUser()); | ||
145 | $config->setTheme($theme); | ||
146 | $this->getEntityManager()->persist($config); | ||
147 | $this->getEntityManager()->flush(); | ||
148 | } | ||
149 | |||
150 | /** | ||
85 | * Check if Redis is installed. | 151 | * Check if Redis is installed. |
86 | * If not, mark test as skip. | 152 | * If not, mark test as skip. |
87 | */ | 153 | */ |
diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index 7043c345..f507563c 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php | |||
@@ -95,6 +95,7 @@ class ImportCommandTest extends WallabagCoreTestCase | |||
95 | 'username' => 1, | 95 | 'username' => 1, |
96 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', | 96 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', |
97 | '--useUserId' => true, | 97 | '--useUserId' => true, |
98 | '--importer' => 'v2', | ||
98 | ]); | 99 | ]); |
99 | } | 100 | } |
100 | } | 101 | } |
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 18a02522..24893259 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | |||
@@ -119,9 +119,10 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase | |||
119 | $this->getLoggedInUserId() | 119 | $this->getLoggedInUserId() |
120 | ); | 120 | ); |
121 | 121 | ||
122 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok'); | 122 | // empty because it wasn't re-imported |
123 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok'); | 123 | $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is empty'); |
124 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok'); | 124 | $this->assertEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is empty'); |
125 | $this->assertEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is empty'); | ||
125 | 126 | ||
126 | $tags = $content->getTags(); | 127 | $tags = $content->getTags(); |
127 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); | 128 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); |