diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle')
18 files changed, 1303 insertions, 457 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php new file mode 100644 index 00000000..e6e57f30 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php | |||
@@ -0,0 +1,108 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; | ||
8 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
10 | |||
11 | class CleanDuplicatesCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | public function testRunCleanDuplicates() | ||
14 | { | ||
15 | $application = new Application($this->getClient()->getKernel()); | ||
16 | $application->add(new CleanDuplicatesCommand()); | ||
17 | |||
18 | $command = $application->find('wallabag:clean-duplicates'); | ||
19 | |||
20 | $tester = new CommandTester($command); | ||
21 | $tester->execute([ | ||
22 | 'command' => $command->getName(), | ||
23 | ]); | ||
24 | |||
25 | $this->assertContains('Cleaning through 3 user accounts', $tester->getDisplay()); | ||
26 | $this->assertContains('Finished cleaning. 0 duplicates found in total', $tester->getDisplay()); | ||
27 | } | ||
28 | |||
29 | public function testRunCleanDuplicatesCommandWithBadUsername() | ||
30 | { | ||
31 | $application = new Application($this->getClient()->getKernel()); | ||
32 | $application->add(new CleanDuplicatesCommand()); | ||
33 | |||
34 | $command = $application->find('wallabag:clean-duplicates'); | ||
35 | |||
36 | $tester = new CommandTester($command); | ||
37 | $tester->execute([ | ||
38 | 'command' => $command->getName(), | ||
39 | 'username' => 'unknown', | ||
40 | ]); | ||
41 | |||
42 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
43 | } | ||
44 | |||
45 | public function testRunCleanDuplicatesCommandForUser() | ||
46 | { | ||
47 | $application = new Application($this->getClient()->getKernel()); | ||
48 | $application->add(new CleanDuplicatesCommand()); | ||
49 | |||
50 | $command = $application->find('wallabag:clean-duplicates'); | ||
51 | |||
52 | $tester = new CommandTester($command); | ||
53 | $tester->execute([ | ||
54 | 'command' => $command->getName(), | ||
55 | 'username' => 'admin', | ||
56 | ]); | ||
57 | |||
58 | $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay()); | ||
59 | } | ||
60 | |||
61 | public function testDuplicate() | ||
62 | { | ||
63 | $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html'; | ||
64 | $client = $this->getClient(); | ||
65 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
66 | |||
67 | $this->logInAs('admin'); | ||
68 | |||
69 | $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
70 | $this->assertCount(0, $nbEntries); | ||
71 | |||
72 | $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); | ||
73 | |||
74 | $entry1 = new Entry($user); | ||
75 | $entry1->setUrl($url); | ||
76 | |||
77 | $entry2 = new Entry($user); | ||
78 | $entry2->setUrl($url); | ||
79 | |||
80 | $em->persist($entry1); | ||
81 | $em->persist($entry2); | ||
82 | |||
83 | $em->flush(); | ||
84 | |||
85 | $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
86 | $this->assertCount(2, $nbEntries); | ||
87 | |||
88 | $application = new Application($this->getClient()->getKernel()); | ||
89 | $application->add(new CleanDuplicatesCommand()); | ||
90 | |||
91 | $command = $application->find('wallabag:clean-duplicates'); | ||
92 | |||
93 | $tester = new CommandTester($command); | ||
94 | $tester->execute([ | ||
95 | 'command' => $command->getName(), | ||
96 | 'username' => 'admin', | ||
97 | ]); | ||
98 | |||
99 | $this->assertContains('Cleaned 1 duplicates for user admin', $tester->getDisplay()); | ||
100 | |||
101 | $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
102 | $this->assertCount(1, $nbEntries); | ||
103 | |||
104 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); | ||
105 | $query->setParameter('url', $url); | ||
106 | $query->execute(); | ||
107 | } | ||
108 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 6798c5d7..2eebf39b 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php | |||
@@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |||
10 | class ExportCommandTest extends WallabagCoreTestCase | 10 | class ExportCommandTest extends WallabagCoreTestCase |
11 | { | 11 | { |
12 | /** | 12 | /** |
13 | * @expectedException Symfony\Component\Console\Exception\RuntimeException | 13 | * @expectedException \Symfony\Component\Console\Exception\RuntimeException |
14 | * @expectedExceptionMessage Not enough arguments (missing: "username") | 14 | * @expectedExceptionMessage Not enough arguments (missing: "username") |
15 | */ | 15 | */ |
16 | public function testExportCommandWithoutUsername() | 16 | public function testExportCommandWithoutUsername() |
@@ -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 | ||
@@ -70,7 +70,7 @@ class ExportCommandTest extends WallabagCoreTestCase | |||
70 | $tester->execute([ | 70 | $tester->execute([ |
71 | 'command' => $command->getName(), | 71 | 'command' => $command->getName(), |
72 | 'username' => 'admin', | 72 | 'username' => 'admin', |
73 | 'filepath' => 'specialexport.json' | 73 | 'filepath' => 'specialexport.json', |
74 | ]); | 74 | ]); |
75 | 75 | ||
76 | $this->assertFileExists('specialexport.json'); | 76 | $this->assertFileExists('specialexport.json'); |
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 1bfd41d5..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() |
@@ -67,18 +82,14 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
67 | 82 | ||
68 | $command = $application->find('wallabag:install'); | 83 | $command = $application->find('wallabag:install'); |
69 | 84 | ||
70 | // We mock the QuestionHelper | ||
71 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | ||
72 | ->disableOriginalConstructor() | ||
73 | ->getMock(); | ||
74 | $question->expects($this->any()) | ||
75 | ->method('ask') | ||
76 | ->will($this->returnValue('yes_'.uniqid('', true))); | ||
77 | |||
78 | // We override the standard helper with our mock | ||
79 | $command->getHelperSet()->set($question, 'question'); | ||
80 | |||
81 | $tester = new CommandTester($command); | 85 | $tester = new CommandTester($command); |
86 | $tester->setInputs([ | ||
87 | 'y', // dropping database | ||
88 | 'y', // create super admin | ||
89 | 'username_'.uniqid('', true), // username | ||
90 | 'password_'.uniqid('', true), // password | ||
91 | 'email_'.uniqid('', true).'@wallabag.it', // email | ||
92 | ]); | ||
82 | $tester->execute([ | 93 | $tester->execute([ |
83 | 'command' => $command->getName(), | 94 | 'command' => $command->getName(), |
84 | ]); | 95 | ]); |
@@ -87,6 +98,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
87 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 98 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
88 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 99 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
89 | $this->assertContains('Config setup.', $tester->getDisplay()); | 100 | $this->assertContains('Config setup.', $tester->getDisplay()); |
101 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
90 | } | 102 | } |
91 | 103 | ||
92 | public function testRunInstallCommandWithReset() | 104 | public function testRunInstallCommandWithReset() |
@@ -96,18 +108,13 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
96 | 108 | ||
97 | $command = $application->find('wallabag:install'); | 109 | $command = $application->find('wallabag:install'); |
98 | 110 | ||
99 | // We mock the QuestionHelper | ||
100 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | ||
101 | ->disableOriginalConstructor() | ||
102 | ->getMock(); | ||
103 | $question->expects($this->any()) | ||
104 | ->method('ask') | ||
105 | ->will($this->returnValue('yes_'.uniqid('', true))); | ||
106 | |||
107 | // We override the standard helper with our mock | ||
108 | $command->getHelperSet()->set($question, 'question'); | ||
109 | |||
110 | $tester = new CommandTester($command); | 111 | $tester = new CommandTester($command); |
112 | $tester->setInputs([ | ||
113 | 'y', // create super admin | ||
114 | 'username_'.uniqid('', true), // username | ||
115 | 'password_'.uniqid('', true), // password | ||
116 | 'email_'.uniqid('', true).'@wallabag.it', // email | ||
117 | ]); | ||
111 | $tester->execute([ | 118 | $tester->execute([ |
112 | 'command' => $command->getName(), | 119 | 'command' => $command->getName(), |
113 | '--reset' => true, | 120 | '--reset' => true, |
@@ -115,19 +122,20 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
115 | 122 | ||
116 | $this->assertContains('Checking system requirements.', $tester->getDisplay()); | 123 | $this->assertContains('Checking system requirements.', $tester->getDisplay()); |
117 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 124 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
118 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); | 125 | $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
119 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 126 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
120 | $this->assertContains('Config setup.', $tester->getDisplay()); | 127 | $this->assertContains('Config setup.', $tester->getDisplay()); |
128 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
121 | 129 | ||
122 | // we force to reset everything | 130 | // we force to reset everything |
123 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); | 131 | $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
124 | } | 132 | } |
125 | 133 | ||
126 | public function testRunInstallCommandWithDatabaseRemoved() | 134 | public function testRunInstallCommandWithDatabaseRemoved() |
127 | { | 135 | { |
128 | // 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, |
129 | // 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 |
130 | 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) { |
131 | $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); | 139 | $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); |
132 | } | 140 | } |
133 | 141 | ||
@@ -148,18 +156,13 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
148 | 156 | ||
149 | $command = $application->find('wallabag:install'); | 157 | $command = $application->find('wallabag:install'); |
150 | 158 | ||
151 | // We mock the QuestionHelper | ||
152 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | ||
153 | ->disableOriginalConstructor() | ||
154 | ->getMock(); | ||
155 | $question->expects($this->any()) | ||
156 | ->method('ask') | ||
157 | ->will($this->returnValue('yes_'.uniqid('', true))); | ||
158 | |||
159 | // We override the standard helper with our mock | ||
160 | $command->getHelperSet()->set($question, 'question'); | ||
161 | |||
162 | $tester = new CommandTester($command); | 159 | $tester = new CommandTester($command); |
160 | $tester->setInputs([ | ||
161 | 'y', // create super admin | ||
162 | 'username_'.uniqid('', true), // username | ||
163 | 'password_'.uniqid('', true), // password | ||
164 | 'email_'.uniqid('', true).'@wallabag.it', // email | ||
165 | ]); | ||
163 | $tester->execute([ | 166 | $tester->execute([ |
164 | 'command' => $command->getName(), | 167 | 'command' => $command->getName(), |
165 | ]); | 168 | ]); |
@@ -168,6 +171,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
168 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 171 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
169 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 172 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
170 | $this->assertContains('Config setup.', $tester->getDisplay()); | 173 | $this->assertContains('Config setup.', $tester->getDisplay()); |
174 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
171 | 175 | ||
172 | // the current database doesn't already exist | 176 | // the current database doesn't already exist |
173 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); | 177 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); |
@@ -180,23 +184,12 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
180 | 184 | ||
181 | $command = $application->find('wallabag:install'); | 185 | $command = $application->find('wallabag:install'); |
182 | 186 | ||
183 | // We mock the QuestionHelper | ||
184 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | ||
185 | ->disableOriginalConstructor() | ||
186 | ->getMock(); | ||
187 | |||
188 | $question->expects($this->exactly(3)) | ||
189 | ->method('ask') | ||
190 | ->will($this->onConsecutiveCalls( | ||
191 | false, // don't want to reset the entire database | ||
192 | true, // do want to reset the schema | ||
193 | false // don't want to create a new user | ||
194 | )); | ||
195 | |||
196 | // We override the standard helper with our mock | ||
197 | $command->getHelperSet()->set($question, 'question'); | ||
198 | |||
199 | $tester = new CommandTester($command); | 187 | $tester = new CommandTester($command); |
188 | $tester->setInputs([ | ||
189 | 'n', // don't want to reset the entire database | ||
190 | 'y', // do want to reset the schema | ||
191 | 'n', // don't want to create a new user | ||
192 | ]); | ||
200 | $tester->execute([ | 193 | $tester->execute([ |
201 | 'command' => $command->getName(), | 194 | 'command' => $command->getName(), |
202 | ]); | 195 | ]); |
@@ -205,8 +198,9 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
205 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 198 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
206 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 199 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
207 | $this->assertContains('Config setup.', $tester->getDisplay()); | 200 | $this->assertContains('Config setup.', $tester->getDisplay()); |
201 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
208 | 202 | ||
209 | $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); | 203 | $this->assertContains('Dropping schema and creating schema', $tester->getDisplay()); |
210 | } | 204 | } |
211 | 205 | ||
212 | public function testRunInstallCommandChooseNothing() | 206 | public function testRunInstallCommandChooseNothing() |
@@ -235,22 +229,11 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
235 | 229 | ||
236 | $command = $application->find('wallabag:install'); | 230 | $command = $application->find('wallabag:install'); |
237 | 231 | ||
238 | // We mock the QuestionHelper | ||
239 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | ||
240 | ->disableOriginalConstructor() | ||
241 | ->getMock(); | ||
242 | |||
243 | $question->expects($this->exactly(2)) | ||
244 | ->method('ask') | ||
245 | ->will($this->onConsecutiveCalls( | ||
246 | false, // don't want to reset the entire database | ||
247 | false // don't want to create a new user | ||
248 | )); | ||
249 | |||
250 | // We override the standard helper with our mock | ||
251 | $command->getHelperSet()->set($question, 'question'); | ||
252 | |||
253 | $tester = new CommandTester($command); | 232 | $tester = new CommandTester($command); |
233 | $tester->setInputs([ | ||
234 | 'n', // don't want to reset the entire database | ||
235 | 'n', // don't want to create a new user | ||
236 | ]); | ||
254 | $tester->execute([ | 237 | $tester->execute([ |
255 | 'command' => $command->getName(), | 238 | 'command' => $command->getName(), |
256 | ]); | 239 | ]); |
@@ -259,6 +242,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
259 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 242 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
260 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 243 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
261 | $this->assertContains('Config setup.', $tester->getDisplay()); | 244 | $this->assertContains('Config setup.', $tester->getDisplay()); |
245 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
262 | 246 | ||
263 | $this->assertContains('Creating schema', $tester->getDisplay()); | 247 | $this->assertContains('Creating schema', $tester->getDisplay()); |
264 | } | 248 | } |
@@ -270,26 +254,17 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
270 | 254 | ||
271 | $command = $application->find('wallabag:install'); | 255 | $command = $application->find('wallabag:install'); |
272 | 256 | ||
273 | // We mock the QuestionHelper | ||
274 | $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') | ||
275 | ->disableOriginalConstructor() | ||
276 | ->getMock(); | ||
277 | $question->expects($this->any()) | ||
278 | ->method('ask') | ||
279 | ->will($this->returnValue('yes_'.uniqid('', true))); | ||
280 | |||
281 | // We override the standard helper with our mock | ||
282 | $command->getHelperSet()->set($question, 'question'); | ||
283 | |||
284 | $tester = new CommandTester($command); | 257 | $tester = new CommandTester($command); |
285 | $tester->execute([ | 258 | $tester->execute([ |
286 | 'command' => $command->getName(), | 259 | 'command' => $command->getName(), |
287 | '--no-interaction' => true, | 260 | ], [ |
261 | 'interactive' => false, | ||
288 | ]); | 262 | ]); |
289 | 263 | ||
290 | $this->assertContains('Checking system requirements.', $tester->getDisplay()); | 264 | $this->assertContains('Checking system requirements.', $tester->getDisplay()); |
291 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 265 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
292 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 266 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
293 | $this->assertContains('Config setup.', $tester->getDisplay()); | 267 | $this->assertContains('Config setup.', $tester->getDisplay()); |
268 | $this->assertContains('Run migrations.', $tester->getDisplay()); | ||
294 | } | 269 | } |
295 | } | 270 | } |
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php new file mode 100644 index 00000000..c0a4acfa --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | |||
@@ -0,0 +1,93 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
8 | use Wallabag\CoreBundle\Command\ShowUserCommand; | ||
9 | use Wallabag\UserBundle\Entity\User; | ||
10 | |||
11 | class ShowUserCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | /** | ||
14 | * @expectedException \Symfony\Component\Console\Exception\RuntimeException | ||
15 | * @expectedExceptionMessage Not enough arguments | ||
16 | */ | ||
17 | public function testRunShowUserCommandWithoutUsername() | ||
18 | { | ||
19 | $application = new Application($this->getClient()->getKernel()); | ||
20 | $application->add(new ShowUserCommand()); | ||
21 | |||
22 | $command = $application->find('wallabag:user:show'); | ||
23 | |||
24 | $tester = new CommandTester($command); | ||
25 | $tester->execute([ | ||
26 | 'command' => $command->getName(), | ||
27 | ]); | ||
28 | } | ||
29 | |||
30 | public function testRunShowUserCommandWithBadUsername() | ||
31 | { | ||
32 | $application = new Application($this->getClient()->getKernel()); | ||
33 | $application->add(new ShowUserCommand()); | ||
34 | |||
35 | $command = $application->find('wallabag:user:show'); | ||
36 | |||
37 | $tester = new CommandTester($command); | ||
38 | $tester->execute([ | ||
39 | 'command' => $command->getName(), | ||
40 | 'username' => 'unknown', | ||
41 | ]); | ||
42 | |||
43 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
44 | } | ||
45 | |||
46 | public function testRunShowUserCommandForUser() | ||
47 | { | ||
48 | $application = new Application($this->getClient()->getKernel()); | ||
49 | $application->add(new ShowUserCommand()); | ||
50 | |||
51 | $command = $application->find('wallabag:user:show'); | ||
52 | |||
53 | $tester = new CommandTester($command); | ||
54 | $tester->execute([ | ||
55 | 'command' => $command->getName(), | ||
56 | 'username' => 'admin', | ||
57 | ]); | ||
58 | |||
59 | $this->assertContains('Username : admin', $tester->getDisplay()); | ||
60 | $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); | ||
61 | $this->assertContains('Display name : Big boss', $tester->getDisplay()); | ||
62 | $this->assertContains('2FA activated: no', $tester->getDisplay()); | ||
63 | } | ||
64 | |||
65 | public function testShowUser() | ||
66 | { | ||
67 | $client = $this->getClient(); | ||
68 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
69 | |||
70 | $this->logInAs('admin'); | ||
71 | |||
72 | /** @var User $user */ | ||
73 | $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); | ||
74 | |||
75 | $user->setName('Bug boss'); | ||
76 | $em->persist($user); | ||
77 | |||
78 | $em->flush(); | ||
79 | |||
80 | $application = new Application($this->getClient()->getKernel()); | ||
81 | $application->add(new ShowUserCommand()); | ||
82 | |||
83 | $command = $application->find('wallabag:user:show'); | ||
84 | |||
85 | $tester = new CommandTester($command); | ||
86 | $tester->execute([ | ||
87 | 'command' => $command->getName(), | ||
88 | 'username' => 'admin', | ||
89 | ]); | ||
90 | |||
91 | $this->assertContains('Display name : Bug boss', $tester->getDisplay()); | ||
92 | } | ||
93 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php index ec31708f..4cde3679 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php | |||
@@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |||
10 | class TagAllCommandTest extends WallabagCoreTestCase | 10 | class TagAllCommandTest extends WallabagCoreTestCase |
11 | { | 11 | { |
12 | /** | 12 | /** |
13 | * @expectedException Symfony\Component\Console\Exception\RuntimeException | 13 | * @expectedException \Symfony\Component\Console\Exception\RuntimeException |
14 | * @expectedExceptionMessage Not enough arguments (missing: "username") | 14 | * @expectedExceptionMessage Not enough arguments (missing: "username") |
15 | */ | 15 | */ |
16 | public function testRunTagAllCommandWithoutUsername() | 16 | public function testRunTagAllCommandWithoutUsername() |
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index beb0598a..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'); |
@@ -798,11 +808,87 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
798 | 808 | ||
799 | $entryReset = $em | 809 | $entryReset = $em |
800 | ->getRepository('WallabagCoreBundle:Entry') | 810 | ->getRepository('WallabagCoreBundle:Entry') |
801 | ->countAllEntriesByUsername($user->getId()); | 811 | ->countAllEntriesByUser($user->getId()); |
802 | 812 | ||
803 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | 813 | $this->assertEquals(0, $entryReset, 'Entries were reset'); |
804 | } | 814 | } |
805 | 815 | ||
816 | public function testResetArchivedEntries() | ||
817 | { | ||
818 | $this->logInAs('empty'); | ||
819 | $client = $this->getClient(); | ||
820 | |||
821 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
822 | |||
823 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
824 | |||
825 | $tag = new Tag(); | ||
826 | $tag->setLabel('super'); | ||
827 | $em->persist($tag); | ||
828 | |||
829 | $entry = new Entry($user); | ||
830 | $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
831 | $entry->setContent('Youhou'); | ||
832 | $entry->setTitle('Youhou'); | ||
833 | $entry->addTag($tag); | ||
834 | $em->persist($entry); | ||
835 | |||
836 | $annotation = new Annotation($user); | ||
837 | $annotation->setText('annotated'); | ||
838 | $annotation->setQuote('annotated'); | ||
839 | $annotation->setRanges([]); | ||
840 | $annotation->setEntry($entry); | ||
841 | $em->persist($annotation); | ||
842 | |||
843 | $tagArchived = new Tag(); | ||
844 | $tagArchived->setLabel('super'); | ||
845 | $em->persist($tagArchived); | ||
846 | |||
847 | $entryArchived = new Entry($user); | ||
848 | $entryArchived->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
849 | $entryArchived->setContent('Youhou'); | ||
850 | $entryArchived->setTitle('Youhou'); | ||
851 | $entryArchived->addTag($tagArchived); | ||
852 | $entryArchived->setArchived(true); | ||
853 | $em->persist($entryArchived); | ||
854 | |||
855 | $annotationArchived = new Annotation($user); | ||
856 | $annotationArchived->setText('annotated'); | ||
857 | $annotationArchived->setQuote('annotated'); | ||
858 | $annotationArchived->setRanges([]); | ||
859 | $annotationArchived->setEntry($entryArchived); | ||
860 | $em->persist($annotationArchived); | ||
861 | |||
862 | $em->flush(); | ||
863 | |||
864 | $crawler = $client->request('GET', '/config#set3'); | ||
865 | |||
866 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
867 | |||
868 | $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); | ||
869 | |||
870 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
871 | $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
872 | |||
873 | $entryReset = $em | ||
874 | ->getRepository('WallabagCoreBundle:Entry') | ||
875 | ->countAllEntriesByUser($user->getId()); | ||
876 | |||
877 | $this->assertEquals(1, $entryReset, 'Entries were reset'); | ||
878 | |||
879 | $tagReset = $em | ||
880 | ->getRepository('WallabagCoreBundle:Tag') | ||
881 | ->countAllTags($user->getId()); | ||
882 | |||
883 | $this->assertEquals(1, $tagReset, 'Tags were reset'); | ||
884 | |||
885 | $annotationsReset = $em | ||
886 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
887 | ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId()); | ||
888 | |||
889 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
890 | } | ||
891 | |||
806 | public function testResetEntriesCascade() | 892 | public function testResetEntriesCascade() |
807 | { | 893 | { |
808 | $this->logInAs('empty'); | 894 | $this->logInAs('empty'); |
@@ -843,7 +929,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
843 | 929 | ||
844 | $entryReset = $em | 930 | $entryReset = $em |
845 | ->getRepository('WallabagCoreBundle:Entry') | 931 | ->getRepository('WallabagCoreBundle:Entry') |
846 | ->countAllEntriesByUsername($user->getId()); | 932 | ->countAllEntriesByUser($user->getId()); |
847 | 933 | ||
848 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | 934 | $this->assertEquals(0, $entryReset, 'Entries were reset'); |
849 | 935 | ||
@@ -863,6 +949,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
863 | public function testSwitchViewMode() | 949 | public function testSwitchViewMode() |
864 | { | 950 | { |
865 | $this->logInAs('admin'); | 951 | $this->logInAs('admin'); |
952 | $this->useTheme('baggy'); | ||
866 | $client = $this->getClient(); | 953 | $client = $this->getClient(); |
867 | 954 | ||
868 | $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 7db4cf1f..8f5c372d 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -8,8 +8,24 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
8 | 8 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | 9 | class EntryControllerTest extends WallabagCoreTestCase |
10 | { | 10 | { |
11 | public $downloadImagesEnabled = false; | ||
11 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; | 12 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
12 | 13 | ||
14 | /** | ||
15 | * @after | ||
16 | * | ||
17 | * Ensure download_images_enabled is disabled after each script | ||
18 | */ | ||
19 | public function tearDownImagesEnabled() | ||
20 | { | ||
21 | if ($this->downloadImagesEnabled) { | ||
22 | $client = static::createClient(); | ||
23 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | ||
24 | |||
25 | $this->downloadImagesEnabled = false; | ||
26 | } | ||
27 | } | ||
28 | |||
13 | public function testLogin() | 29 | public function testLogin() |
14 | { | 30 | { |
15 | $client = $this->getClient(); | 31 | $client = $this->getClient(); |
@@ -55,6 +71,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
55 | public function testGetNew() | 71 | public function testGetNew() |
56 | { | 72 | { |
57 | $this->logInAs('admin'); | 73 | $this->logInAs('admin'); |
74 | $this->useTheme('baggy'); | ||
58 | $client = $this->getClient(); | 75 | $client = $this->getClient(); |
59 | 76 | ||
60 | $crawler = $client->request('GET', '/new'); | 77 | $crawler = $client->request('GET', '/new'); |
@@ -68,6 +85,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
68 | public function testPostNewViaBookmarklet() | 85 | public function testPostNewViaBookmarklet() |
69 | { | 86 | { |
70 | $this->logInAs('admin'); | 87 | $this->logInAs('admin'); |
88 | $this->useTheme('baggy'); | ||
71 | $client = $this->getClient(); | 89 | $client = $this->getClient(); |
72 | 90 | ||
73 | $crawler = $client->request('GET', '/'); | 91 | $crawler = $client->request('GET', '/'); |
@@ -135,14 +153,58 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
135 | ->getRepository('WallabagCoreBundle:Entry') | 153 | ->getRepository('WallabagCoreBundle:Entry') |
136 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 154 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
137 | 155 | ||
156 | $author = $content->getPublishedBy(); | ||
157 | |||
138 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 158 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
139 | $this->assertEquals($this->url, $content->getUrl()); | 159 | $this->assertEquals($this->url, $content->getUrl()); |
140 | $this->assertContains('Google', $content->getTitle()); | 160 | $this->assertContains('Google', $content->getTitle()); |
161 | $this->assertEquals('fr', $content->getLanguage()); | ||
162 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
163 | $this->assertEquals('Morgane Tual', $author[0]); | ||
164 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); | ||
165 | } | ||
166 | |||
167 | public function testPostWithMultipleAuthors() | ||
168 | { | ||
169 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | ||
170 | $this->logInAs('admin'); | ||
171 | $client = $this->getClient(); | ||
172 | |||
173 | $crawler = $client->request('GET', '/new'); | ||
174 | |||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
176 | |||
177 | $form = $crawler->filter('form[name=entry]')->form(); | ||
178 | |||
179 | $data = [ | ||
180 | 'entry[url]' => $url, | ||
181 | ]; | ||
182 | |||
183 | $client->submit($form, $data); | ||
184 | |||
185 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
186 | |||
187 | $content = $client->getContainer() | ||
188 | ->get('doctrine.orm.entity_manager') | ||
189 | ->getRepository('WallabagCoreBundle:Entry') | ||
190 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
191 | |||
192 | $authors = $content->getPublishedBy(); | ||
193 | $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
194 | $this->assertEquals('fr', $content->getLanguage()); | ||
195 | $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | ||
196 | $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); | ||
141 | } | 197 | } |
142 | 198 | ||
143 | public function testPostNewOkUrlExist() | 199 | public function testPostNewOkUrlExist() |
144 | { | 200 | { |
145 | $this->logInAs('admin'); | 201 | $this->logInAs('admin'); |
202 | |||
203 | $entry = new Entry($this->getLoggedInUser()); | ||
204 | $entry->setUrl($this->url); | ||
205 | $this->getEntityManager()->persist($entry); | ||
206 | $this->getEntityManager()->flush(); | ||
207 | |||
146 | $client = $this->getClient(); | 208 | $client = $this->getClient(); |
147 | 209 | ||
148 | $crawler = $client->request('GET', '/new'); | 210 | $crawler = $client->request('GET', '/new'); |
@@ -194,15 +256,6 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
194 | 256 | ||
195 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 257 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
196 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | 258 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
197 | |||
198 | $em = $client->getContainer() | ||
199 | ->get('doctrine.orm.entity_manager'); | ||
200 | $entry = $em | ||
201 | ->getRepository('WallabagCoreBundle:Entry') | ||
202 | ->findOneByUrl(urldecode($url)); | ||
203 | |||
204 | $em->remove($entry); | ||
205 | $em->flush(); | ||
206 | } | 259 | } |
207 | 260 | ||
208 | /** | 261 | /** |
@@ -235,8 +288,9 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
235 | ->findOneByUrl($url); | 288 | ->findOneByUrl($url); |
236 | $tags = $entry->getTags(); | 289 | $tags = $entry->getTags(); |
237 | 290 | ||
238 | $this->assertCount(1, $tags); | 291 | $this->assertCount(2, $tags); |
239 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 292 | $this->assertContains('wallabag', $tags); |
293 | $this->assertEquals('en', $entry->getLanguage()); | ||
240 | 294 | ||
241 | $em->remove($entry); | 295 | $em->remove($entry); |
242 | $em->flush(); | 296 | $em->flush(); |
@@ -264,8 +318,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
264 | 318 | ||
265 | $tags = $entry->getTags(); | 319 | $tags = $entry->getTags(); |
266 | 320 | ||
267 | $this->assertCount(1, $tags); | 321 | $this->assertCount(2, $tags); |
268 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 322 | $this->assertContains('wallabag', $tags); |
269 | 323 | ||
270 | $em->remove($entry); | 324 | $em->remove($entry); |
271 | $em->flush(); | 325 | $em->flush(); |
@@ -312,29 +366,26 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
312 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | 366 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); |
313 | } | 367 | } |
314 | 368 | ||
315 | /** | ||
316 | * @depends testPostNewOk | ||
317 | */ | ||
318 | public function testView() | 369 | public function testView() |
319 | { | 370 | { |
320 | $this->logInAs('admin'); | 371 | $this->logInAs('admin'); |
321 | $client = $this->getClient(); | 372 | $client = $this->getClient(); |
322 | 373 | ||
323 | $content = $client->getContainer() | 374 | $entry = new Entry($this->getLoggedInUser()); |
324 | ->get('doctrine.orm.entity_manager') | 375 | $entry->setUrl('http://example.com/foo'); |
325 | ->getRepository('WallabagCoreBundle:Entry') | 376 | $entry->setTitle('title foo'); |
326 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 377 | $entry->setContent('foo bar baz'); |
378 | $this->getEntityManager()->persist($entry); | ||
379 | $this->getEntityManager()->flush(); | ||
327 | 380 | ||
328 | $crawler = $client->request('GET', '/view/'.$content->getId()); | 381 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
329 | 382 | ||
330 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 383 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
331 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 384 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
332 | $this->assertContains($content->getTitle(), $body[0]); | 385 | $this->assertContains($entry->getTitle(), $body[0]); |
333 | } | 386 | } |
334 | 387 | ||
335 | /** | 388 | /** |
336 | * @depends testPostNewOk | ||
337 | * | ||
338 | * This test will require an internet connection. | 389 | * This test will require an internet connection. |
339 | */ | 390 | */ |
340 | public function testReload() | 391 | public function testReload() |
@@ -342,63 +393,45 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
342 | $this->logInAs('admin'); | 393 | $this->logInAs('admin'); |
343 | $client = $this->getClient(); | 394 | $client = $this->getClient(); |
344 | 395 | ||
345 | $em = $client->getContainer() | 396 | $entry = new Entry($this->getLoggedInUser()); |
346 | ->get('doctrine.orm.entity_manager'); | 397 | $entry->setUrl($this->url); |
398 | $entry->setTitle('title foo'); | ||
399 | $entry->setContent(''); | ||
400 | $this->getEntityManager()->persist($entry); | ||
401 | $this->getEntityManager()->flush(); | ||
402 | $this->getEntityManager()->clear(); | ||
347 | 403 | ||
348 | $content = $em | 404 | $client->request('GET', '/reload/'.$entry->getId()); |
349 | ->getRepository('WallabagCoreBundle:Entry') | ||
350 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
351 | |||
352 | // empty content | ||
353 | $content->setContent(''); | ||
354 | $em->persist($content); | ||
355 | $em->flush(); | ||
356 | |||
357 | $client->request('GET', '/reload/'.$content->getId()); | ||
358 | 405 | ||
359 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 406 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
360 | 407 | ||
361 | $content = $em | 408 | $entry = $this->getEntityManager() |
362 | ->getRepository('WallabagCoreBundle:Entry') | 409 | ->getRepository('WallabagCoreBundle:Entry') |
363 | ->find($content->getId()); | 410 | ->find($entry->getId()); |
364 | 411 | ||
365 | $this->assertNotEmpty($content->getContent()); | 412 | $this->assertNotEmpty($entry->getContent()); |
366 | } | 413 | } |
367 | 414 | ||
368 | /** | ||
369 | * @depends testPostNewOk | ||
370 | */ | ||
371 | public function testReloadWithFetchingFailed() | 415 | public function testReloadWithFetchingFailed() |
372 | { | 416 | { |
373 | $this->logInAs('admin'); | 417 | $this->logInAs('admin'); |
374 | $client = $this->getClient(); | 418 | $client = $this->getClient(); |
375 | 419 | ||
376 | $em = $client->getContainer() | 420 | $entry = new Entry($this->getLoggedInUser()); |
377 | ->get('doctrine.orm.entity_manager'); | 421 | $entry->setUrl('http://0.0.0.0/failed.html'); |
378 | 422 | $this->getEntityManager()->persist($entry); | |
379 | $content = $em | 423 | $this->getEntityManager()->flush(); |
380 | ->getRepository('WallabagCoreBundle:Entry') | ||
381 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
382 | 424 | ||
383 | // put a known failed url | 425 | $client->request('GET', '/reload/'.$entry->getId()); |
384 | $content->setUrl('http://0.0.0.0/failed.html'); | ||
385 | $em->persist($content); | ||
386 | $em->flush(); | ||
387 | |||
388 | $client->request('GET', '/reload/'.$content->getId()); | ||
389 | 426 | ||
390 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 427 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
391 | 428 | ||
392 | // force EntityManager to clear previous entity | 429 | // force EntityManager to clear previous entity |
393 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | 430 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 |
394 | $em->clear(); | 431 | $this->getEntityManager()->clear(); |
395 | $newContent = $em | 432 | $newContent = $this->getEntityManager() |
396 | ->getRepository('WallabagCoreBundle:Entry') | 433 | ->getRepository('WallabagCoreBundle:Entry') |
397 | ->find($content->getId()); | 434 | ->find($entry->getId()); |
398 | |||
399 | $newContent->setUrl($this->url); | ||
400 | $em->persist($newContent); | ||
401 | $em->flush(); | ||
402 | 435 | ||
403 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | 436 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); |
404 | } | 437 | } |
@@ -408,12 +441,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
408 | $this->logInAs('admin'); | 441 | $this->logInAs('admin'); |
409 | $client = $this->getClient(); | 442 | $client = $this->getClient(); |
410 | 443 | ||
411 | $content = $client->getContainer() | 444 | $entry = new Entry($this->getLoggedInUser()); |
412 | ->get('doctrine.orm.entity_manager') | 445 | $entry->setUrl($this->url); |
413 | ->getRepository('WallabagCoreBundle:Entry') | 446 | $this->getEntityManager()->persist($entry); |
414 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 447 | $this->getEntityManager()->flush(); |
415 | 448 | ||
416 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 449 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
417 | 450 | ||
418 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 451 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
419 | 452 | ||
@@ -426,12 +459,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
426 | $this->logInAs('admin'); | 459 | $this->logInAs('admin'); |
427 | $client = $this->getClient(); | 460 | $client = $this->getClient(); |
428 | 461 | ||
429 | $content = $client->getContainer() | 462 | $entry = new Entry($this->getLoggedInUser()); |
430 | ->get('doctrine.orm.entity_manager') | 463 | $entry->setUrl($this->url); |
431 | ->getRepository('WallabagCoreBundle:Entry') | 464 | $this->getEntityManager()->persist($entry); |
432 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 465 | $this->getEntityManager()->flush(); |
433 | 466 | ||
434 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 467 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
435 | 468 | ||
436 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 469 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
437 | 470 | ||
@@ -456,19 +489,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
456 | $this->logInAs('admin'); | 489 | $this->logInAs('admin'); |
457 | $client = $this->getClient(); | 490 | $client = $this->getClient(); |
458 | 491 | ||
459 | $content = $client->getContainer() | 492 | $entry = new Entry($this->getLoggedInUser()); |
460 | ->get('doctrine.orm.entity_manager') | 493 | $entry->setUrl($this->url); |
461 | ->getRepository('WallabagCoreBundle:Entry') | 494 | $this->getEntityManager()->persist($entry); |
462 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 495 | $this->getEntityManager()->flush(); |
496 | $this->getEntityManager()->clear(); | ||
463 | 497 | ||
464 | $client->request('GET', '/archive/'.$content->getId()); | 498 | $client->request('GET', '/archive/'.$entry->getId()); |
465 | 499 | ||
466 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 500 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
467 | 501 | ||
468 | $res = $client->getContainer() | 502 | $res = $client->getContainer() |
469 | ->get('doctrine.orm.entity_manager') | 503 | ->get('doctrine.orm.entity_manager') |
470 | ->getRepository('WallabagCoreBundle:Entry') | 504 | ->getRepository('WallabagCoreBundle:Entry') |
471 | ->find($content->getId()); | 505 | ->find($entry->getId()); |
472 | 506 | ||
473 | $this->assertEquals($res->isArchived(), true); | 507 | $this->assertEquals($res->isArchived(), true); |
474 | } | 508 | } |
@@ -478,19 +512,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
478 | $this->logInAs('admin'); | 512 | $this->logInAs('admin'); |
479 | $client = $this->getClient(); | 513 | $client = $this->getClient(); |
480 | 514 | ||
481 | $content = $client->getContainer() | 515 | $entry = new Entry($this->getLoggedInUser()); |
482 | ->get('doctrine.orm.entity_manager') | 516 | $entry->setUrl($this->url); |
483 | ->getRepository('WallabagCoreBundle:Entry') | 517 | $this->getEntityManager()->persist($entry); |
484 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 518 | $this->getEntityManager()->flush(); |
519 | $this->getEntityManager()->clear(); | ||
485 | 520 | ||
486 | $client->request('GET', '/star/'.$content->getId()); | 521 | $client->request('GET', '/star/'.$entry->getId()); |
487 | 522 | ||
488 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 523 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
489 | 524 | ||
490 | $res = $client->getContainer() | 525 | $res = $client->getContainer() |
491 | ->get('doctrine.orm.entity_manager') | 526 | ->get('doctrine.orm.entity_manager') |
492 | ->getRepository('WallabagCoreBundle:Entry') | 527 | ->getRepository('WallabagCoreBundle:Entry') |
493 | ->findOneById($content->getId()); | 528 | ->findOneById($entry->getId()); |
494 | 529 | ||
495 | $this->assertEquals($res->isStarred(), true); | 530 | $this->assertEquals($res->isStarred(), true); |
496 | } | 531 | } |
@@ -500,16 +535,16 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
500 | $this->logInAs('admin'); | 535 | $this->logInAs('admin'); |
501 | $client = $this->getClient(); | 536 | $client = $this->getClient(); |
502 | 537 | ||
503 | $content = $client->getContainer() | 538 | $entry = new Entry($this->getLoggedInUser()); |
504 | ->get('doctrine.orm.entity_manager') | 539 | $entry->setUrl($this->url); |
505 | ->getRepository('WallabagCoreBundle:Entry') | 540 | $this->getEntityManager()->persist($entry); |
506 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 541 | $this->getEntityManager()->flush(); |
507 | 542 | ||
508 | $client->request('GET', '/delete/'.$content->getId()); | 543 | $client->request('GET', '/delete/'.$entry->getId()); |
509 | 544 | ||
510 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 545 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
511 | 546 | ||
512 | $client->request('GET', '/delete/'.$content->getId()); | 547 | $client->request('GET', '/delete/'.$entry->getId()); |
513 | 548 | ||
514 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 549 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
515 | } | 550 | } |
@@ -575,7 +610,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
575 | public function testFilterOnReadingTime() | 610 | public function testFilterOnReadingTime() |
576 | { | 611 | { |
577 | $this->logInAs('admin'); | 612 | $this->logInAs('admin'); |
613 | $this->useTheme('baggy'); | ||
578 | $client = $this->getClient(); | 614 | $client = $this->getClient(); |
615 | $entry = new Entry($this->getLoggedInUser()); | ||
616 | $entry->setUrl($this->url); | ||
617 | $entry->setReadingTime(22); | ||
618 | $this->getEntityManager()->persist($entry); | ||
619 | $this->getEntityManager()->flush(); | ||
579 | 620 | ||
580 | $crawler = $client->request('GET', '/unread/list'); | 621 | $crawler = $client->request('GET', '/unread/list'); |
581 | 622 | ||
@@ -614,9 +655,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
614 | public function testFilterOnReadingTimeOnlyUpper() | 655 | public function testFilterOnReadingTimeOnlyUpper() |
615 | { | 656 | { |
616 | $this->logInAs('admin'); | 657 | $this->logInAs('admin'); |
658 | $this->useTheme('baggy'); | ||
617 | $client = $this->getClient(); | 659 | $client = $this->getClient(); |
618 | 660 | ||
619 | $crawler = $client->request('GET', '/unread/list'); | 661 | $crawler = $client->request('GET', '/all/list'); |
662 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
663 | |||
664 | $entry = new Entry($this->getLoggedInUser()); | ||
665 | $entry->setUrl($this->url); | ||
666 | $entry->setReadingTime(23); | ||
667 | $this->getEntityManager()->persist($entry); | ||
668 | $this->getEntityManager()->flush(); | ||
669 | |||
670 | $crawler = $client->request('GET', '/all/list'); | ||
671 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | ||
620 | 672 | ||
621 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 673 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
622 | 674 | ||
@@ -626,12 +678,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
626 | 678 | ||
627 | $crawler = $client->submit($form, $data); | 679 | $crawler = $client->submit($form, $data); |
628 | 680 | ||
629 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 681 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
630 | } | 682 | } |
631 | 683 | ||
632 | public function testFilterOnReadingTimeOnlyLower() | 684 | public function testFilterOnReadingTimeOnlyLower() |
633 | { | 685 | { |
634 | $this->logInAs('admin'); | 686 | $this->logInAs('admin'); |
687 | $this->useTheme('baggy'); | ||
635 | $client = $this->getClient(); | 688 | $client = $this->getClient(); |
636 | 689 | ||
637 | $crawler = $client->request('GET', '/unread/list'); | 690 | $crawler = $client->request('GET', '/unread/list'); |
@@ -644,12 +697,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
644 | 697 | ||
645 | $crawler = $client->submit($form, $data); | 698 | $crawler = $client->submit($form, $data); |
646 | 699 | ||
647 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 700 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
701 | |||
702 | $entry = new Entry($this->getLoggedInUser()); | ||
703 | $entry->setUrl($this->url); | ||
704 | $entry->setReadingTime(23); | ||
705 | $this->getEntityManager()->persist($entry); | ||
706 | $this->getEntityManager()->flush(); | ||
707 | |||
708 | $crawler = $client->submit($form, $data); | ||
709 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | ||
648 | } | 710 | } |
649 | 711 | ||
650 | public function testFilterOnUnreadStatus() | 712 | public function testFilterOnUnreadStatus() |
651 | { | 713 | { |
652 | $this->logInAs('admin'); | 714 | $this->logInAs('admin'); |
715 | $this->useTheme('baggy'); | ||
653 | $client = $this->getClient(); | 716 | $client = $this->getClient(); |
654 | 717 | ||
655 | $crawler = $client->request('GET', '/all/list'); | 718 | $crawler = $client->request('GET', '/all/list'); |
@@ -663,11 +726,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
663 | $crawler = $client->submit($form, $data); | 726 | $crawler = $client->submit($form, $data); |
664 | 727 | ||
665 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 728 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
729 | |||
730 | $entry = new Entry($this->getLoggedInUser()); | ||
731 | $entry->setUrl($this->url); | ||
732 | $entry->setArchived(false); | ||
733 | $this->getEntityManager()->persist($entry); | ||
734 | $this->getEntityManager()->flush(); | ||
735 | |||
736 | $crawler = $client->submit($form, $data); | ||
737 | |||
738 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
666 | } | 739 | } |
667 | 740 | ||
668 | public function testFilterOnCreationDate() | 741 | public function testFilterOnCreationDate() |
669 | { | 742 | { |
670 | $this->logInAs('admin'); | 743 | $this->logInAs('admin'); |
744 | $this->useTheme('baggy'); | ||
671 | $client = $this->getClient(); | 745 | $client = $this->getClient(); |
672 | 746 | ||
673 | $crawler = $client->request('GET', '/unread/list'); | 747 | $crawler = $client->request('GET', '/unread/list'); |
@@ -734,6 +808,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
734 | public function testFilterOnDomainName() | 808 | public function testFilterOnDomainName() |
735 | { | 809 | { |
736 | $this->logInAs('admin'); | 810 | $this->logInAs('admin'); |
811 | $this->useTheme('baggy'); | ||
737 | $client = $this->getClient(); | 812 | $client = $this->getClient(); |
738 | 813 | ||
739 | $crawler = $client->request('GET', '/unread/list'); | 814 | $crawler = $client->request('GET', '/unread/list'); |
@@ -766,6 +841,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
766 | public function testFilterOnStatus() | 841 | public function testFilterOnStatus() |
767 | { | 842 | { |
768 | $this->logInAs('admin'); | 843 | $this->logInAs('admin'); |
844 | $this->useTheme('baggy'); | ||
769 | $client = $this->getClient(); | 845 | $client = $this->getClient(); |
770 | 846 | ||
771 | $crawler = $client->request('GET', '/unread/list'); | 847 | $crawler = $client->request('GET', '/unread/list'); |
@@ -787,6 +863,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
787 | public function testPreviewPictureFilter() | 863 | public function testPreviewPictureFilter() |
788 | { | 864 | { |
789 | $this->logInAs('admin'); | 865 | $this->logInAs('admin'); |
866 | $this->useTheme('baggy'); | ||
790 | $client = $this->getClient(); | 867 | $client = $this->getClient(); |
791 | 868 | ||
792 | $crawler = $client->request('GET', '/unread/list'); | 869 | $crawler = $client->request('GET', '/unread/list'); |
@@ -800,8 +877,15 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
800 | public function testFilterOnLanguage() | 877 | public function testFilterOnLanguage() |
801 | { | 878 | { |
802 | $this->logInAs('admin'); | 879 | $this->logInAs('admin'); |
880 | $this->useTheme('baggy'); | ||
803 | $client = $this->getClient(); | 881 | $client = $this->getClient(); |
804 | 882 | ||
883 | $entry = new Entry($this->getLoggedInUser()); | ||
884 | $entry->setUrl($this->url); | ||
885 | $entry->setLanguage('fr'); | ||
886 | $this->getEntityManager()->persist($entry); | ||
887 | $this->getEntityManager()->flush(); | ||
888 | |||
805 | $crawler = $client->request('GET', '/unread/list'); | 889 | $crawler = $client->request('GET', '/unread/list'); |
806 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 890 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
807 | $data = [ | 891 | $data = [ |
@@ -809,7 +893,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
809 | ]; | 893 | ]; |
810 | 894 | ||
811 | $crawler = $client->submit($form, $data); | 895 | $crawler = $client->submit($form, $data); |
812 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 896 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
813 | 897 | ||
814 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 898 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
815 | $data = [ | 899 | $data = [ |
@@ -825,10 +909,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
825 | $this->logInAs('admin'); | 909 | $this->logInAs('admin'); |
826 | $client = $this->getClient(); | 910 | $client = $this->getClient(); |
827 | 911 | ||
828 | $content = $client->getContainer() | 912 | // sharing is enabled |
829 | ->get('doctrine.orm.entity_manager') | 913 | $client->getContainer()->get('craue_config')->set('share_public', 1); |
830 | ->getRepository('WallabagCoreBundle:Entry') | 914 | |
831 | ->findOneByUser($this->getLoggedInUserId()); | 915 | $content = new Entry($this->getLoggedInUser()); |
916 | $content->setUrl($this->url); | ||
917 | $this->getEntityManager()->persist($content); | ||
918 | $this->getEntityManager()->flush(); | ||
919 | $this->getEntityManager()->clear(); | ||
832 | 920 | ||
833 | // no uid | 921 | // no uid |
834 | $client->request('GET', '/share/'.$content->getUid()); | 922 | $client->request('GET', '/share/'.$content->getUid()); |
@@ -869,6 +957,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
869 | 957 | ||
870 | public function testNewEntryWithDownloadImagesEnabled() | 958 | public function testNewEntryWithDownloadImagesEnabled() |
871 | { | 959 | { |
960 | $this->downloadImagesEnabled = true; | ||
872 | $this->logInAs('admin'); | 961 | $this->logInAs('admin'); |
873 | $client = $this->getClient(); | 962 | $client = $this->getClient(); |
874 | 963 | ||
@@ -899,7 +988,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
899 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | 988 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); |
900 | $this->assertEquals($url, $entry->getUrl()); | 989 | $this->assertEquals($url, $entry->getUrl()); |
901 | $this->assertContains('Perpignan', $entry->getTitle()); | 990 | $this->assertContains('Perpignan', $entry->getTitle()); |
902 | $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); | 991 | // instead of checking for the filename (which might change) check that the image is now local |
992 | $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); | ||
903 | 993 | ||
904 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 994 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
905 | } | 995 | } |
@@ -909,12 +999,27 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
909 | */ | 999 | */ |
910 | public function testRemoveEntryWithDownloadImagesEnabled() | 1000 | public function testRemoveEntryWithDownloadImagesEnabled() |
911 | { | 1001 | { |
1002 | $this->downloadImagesEnabled = true; | ||
912 | $this->logInAs('admin'); | 1003 | $this->logInAs('admin'); |
913 | $client = $this->getClient(); | 1004 | $client = $this->getClient(); |
914 | 1005 | ||
915 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | 1006 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; |
916 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | 1007 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
917 | 1008 | ||
1009 | $crawler = $client->request('GET', '/new'); | ||
1010 | |||
1011 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1012 | |||
1013 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1014 | |||
1015 | $data = [ | ||
1016 | 'entry[url]' => $url, | ||
1017 | ]; | ||
1018 | |||
1019 | $client->submit($form, $data); | ||
1020 | |||
1021 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1022 | |||
918 | $content = $client->getContainer() | 1023 | $content = $client->getContainer() |
919 | ->get('doctrine.orm.entity_manager') | 1024 | ->get('doctrine.orm.entity_manager') |
920 | ->getRepository('WallabagCoreBundle:Entry') | 1025 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -932,28 +1037,19 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
932 | $this->logInAs('empty'); | 1037 | $this->logInAs('empty'); |
933 | $client = $this->getClient(); | 1038 | $client = $this->getClient(); |
934 | 1039 | ||
935 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
936 | $user = $em | ||
937 | ->getRepository('WallabagUserBundle:User') | ||
938 | ->find($this->getLoggedInUserId()); | ||
939 | |||
940 | if (!$user) { | ||
941 | $this->markTestSkipped('No user found in db.'); | ||
942 | } | ||
943 | |||
944 | // Redirect to homepage | 1040 | // Redirect to homepage |
945 | $config = $user->getConfig(); | 1041 | $config = $this->getLoggedInUser()->getConfig(); |
946 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | 1042 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
947 | $em->persist($config); | 1043 | $this->getEntityManager()->persist($config); |
948 | $em->flush(); | ||
949 | 1044 | ||
950 | $content = $client->getContainer() | 1045 | $entry = new Entry($this->getLoggedInUser()); |
951 | ->get('doctrine.orm.entity_manager') | 1046 | $entry->setUrl($this->url); |
952 | ->getRepository('WallabagCoreBundle:Entry') | 1047 | $this->getEntityManager()->persist($entry); |
953 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
954 | 1048 | ||
955 | $client->request('GET', '/view/'.$content->getId()); | 1049 | $this->getEntityManager()->flush(); |
956 | $client->request('GET', '/archive/'.$content->getId()); | 1050 | |
1051 | $client->request('GET', '/view/'.$entry->getId()); | ||
1052 | $client->request('GET', '/archive/'.$entry->getId()); | ||
957 | 1053 | ||
958 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1054 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
959 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | 1055 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); |
@@ -964,46 +1060,36 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
964 | $this->logInAs('empty'); | 1060 | $this->logInAs('empty'); |
965 | $client = $this->getClient(); | 1061 | $client = $this->getClient(); |
966 | 1062 | ||
967 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
968 | $user = $em | ||
969 | ->getRepository('WallabagUserBundle:User') | ||
970 | ->find($this->getLoggedInUserId()); | ||
971 | |||
972 | if (!$user) { | ||
973 | $this->markTestSkipped('No user found in db.'); | ||
974 | } | ||
975 | |||
976 | // Redirect to current page | 1063 | // Redirect to current page |
977 | $config = $user->getConfig(); | 1064 | $config = $this->getLoggedInUser()->getConfig(); |
978 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | 1065 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
979 | $em->persist($config); | 1066 | $this->getEntityManager()->persist($config); |
980 | $em->flush(); | ||
981 | 1067 | ||
982 | $content = $client->getContainer() | 1068 | $entry = new Entry($this->getLoggedInUser()); |
983 | ->get('doctrine.orm.entity_manager') | 1069 | $entry->setUrl($this->url); |
984 | ->getRepository('WallabagCoreBundle:Entry') | 1070 | $this->getEntityManager()->persist($entry); |
985 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
986 | 1071 | ||
987 | $client->request('GET', '/view/'.$content->getId()); | 1072 | $this->getEntityManager()->flush(); |
988 | $client->request('GET', '/archive/'.$content->getId()); | 1073 | |
1074 | $client->request('GET', '/view/'.$entry->getId()); | ||
1075 | $client->request('GET', '/archive/'.$entry->getId()); | ||
989 | 1076 | ||
990 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1077 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
991 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | 1078 | $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); |
992 | } | 1079 | } |
993 | 1080 | ||
994 | public function testFilterOnHttpStatus() | 1081 | public function testFilterOnHttpStatus() |
995 | { | 1082 | { |
996 | $this->logInAs('admin'); | 1083 | $this->logInAs('admin'); |
1084 | $this->useTheme('baggy'); | ||
997 | $client = $this->getClient(); | 1085 | $client = $this->getClient(); |
998 | 1086 | ||
999 | $crawler = $client->request('GET', '/new'); | 1087 | $entry = new Entry($this->getLoggedInUser()); |
1000 | $form = $crawler->filter('form[name=entry]')->form(); | 1088 | $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); |
1001 | 1089 | $entry->setHttpStatus(404); | |
1002 | $data = [ | 1090 | $this->getEntityManager()->persist($entry); |
1003 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | ||
1004 | ]; | ||
1005 | 1091 | ||
1006 | $client->submit($form, $data); | 1092 | $this->getEntityManager()->flush(); |
1007 | 1093 | ||
1008 | $crawler = $client->request('GET', '/all/list'); | 1094 | $crawler = $client->request('GET', '/all/list'); |
1009 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1095 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1016,14 +1102,17 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1016 | 1102 | ||
1017 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1103 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1018 | 1104 | ||
1019 | $crawler = $client->request('GET', '/new'); | 1105 | $entry = new Entry($this->getLoggedInUser()); |
1020 | $form = $crawler->filter('form[name=entry]')->form(); | 1106 | $entry->setUrl($this->url); |
1107 | $entry->setHttpStatus(200); | ||
1108 | $this->getEntityManager()->persist($entry); | ||
1021 | 1109 | ||
1022 | $data = [ | 1110 | $entry = new Entry($this->getLoggedInUser()); |
1023 | 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', | 1111 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); |
1024 | ]; | 1112 | $entry->setHttpStatus(200); |
1113 | $this->getEntityManager()->persist($entry); | ||
1025 | 1114 | ||
1026 | $client->submit($form, $data); | 1115 | $this->getEntityManager()->flush(); |
1027 | 1116 | ||
1028 | $crawler = $client->request('GET', '/all/list'); | 1117 | $crawler = $client->request('GET', '/all/list'); |
1029 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1118 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1034,7 +1123,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1034 | 1123 | ||
1035 | $crawler = $client->submit($form, $data); | 1124 | $crawler = $client->submit($form, $data); |
1036 | 1125 | ||
1037 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1126 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
1038 | 1127 | ||
1039 | $crawler = $client->request('GET', '/all/list'); | 1128 | $crawler = $client->request('GET', '/all/list'); |
1040 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1129 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1045,14 +1134,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1045 | 1134 | ||
1046 | $crawler = $client->submit($form, $data); | 1135 | $crawler = $client->submit($form, $data); |
1047 | 1136 | ||
1048 | $this->assertCount(7, $crawler->filter('div[class=entry]')); | 1137 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
1049 | } | 1138 | } |
1050 | 1139 | ||
1051 | public function testSearch() | 1140 | public function testSearch() |
1052 | { | 1141 | { |
1053 | $this->logInAs('admin'); | 1142 | $this->logInAs('admin'); |
1143 | $this->useTheme('baggy'); | ||
1054 | $client = $this->getClient(); | 1144 | $client = $this->getClient(); |
1055 | 1145 | ||
1146 | $entry = new Entry($this->getLoggedInUser()); | ||
1147 | $entry->setUrl($this->url); | ||
1148 | $entry->setTitle('test'); | ||
1149 | $this->getEntityManager()->persist($entry); | ||
1150 | $this->getEntityManager()->flush(); | ||
1151 | |||
1056 | // Search on unread list | 1152 | // Search on unread list |
1057 | $crawler = $client->request('GET', '/unread/list'); | 1153 | $crawler = $client->request('GET', '/unread/list'); |
1058 | 1154 | ||
@@ -1063,35 +1159,37 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1063 | 1159 | ||
1064 | $crawler = $client->submit($form, $data); | 1160 | $crawler = $client->submit($form, $data); |
1065 | 1161 | ||
1066 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 1162 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
1067 | 1163 | ||
1068 | // Search on starred list | 1164 | // Search on starred list |
1069 | $crawler = $client->request('GET', '/starred/list'); | 1165 | $crawler = $client->request('GET', '/starred/list'); |
1070 | 1166 | ||
1167 | $entry = new Entry($this->getLoggedInUser()); | ||
1168 | $entry->setUrl('http://localhost/foo/bar'); | ||
1169 | $entry->setTitle('testeur'); | ||
1170 | $entry->setStarred(true); | ||
1171 | $this->getEntityManager()->persist($entry); | ||
1172 | $this->getEntityManager()->flush(); | ||
1173 | |||
1071 | $form = $crawler->filter('form[name=search]')->form(); | 1174 | $form = $crawler->filter('form[name=search]')->form(); |
1072 | $data = [ | 1175 | $data = [ |
1073 | 'search_entry[term]' => 'title', | 1176 | 'search_entry[term]' => 'testeur', |
1074 | ]; | 1177 | ]; |
1075 | 1178 | ||
1076 | $crawler = $client->submit($form, $data); | 1179 | $crawler = $client->submit($form, $data); |
1077 | 1180 | ||
1078 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1181 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1079 | 1182 | ||
1080 | // Added new article to test on archive list | ||
1081 | $crawler = $client->request('GET', '/new'); | ||
1082 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1083 | $data = [ | ||
1084 | 'entry[url]' => $this->url, | ||
1085 | ]; | ||
1086 | $client->submit($form, $data); | ||
1087 | $content = $client->getContainer() | ||
1088 | ->get('doctrine.orm.entity_manager') | ||
1089 | ->getRepository('WallabagCoreBundle:Entry') | ||
1090 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
1091 | $client->request('GET', '/archive/'.$content->getId()); | ||
1092 | |||
1093 | $crawler = $client->request('GET', '/archive/list'); | 1183 | $crawler = $client->request('GET', '/archive/list'); |
1094 | 1184 | ||
1185 | // Added new article to test on archive list | ||
1186 | $entry = new Entry($this->getLoggedInUser()); | ||
1187 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | ||
1188 | $entry->setTitle('Le manège'); | ||
1189 | $entry->setArchived(true); | ||
1190 | $this->getEntityManager()->persist($entry); | ||
1191 | $this->getEntityManager()->flush(); | ||
1192 | |||
1095 | $form = $crawler->filter('form[name=search]')->form(); | 1193 | $form = $crawler->filter('form[name=search]')->form(); |
1096 | $data = [ | 1194 | $data = [ |
1097 | 'search_entry[term]' => 'manège', | 1195 | 'search_entry[term]' => 'manège', |
@@ -1100,7 +1198,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1100 | $crawler = $client->submit($form, $data); | 1198 | $crawler = $client->submit($form, $data); |
1101 | 1199 | ||
1102 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1200 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1103 | $client->request('GET', '/delete/'.$content->getId()); | 1201 | $client->request('GET', '/delete/'.$entry->getId()); |
1104 | 1202 | ||
1105 | // test on list of all articles | 1203 | // test on list of all articles |
1106 | $crawler = $client->request('GET', '/all/list'); | 1204 | $crawler = $client->request('GET', '/all/list'); |
@@ -1115,6 +1213,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1115 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | 1213 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
1116 | 1214 | ||
1117 | // test url search on list of all articles | 1215 | // test url search on list of all articles |
1216 | $entry = new Entry($this->getLoggedInUser()); | ||
1217 | $entry->setUrl('http://domain/qux'); | ||
1218 | $entry->setTitle('Le manège'); | ||
1219 | $entry->setArchived(true); | ||
1220 | $this->getEntityManager()->persist($entry); | ||
1221 | $this->getEntityManager()->flush(); | ||
1222 | |||
1118 | $crawler = $client->request('GET', '/all/list'); | 1223 | $crawler = $client->request('GET', '/all/list'); |
1119 | 1224 | ||
1120 | $form = $crawler->filter('form[name=search]')->form(); | 1225 | $form = $crawler->filter('form[name=search]')->form(); |
@@ -1138,4 +1243,82 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1138 | 1243 | ||
1139 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1244 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1140 | } | 1245 | } |
1246 | |||
1247 | public function dataForLanguage() | ||
1248 | { | ||
1249 | return [ | ||
1250 | 'ru' => [ | ||
1251 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | ||
1252 | 'ru', | ||
1253 | ], | ||
1254 | 'fr-FR' => [ | ||
1255 | 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', | ||
1256 | 'fr_FR', | ||
1257 | ], | ||
1258 | 'de' => [ | ||
1259 | 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', | ||
1260 | 'de', | ||
1261 | ], | ||
1262 | 'it' => [ | ||
1263 | 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | ||
1264 | 'it', | ||
1265 | ], | ||
1266 | 'zh_CN' => [ | ||
1267 | 'http://www.hao123.com/shequ?__noscript__-=1', | ||
1268 | 'zh_CN', | ||
1269 | ], | ||
1270 | 'de_AT' => [ | ||
1271 | 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728', | ||
1272 | 'de_AT', | ||
1273 | ], | ||
1274 | 'ru_RU' => [ | ||
1275 | 'http://netler.ru/ikt/windows-error-reporting.htm', | ||
1276 | 'ru_RU', | ||
1277 | ], | ||
1278 | 'pt_BR' => [ | ||
1279 | 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', | ||
1280 | 'pt_BR', | ||
1281 | ], | ||
1282 | 'fucked_list_of_languages' => [ | ||
1283 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', | ||
1284 | '', | ||
1285 | ], | ||
1286 | 'es-ES' => [ | ||
1287 | 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', | ||
1288 | 'es_ES', | ||
1289 | ], | ||
1290 | ]; | ||
1291 | } | ||
1292 | |||
1293 | /** | ||
1294 | * @dataProvider dataForLanguage | ||
1295 | */ | ||
1296 | public function testLanguageValidation($url, $expectedLanguage) | ||
1297 | { | ||
1298 | $this->logInAs('admin'); | ||
1299 | $client = $this->getClient(); | ||
1300 | |||
1301 | $crawler = $client->request('GET', '/new'); | ||
1302 | |||
1303 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1304 | |||
1305 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1306 | |||
1307 | $data = [ | ||
1308 | 'entry[url]' => $url, | ||
1309 | ]; | ||
1310 | |||
1311 | $client->submit($form, $data); | ||
1312 | |||
1313 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1314 | |||
1315 | $content = $client->getContainer() | ||
1316 | ->get('doctrine.orm.entity_manager') | ||
1317 | ->getRepository('WallabagCoreBundle:Entry') | ||
1318 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
1319 | |||
1320 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
1321 | $this->assertEquals($url, $content->getUrl()); | ||
1322 | $this->assertEquals($expectedLanguage, $content->getLanguage()); | ||
1323 | } | ||
1141 | } | 1324 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 32a18e26..b38961d3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | |||
@@ -189,11 +189,9 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
189 | $this->assertContains($contentInDB[0]['language'], $csv[1]); | 189 | $this->assertContains($contentInDB[0]['language'], $csv[1]); |
190 | $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); | 190 | $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); |
191 | 191 | ||
192 | $expectedTag = []; | ||
193 | foreach ($contentInDB[0]['tags'] as $tag) { | 192 | foreach ($contentInDB[0]['tags'] as $tag) { |
194 | $expectedTag[] = $tag['label']; | 193 | $this->assertContains($tag['label'], $csv[1]); |
195 | } | 194 | } |
196 | $this->assertContains(implode(', ', $expectedTag), $csv[1]); | ||
197 | } | 195 | } |
198 | 196 | ||
199 | public function testJsonExport() | 197 | public function testJsonExport() |
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index fa1a3539..af1ad7af 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(3, 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(3, 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(3, count($newEntry->getTags())); | ||
76 | } | 66 | } |
77 | 67 | ||
78 | public function testAddMultipleTagToEntry() | 68 | public function testAddMultipleTagToEntry() |
@@ -116,20 +106,25 @@ 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); | 117 | |
128 | 118 | // We make a first request to set an history and test redirection after tag deletion | |
119 | $client->request('GET', '/view/'.$entry->getId()); | ||
120 | $entryUri = $client->getRequest()->getUri(); | ||
129 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 121 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |
130 | 122 | ||
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
124 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); | ||
132 | 125 | ||
126 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) | ||
127 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); | ||
133 | $this->assertNotContains($this->tagName, $entry->getTags()); | 128 | $this->assertNotContains($this->tagName, $entry->getTags()); |
134 | 129 | ||
135 | $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/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index aee67259..8b50bce9 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; | 3 | namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; |
4 | 4 | ||
5 | use Monolog\Handler\TestHandler; | ||
6 | use Monolog\Logger; | ||
5 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; | 7 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; |
6 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; | 8 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; |
7 | use PHPUnit_Framework_TestCase; | 9 | use PHPUnit_Framework_TestCase; |
@@ -24,7 +26,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
24 | $grabySiteConfig->login_uri = 'http://example.com/login'; | 26 | $grabySiteConfig->login_uri = 'http://example.com/login'; |
25 | $grabySiteConfig->login_username_field = 'login'; | 27 | $grabySiteConfig->login_username_field = 'login'; |
26 | $grabySiteConfig->login_password_field = 'password'; | 28 | $grabySiteConfig->login_password_field = 'password'; |
27 | $grabySiteConfig->login_extra_fields = ['field' => 'value']; | 29 | $grabySiteConfig->login_extra_fields = ['field=value']; |
28 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | 30 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; |
29 | 31 | ||
30 | $grabyConfigBuilderMock | 32 | $grabyConfigBuilderMock |
@@ -32,14 +34,19 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
32 | ->with('example.com') | 34 | ->with('example.com') |
33 | ->will($this->returnValue($grabySiteConfig)); | 35 | ->will($this->returnValue($grabySiteConfig)); |
34 | 36 | ||
37 | $logger = new Logger('foo'); | ||
38 | $handler = new TestHandler(); | ||
39 | $logger->pushHandler($handler); | ||
40 | |||
35 | $this->builder = new GrabySiteConfigBuilder( | 41 | $this->builder = new GrabySiteConfigBuilder( |
36 | $grabyConfigBuilderMock, | 42 | $grabyConfigBuilderMock, |
37 | ['example.com' => ['username' => 'foo', 'password' => 'bar']] | 43 | ['example.com' => ['username' => 'foo', 'password' => 'bar']], |
44 | $logger | ||
38 | ); | 45 | ); |
39 | 46 | ||
40 | $config = $this->builder->buildForHost('example.com'); | 47 | $config = $this->builder->buildForHost('example.com'); |
41 | 48 | ||
42 | self::assertEquals( | 49 | $this->assertEquals( |
43 | new SiteConfig([ | 50 | new SiteConfig([ |
44 | 'host' => 'example.com', | 51 | 'host' => 'example.com', |
45 | 'requiresLogin' => true, | 52 | 'requiresLogin' => true, |
@@ -53,6 +60,10 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
53 | ]), | 60 | ]), |
54 | $config | 61 | $config |
55 | ); | 62 | ); |
63 | |||
64 | $records = $handler->getRecords(); | ||
65 | |||
66 | $this->assertCount(1, $records, 'One log was recorded'); | ||
56 | } | 67 | } |
57 | 68 | ||
58 | public function testBuildConfigDoesntExist() | 69 | public function testBuildConfigDoesntExist() |
@@ -67,19 +78,22 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
67 | ->with('unknown.com') | 78 | ->with('unknown.com') |
68 | ->will($this->returnValue(new GrabySiteConfig())); | 79 | ->will($this->returnValue(new GrabySiteConfig())); |
69 | 80 | ||
70 | $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []); | 81 | $logger = new Logger('foo'); |
82 | $handler = new TestHandler(); | ||
83 | $logger->pushHandler($handler); | ||
84 | |||
85 | $this->builder = new GrabySiteConfigBuilder( | ||
86 | $grabyConfigBuilderMock, | ||
87 | [], | ||
88 | $logger | ||
89 | ); | ||
71 | 90 | ||
72 | $config = $this->builder->buildForHost('unknown.com'); | 91 | $config = $this->builder->buildForHost('unknown.com'); |
73 | 92 | ||
74 | self::assertEquals( | 93 | $this->assertFalse($config); |
75 | new SiteConfig([ | 94 | |
76 | 'host' => 'unknown.com', | 95 | $records = $handler->getRecords(); |
77 | 'requiresLogin' => false, | 96 | |
78 | 'username' => null, | 97 | $this->assertCount(1, $records, 'One log was recorded'); |
79 | 'password' => null, | ||
80 | 'extraFields' => [], | ||
81 | ]), | ||
82 | $config | ||
83 | ); | ||
84 | } | 98 | } |
85 | } | 99 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 4f70ed0c..95dd75ba 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -3,10 +3,17 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Psr\Log\NullLogger; | 5 | use Psr\Log\NullLogger; |
6 | use Monolog\Logger; | ||
7 | use Monolog\Handler\TestHandler; | ||
6 | use Wallabag\CoreBundle\Helper\ContentProxy; | 8 | use Wallabag\CoreBundle\Helper\ContentProxy; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\CoreBundle\Entity\Tag; | 10 | use Wallabag\CoreBundle\Entity\Tag; |
9 | use Wallabag\UserBundle\Entity\User; | 11 | use Wallabag\UserBundle\Entity\User; |
12 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; | ||
13 | use Graby\Graby; | ||
14 | use Symfony\Component\Validator\Validator\RecursiveValidator; | ||
15 | use Symfony\Component\Validator\ConstraintViolationList; | ||
16 | use Symfony\Component\Validator\ConstraintViolation; | ||
10 | 17 | ||
11 | class ContentProxyTest extends \PHPUnit_Framework_TestCase | 18 | class ContentProxyTest extends \PHPUnit_Framework_TestCase |
12 | { | 19 | { |
@@ -33,8 +40,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
33 | 'language' => '', | 40 | 'language' => '', |
34 | ]); | 41 | ]); |
35 | 42 | ||
36 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 43 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
37 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); | 44 | $entry = new Entry(new User()); |
45 | $proxy->updateEntry($entry, 'http://user@:80'); | ||
38 | 46 | ||
39 | $this->assertEquals('http://user@:80', $entry->getUrl()); | 47 | $this->assertEquals('http://user@:80', $entry->getUrl()); |
40 | $this->assertEmpty($entry->getTitle()); | 48 | $this->assertEmpty($entry->getTitle()); |
@@ -67,8 +75,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
67 | 'language' => '', | 75 | 'language' => '', |
68 | ]); | 76 | ]); |
69 | 77 | ||
70 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 78 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
71 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | 79 | $entry = new Entry(new User()); |
80 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
72 | 81 | ||
73 | $this->assertEquals('http://0.0.0.0', $entry->getUrl()); | 82 | $this->assertEquals('http://0.0.0.0', $entry->getUrl()); |
74 | $this->assertEmpty($entry->getTitle()); | 83 | $this->assertEmpty($entry->getTitle()); |
@@ -106,12 +115,13 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
106 | ], | 115 | ], |
107 | ]); | 116 | ]); |
108 | 117 | ||
109 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 118 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
110 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); | 119 | $entry = new Entry(new User()); |
120 | $proxy->updateEntry($entry, 'http://domain.io'); | ||
111 | 121 | ||
112 | $this->assertEquals('http://domain.io', $entry->getUrl()); | 122 | $this->assertEquals('http://domain.io', $entry->getUrl()); |
113 | $this->assertEquals('my title', $entry->getTitle()); | 123 | $this->assertEquals('my title', $entry->getTitle()); |
114 | $this->assertEquals($this->fetchingErrorMessage . '<p><i>But we found a short description: </i></p>desc', $entry->getContent()); | 124 | $this->assertEquals($this->fetchingErrorMessage.'<p><i>But we found a short description: </i></p>desc', $entry->getContent()); |
115 | $this->assertEmpty($entry->getPreviewPicture()); | 125 | $this->assertEmpty($entry->getPreviewPicture()); |
116 | $this->assertEmpty($entry->getLanguage()); | 126 | $this->assertEmpty($entry->getLanguage()); |
117 | $this->assertEmpty($entry->getHttpStatus()); | 127 | $this->assertEmpty($entry->getHttpStatus()); |
@@ -147,8 +157,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
147 | ], | 157 | ], |
148 | ]); | 158 | ]); |
149 | 159 | ||
150 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 160 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
151 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | 161 | $entry = new Entry(new User()); |
162 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
152 | 163 | ||
153 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | 164 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
154 | $this->assertEquals('this is my title', $entry->getTitle()); | 165 | $this->assertEquals('this is my title', $entry->getTitle()); |
@@ -184,17 +195,18 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
184 | 'open_graph' => [ | 195 | 'open_graph' => [ |
185 | 'og_title' => 'my OG title', | 196 | 'og_title' => 'my OG title', |
186 | 'og_description' => 'OG desc', | 197 | 'og_description' => 'OG desc', |
187 | 'og_image' => false, | 198 | 'og_image' => null, |
188 | ], | 199 | ], |
189 | ]); | 200 | ]); |
190 | 201 | ||
191 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 202 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
192 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | 203 | $entry = new Entry(new User()); |
204 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
193 | 205 | ||
194 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | 206 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
195 | $this->assertEquals('this is my title', $entry->getTitle()); | 207 | $this->assertEquals('this is my title', $entry->getTitle()); |
196 | $this->assertContains('this is my content', $entry->getContent()); | 208 | $this->assertContains('this is my content', $entry->getContent()); |
197 | $this->assertNull($entry->getPreviewPicture()); | 209 | $this->assertEmpty($entry->getPreviewPicture()); |
198 | $this->assertEquals('text/html', $entry->getMimetype()); | 210 | $this->assertEquals('text/html', $entry->getMimetype()); |
199 | $this->assertEquals('fr', $entry->getLanguage()); | 211 | $this->assertEquals('fr', $entry->getLanguage()); |
200 | $this->assertEquals('200', $entry->getHttpStatus()); | 212 | $this->assertEquals('200', $entry->getHttpStatus()); |
@@ -202,187 +214,308 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
202 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | 214 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); |
203 | } | 215 | } |
204 | 216 | ||
205 | public function testWithForcedContent() | 217 | public function testWithContentAndBadLanguage() |
206 | { | 218 | { |
207 | $tagger = $this->getTaggerMock(); | 219 | $tagger = $this->getTaggerMock(); |
208 | $tagger->expects($this->once()) | 220 | $tagger->expects($this->once()) |
209 | ->method('tag'); | 221 | ->method('tag'); |
210 | 222 | ||
211 | $graby = $this->getMockBuilder('Graby\Graby')->getMock(); | 223 | $validator = $this->getValidator(); |
224 | $validator->expects($this->exactly(2)) | ||
225 | ->method('validate') | ||
226 | ->will($this->onConsecutiveCalls( | ||
227 | new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')]), | ||
228 | new ConstraintViolationList() | ||
229 | )); | ||
230 | |||
231 | $graby = $this->getMockBuilder('Graby\Graby') | ||
232 | ->setMethods(['fetchContent']) | ||
233 | ->disableOriginalConstructor() | ||
234 | ->getMock(); | ||
212 | 235 | ||
213 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 236 | $graby->expects($this->any()) |
214 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ | 237 | ->method('fetchContent') |
215 | 'html' => str_repeat('this is my content', 325), | 238 | ->willReturn([ |
216 | 'title' => 'this is my title', | 239 | 'html' => str_repeat('this is my content', 325), |
217 | 'url' => 'http://1.1.1.1', | 240 | 'title' => 'this is my title', |
218 | 'content_type' => 'text/html', | 241 | 'url' => 'http://1.1.1.1', |
219 | 'language' => 'fr', | 242 | 'content_type' => 'text/html', |
220 | ]); | 243 | 'language' => 'dontexist', |
244 | 'status' => '200', | ||
245 | ]); | ||
246 | |||
247 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | ||
248 | $entry = new Entry(new User()); | ||
249 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
221 | 250 | ||
222 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | 251 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
223 | $this->assertEquals('this is my title', $entry->getTitle()); | 252 | $this->assertEquals('this is my title', $entry->getTitle()); |
224 | $this->assertContains('this is my content', $entry->getContent()); | 253 | $this->assertContains('this is my content', $entry->getContent()); |
225 | $this->assertEquals('text/html', $entry->getMimetype()); | 254 | $this->assertEquals('text/html', $entry->getMimetype()); |
226 | $this->assertEquals('fr', $entry->getLanguage()); | 255 | $this->assertEmpty($entry->getLanguage()); |
256 | $this->assertEquals('200', $entry->getHttpStatus()); | ||
227 | $this->assertEquals(4.0, $entry->getReadingTime()); | 257 | $this->assertEquals(4.0, $entry->getReadingTime()); |
228 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | 258 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); |
229 | } | 259 | } |
230 | 260 | ||
231 | public function testTaggerThrowException() | 261 | public function testWithContentAndBadOgImage() |
232 | { | 262 | { |
233 | $graby = $this->getMockBuilder('Graby\Graby') | ||
234 | ->disableOriginalConstructor() | ||
235 | ->getMock(); | ||
236 | |||
237 | $tagger = $this->getTaggerMock(); | 263 | $tagger = $this->getTaggerMock(); |
238 | $tagger->expects($this->once()) | 264 | $tagger->expects($this->once()) |
239 | ->method('tag') | 265 | ->method('tag'); |
240 | ->will($this->throwException(new \Exception())); | ||
241 | |||
242 | $tagRepo = $this->getTagRepositoryMock(); | ||
243 | $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | ||
244 | |||
245 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ | ||
246 | 'html' => str_repeat('this is my content', 325), | ||
247 | 'title' => 'this is my title', | ||
248 | 'url' => 'http://1.1.1.1', | ||
249 | 'content_type' => 'text/html', | ||
250 | 'language' => 'fr', | ||
251 | ]); | ||
252 | 266 | ||
253 | $this->assertCount(0, $entry->getTags()); | 267 | $validator = $this->getValidator(); |
254 | } | 268 | $validator->expects($this->exactly(2)) |
269 | ->method('validate') | ||
270 | ->will($this->onConsecutiveCalls( | ||
271 | new ConstraintViolationList(), | ||
272 | new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'url', 'https://')]) | ||
273 | )); | ||
255 | 274 | ||
256 | public function testAssignTagsWithArrayAndExtraSpaces() | ||
257 | { | ||
258 | $graby = $this->getMockBuilder('Graby\Graby') | 275 | $graby = $this->getMockBuilder('Graby\Graby') |
276 | ->setMethods(['fetchContent']) | ||
259 | ->disableOriginalConstructor() | 277 | ->disableOriginalConstructor() |
260 | ->getMock(); | 278 | ->getMock(); |
261 | 279 | ||
262 | $tagRepo = $this->getTagRepositoryMock(); | 280 | $graby->expects($this->any()) |
263 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 281 | ->method('fetchContent') |
282 | ->willReturn([ | ||
283 | 'html' => str_repeat('this is my content', 325), | ||
284 | 'title' => 'this is my title', | ||
285 | 'url' => 'http://1.1.1.1', | ||
286 | 'content_type' => 'text/html', | ||
287 | 'language' => 'fr', | ||
288 | 'status' => '200', | ||
289 | 'open_graph' => [ | ||
290 | 'og_title' => 'my OG title', | ||
291 | 'og_description' => 'OG desc', | ||
292 | 'og_image' => 'https://', | ||
293 | ], | ||
294 | ]); | ||
264 | 295 | ||
296 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | ||
265 | $entry = new Entry(new User()); | 297 | $entry = new Entry(new User()); |
298 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
266 | 299 | ||
267 | $proxy->assignTagsToEntry($entry, [' tag1', 'tag2 ']); | 300 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
268 | 301 | $this->assertEquals('this is my title', $entry->getTitle()); | |
269 | $this->assertCount(2, $entry->getTags()); | 302 | $this->assertContains('this is my content', $entry->getContent()); |
270 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 303 | $this->assertEmpty($entry->getPreviewPicture()); |
271 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | 304 | $this->assertEquals('text/html', $entry->getMimetype()); |
305 | $this->assertEquals('fr', $entry->getLanguage()); | ||
306 | $this->assertEquals('200', $entry->getHttpStatus()); | ||
307 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
308 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
272 | } | 309 | } |
273 | 310 | ||
274 | public function testAssignTagsWithString() | 311 | public function testWithForcedContent() |
275 | { | 312 | { |
276 | $graby = $this->getMockBuilder('Graby\Graby') | 313 | $tagger = $this->getTaggerMock(); |
277 | ->disableOriginalConstructor() | 314 | $tagger->expects($this->once()) |
278 | ->getMock(); | 315 | ->method('tag'); |
279 | |||
280 | $tagRepo = $this->getTagRepositoryMock(); | ||
281 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | ||
282 | 316 | ||
317 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
283 | $entry = new Entry(new User()); | 318 | $entry = new Entry(new User()); |
319 | $proxy->updateEntry( | ||
320 | $entry, | ||
321 | 'http://0.0.0.0', | ||
322 | [ | ||
323 | 'html' => str_repeat('this is my content', 325), | ||
324 | 'title' => 'this is my title', | ||
325 | 'url' => 'http://1.1.1.1', | ||
326 | 'content_type' => 'text/html', | ||
327 | 'language' => 'fr', | ||
328 | 'date' => '1395635872', | ||
329 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], | ||
330 | 'all_headers' => [ | ||
331 | 'Cache-Control' => 'no-cache', | ||
332 | ], | ||
333 | ] | ||
334 | ); | ||
284 | 335 | ||
285 | $proxy->assignTagsToEntry($entry, 'tag1, tag2'); | 336 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
286 | 337 | $this->assertEquals('this is my title', $entry->getTitle()); | |
287 | $this->assertCount(2, $entry->getTags()); | 338 | $this->assertContains('this is my content', $entry->getContent()); |
288 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 339 | $this->assertEquals('text/html', $entry->getMimetype()); |
289 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | 340 | $this->assertEquals('fr', $entry->getLanguage()); |
341 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
342 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
343 | $this->assertEquals('24/03/2014', $entry->getPublishedAt()->format('d/m/Y')); | ||
344 | $this->assertContains('Jeremy', $entry->getPublishedBy()); | ||
345 | $this->assertContains('Nico', $entry->getPublishedBy()); | ||
346 | $this->assertContains('Thomas', $entry->getPublishedBy()); | ||
347 | $this->assertContains('no-cache', $entry->getHeaders()); | ||
290 | } | 348 | } |
291 | 349 | ||
292 | public function testAssignTagsWithEmptyArray() | 350 | public function testWithForcedContentAndDatetime() |
293 | { | 351 | { |
294 | $graby = $this->getMockBuilder('Graby\Graby') | 352 | $tagger = $this->getTaggerMock(); |
295 | ->disableOriginalConstructor() | 353 | $tagger->expects($this->once()) |
296 | ->getMock(); | 354 | ->method('tag'); |
297 | 355 | ||
298 | $tagRepo = $this->getTagRepositoryMock(); | 356 | $logHandler = new TestHandler(); |
299 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 357 | $logger = new Logger('test', [$logHandler]); |
300 | 358 | ||
359 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); | ||
301 | $entry = new Entry(new User()); | 360 | $entry = new Entry(new User()); |
361 | $proxy->updateEntry( | ||
362 | $entry, | ||
363 | 'http://1.1.1.1', | ||
364 | [ | ||
365 | 'html' => str_repeat('this is my content', 325), | ||
366 | 'title' => 'this is my title', | ||
367 | 'url' => 'http://1.1.1.1', | ||
368 | 'content_type' => 'text/html', | ||
369 | 'language' => 'fr', | ||
370 | 'date' => '2016-09-08T11:55:58+0200', | ||
371 | ] | ||
372 | ); | ||
302 | 373 | ||
303 | $proxy->assignTagsToEntry($entry, []); | 374 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
304 | 375 | $this->assertEquals('this is my title', $entry->getTitle()); | |
305 | $this->assertCount(0, $entry->getTags()); | 376 | $this->assertContains('this is my content', $entry->getContent()); |
377 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
378 | $this->assertEquals('fr', $entry->getLanguage()); | ||
379 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
380 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
381 | $this->assertEquals('08/09/2016', $entry->getPublishedAt()->format('d/m/Y')); | ||
306 | } | 382 | } |
307 | 383 | ||
308 | public function testAssignTagsWithEmptyString() | 384 | public function testWithForcedContentAndBadDate() |
309 | { | 385 | { |
310 | $graby = $this->getMockBuilder('Graby\Graby') | 386 | $tagger = $this->getTaggerMock(); |
311 | ->disableOriginalConstructor() | 387 | $tagger->expects($this->once()) |
312 | ->getMock(); | 388 | ->method('tag'); |
313 | 389 | ||
314 | $tagRepo = $this->getTagRepositoryMock(); | 390 | $logger = new Logger('foo'); |
315 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 391 | $handler = new TestHandler(); |
392 | $logger->pushHandler($handler); | ||
316 | 393 | ||
394 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); | ||
317 | $entry = new Entry(new User()); | 395 | $entry = new Entry(new User()); |
396 | $proxy->updateEntry( | ||
397 | $entry, | ||
398 | 'http://1.1.1.1', | ||
399 | [ | ||
400 | 'html' => str_repeat('this is my content', 325), | ||
401 | 'title' => 'this is my title', | ||
402 | 'url' => 'http://1.1.1.1', | ||
403 | 'content_type' => 'text/html', | ||
404 | 'language' => 'fr', | ||
405 | 'date' => '01 02 2012', | ||
406 | ] | ||
407 | ); | ||
408 | |||
409 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
410 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
411 | $this->assertContains('this is my content', $entry->getContent()); | ||
412 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
413 | $this->assertEquals('fr', $entry->getLanguage()); | ||
414 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
415 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
416 | $this->assertNull($entry->getPublishedAt()); | ||
318 | 417 | ||
319 | $proxy->assignTagsToEntry($entry, ''); | 418 | $records = $handler->getRecords(); |
320 | 419 | ||
321 | $this->assertCount(0, $entry->getTags()); | 420 | $this->assertCount(1, $records); |
421 | $this->assertContains('Error while defining date', $records[0]['message']); | ||
322 | } | 422 | } |
323 | 423 | ||
324 | public function testAssignTagsAlreadyAssigned() | 424 | public function testTaggerThrowException() |
325 | { | 425 | { |
326 | $graby = $this->getMockBuilder('Graby\Graby') | 426 | $tagger = $this->getTaggerMock(); |
327 | ->disableOriginalConstructor() | 427 | $tagger->expects($this->once()) |
328 | ->getMock(); | 428 | ->method('tag') |
329 | 429 | ->will($this->throwException(new \Exception())); | |
330 | $tagRepo = $this->getTagRepositoryMock(); | ||
331 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | ||
332 | |||
333 | $tagEntity = new Tag(); | ||
334 | $tagEntity->setLabel('tag1'); | ||
335 | 430 | ||
431 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
336 | $entry = new Entry(new User()); | 432 | $entry = new Entry(new User()); |
337 | $entry->addTag($tagEntity); | 433 | $proxy->updateEntry( |
338 | 434 | $entry, | |
339 | $proxy->assignTagsToEntry($entry, 'tag1, tag2'); | 435 | 'http://1.1.1.1', |
436 | [ | ||
437 | 'html' => str_repeat('this is my content', 325), | ||
438 | 'title' => 'this is my title', | ||
439 | 'url' => 'http://1.1.1.1', | ||
440 | 'content_type' => 'text/html', | ||
441 | 'language' => 'fr', | ||
442 | ] | ||
443 | ); | ||
340 | 444 | ||
341 | $this->assertCount(2, $entry->getTags()); | 445 | $this->assertCount(0, $entry->getTags()); |
342 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
343 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
344 | } | 446 | } |
345 | 447 | ||
346 | public function testAssignTagsNotFlushed() | 448 | public function dataForCrazyHtml() |
347 | { | 449 | { |
348 | $graby = $this->getMockBuilder('Graby\Graby') | 450 | return [ |
349 | ->disableOriginalConstructor() | 451 | 'script and comment' => [ |
350 | ->getMock(); | 452 | '<strong>Script inside:</strong> <!--[if gte IE 4]><script>alert(\'lol\');</script><![endif]--><br />', |
351 | 453 | 'lol', | |
352 | $tagRepo = $this->getTagRepositoryMock(); | 454 | ], |
353 | $tagRepo->expects($this->never()) | 455 | 'script' => [ |
354 | ->method('__call'); | 456 | '<strong>Script inside:</strong><script>alert(\'lol\');</script>', |
355 | 457 | 'script', | |
356 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 458 | ], |
459 | ]; | ||
460 | } | ||
357 | 461 | ||
358 | $tagEntity = new Tag(); | 462 | /** |
359 | $tagEntity->setLabel('tag1'); | 463 | * @dataProvider dataForCrazyHtml |
464 | */ | ||
465 | public function testWithCrazyHtmlContent($html, $escapedString) | ||
466 | { | ||
467 | $tagger = $this->getTaggerMock(); | ||
468 | $tagger->expects($this->once()) | ||
469 | ->method('tag'); | ||
360 | 470 | ||
471 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
361 | $entry = new Entry(new User()); | 472 | $entry = new Entry(new User()); |
473 | $proxy->updateEntry( | ||
474 | $entry, | ||
475 | 'http://1.1.1.1', | ||
476 | [ | ||
477 | 'html' => $html, | ||
478 | 'title' => 'this is my title', | ||
479 | 'url' => 'http://1.1.1.1', | ||
480 | 'content_type' => 'text/html', | ||
481 | 'language' => 'fr', | ||
482 | 'status' => '200', | ||
483 | 'open_graph' => [ | ||
484 | 'og_title' => 'my OG title', | ||
485 | 'og_description' => 'OG desc', | ||
486 | 'og_image' => 'http://3.3.3.3/cover.jpg', | ||
487 | ], | ||
488 | ] | ||
489 | ); | ||
362 | 490 | ||
363 | $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]); | 491 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); |
364 | 492 | $this->assertEquals('this is my title', $entry->getTitle()); | |
365 | $this->assertCount(1, $entry->getTags()); | 493 | $this->assertNotContains($escapedString, $entry->getContent()); |
366 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 494 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); |
495 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
496 | $this->assertEquals('fr', $entry->getLanguage()); | ||
497 | $this->assertEquals('200', $entry->getHttpStatus()); | ||
498 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
367 | } | 499 | } |
368 | 500 | ||
369 | private function getTaggerMock() | 501 | private function getTaggerMock() |
370 | { | 502 | { |
371 | return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') | 503 | return $this->getMockBuilder(RuleBasedTagger::class) |
372 | ->setMethods(['tag']) | 504 | ->setMethods(['tag']) |
373 | ->disableOriginalConstructor() | 505 | ->disableOriginalConstructor() |
374 | ->getMock(); | 506 | ->getMock(); |
375 | } | 507 | } |
376 | 508 | ||
377 | private function getTagRepositoryMock() | 509 | private function getLogger() |
378 | { | 510 | { |
379 | return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | 511 | return new NullLogger(); |
380 | ->disableOriginalConstructor() | ||
381 | ->getMock(); | ||
382 | } | 512 | } |
383 | 513 | ||
384 | private function getLogger() | 514 | private function getValidator() |
385 | { | 515 | { |
386 | return new NullLogger(); | 516 | return $this->getMockBuilder(RecursiveValidator::class) |
517 | ->setMethods(['validate']) | ||
518 | ->disableOriginalConstructor() | ||
519 | ->getMock(); | ||
387 | } | 520 | } |
388 | } | 521 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 85f12d87..c02f9658 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -12,7 +12,24 @@ use GuzzleHttp\Stream\Stream; | |||
12 | 12 | ||
13 | class DownloadImagesTest extends \PHPUnit_Framework_TestCase | 13 | class DownloadImagesTest extends \PHPUnit_Framework_TestCase |
14 | { | 14 | { |
15 | public function testProcessHtml() | 15 | public function dataForSuccessImage() |
16 | { | ||
17 | return [ | ||
18 | 'imgur' => [ | ||
19 | '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', | ||
20 | 'http://imgur.com/gallery/WxtWY', | ||
21 | ], | ||
22 | 'image with &' => [ | ||
23 | '<div><img src="https://i2.wp.com/www.tvaddons.ag/wp-content/uploads/2017/01/Screen-Shot-2017-01-07-at-10.17.40-PM.jpg?w=640&ssl=1" /></div>', | ||
24 | 'https://www.tvaddons.ag/realdebrid-kodi-jarvis/', | ||
25 | ], | ||
26 | ]; | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * @dataProvider dataForSuccessImage | ||
31 | */ | ||
32 | public function testProcessHtml($html, $url) | ||
16 | { | 33 | { |
17 | $client = new Client(); | 34 | $client = new Client(); |
18 | 35 | ||
@@ -27,9 +44,10 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
27 | 44 | ||
28 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | 45 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); |
29 | 46 | ||
30 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); | 47 | $res = $download->processHtml(123, $html, $url); |
31 | 48 | ||
32 | $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res); | 49 | // this the base path of all image (since it's calculated using the entry id: 123) |
50 | $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/', $res); | ||
33 | } | 51 | } |
34 | 52 | ||
35 | public function testProcessHtmlWithBadImage() | 53 | public function testProcessHtmlWithBadImage() |
@@ -139,4 +157,29 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
139 | 157 | ||
140 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); | 158 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); |
141 | } | 159 | } |
160 | |||
161 | public function testProcessRealImage() | ||
162 | { | ||
163 | $client = new Client(); | ||
164 | |||
165 | $mock = new Mock([ | ||
166 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__.'/../fixtures/image-no-content-type.jpg'))), | ||
167 | ]); | ||
168 | |||
169 | $client->getEmitter()->attach($mock); | ||
170 | |||
171 | $logHandler = new TestHandler(); | ||
172 | $logger = new Logger('test', array($logHandler)); | ||
173 | |||
174 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
175 | |||
176 | $res = $download->processSingleImage( | ||
177 | 123, | ||
178 | 'https://cdn.theconversation.com/files/157200/article/width926/gsj2rjp2-1487348607.jpg', | ||
179 | 'https://theconversation.com/conversation-avec-gerald-bronner-ce-nest-pas-la-post-verite-qui-nous-menace-mais-lextension-de-notre-credulite-73089' | ||
180 | ); | ||
181 | |||
182 | $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/', $res, 'Content-Type was empty but data is ok for an image'); | ||
183 | $this->assertContains('DownloadImages: Checking extension (alternative)', $logHandler->getRecords()[3]['message']); | ||
184 | } | ||
142 | } | 185 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 0539f20a..f420d06a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |||
@@ -89,4 +89,22 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
89 | 89 | ||
90 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | 90 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); |
91 | } | 91 | } |
92 | |||
93 | public function testUserForRedirectWithIgnoreActionMarkAsRead() | ||
94 | { | ||
95 | $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | ||
96 | |||
97 | $redirectUrl = $this->redirect->to('/unread/list', '', true); | ||
98 | |||
99 | $this->assertEquals('/unread/list', $redirectUrl); | ||
100 | } | ||
101 | |||
102 | public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead() | ||
103 | { | ||
104 | $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | ||
105 | |||
106 | $redirectUrl = $this->redirect->to(null, 'fallback', true); | ||
107 | |||
108 | $this->assertEquals('fallback', $redirectUrl); | ||
109 | } | ||
92 | } | 110 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php index 17b08c2a..1e21f400 100644 --- a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Monolog\Handler\TestHandler; | ||
6 | use Monolog\Logger; | ||
5 | use Wallabag\CoreBundle\Entity\Config; | 7 | use Wallabag\CoreBundle\Entity\Config; |
6 | use Wallabag\CoreBundle\Entity\Entry; | 8 | use Wallabag\CoreBundle\Entity\Entry; |
7 | use Wallabag\CoreBundle\Entity\Tag; | 9 | use Wallabag\CoreBundle\Entity\Tag; |
@@ -15,14 +17,19 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
15 | private $tagRepository; | 17 | private $tagRepository; |
16 | private $entryRepository; | 18 | private $entryRepository; |
17 | private $tagger; | 19 | private $tagger; |
20 | private $logger; | ||
21 | private $handler; | ||
18 | 22 | ||
19 | public function setUp() | 23 | public function setUp() |
20 | { | 24 | { |
21 | $this->rulerz = $this->getRulerZMock(); | 25 | $this->rulerz = $this->getRulerZMock(); |
22 | $this->tagRepository = $this->getTagRepositoryMock(); | 26 | $this->tagRepository = $this->getTagRepositoryMock(); |
23 | $this->entryRepository = $this->getEntryRepositoryMock(); | 27 | $this->entryRepository = $this->getEntryRepositoryMock(); |
28 | $this->logger = $this->getLogger(); | ||
29 | $this->handler = new TestHandler(); | ||
30 | $this->logger->pushHandler($this->handler); | ||
24 | 31 | ||
25 | $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository); | 32 | $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->logger); |
26 | } | 33 | } |
27 | 34 | ||
28 | public function testTagWithNoRule() | 35 | public function testTagWithNoRule() |
@@ -32,6 +39,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
32 | $this->tagger->tag($entry); | 39 | $this->tagger->tag($entry); |
33 | 40 | ||
34 | $this->assertTrue($entry->getTags()->isEmpty()); | 41 | $this->assertTrue($entry->getTags()->isEmpty()); |
42 | $records = $this->handler->getRecords(); | ||
43 | $this->assertCount(0, $records); | ||
35 | } | 44 | } |
36 | 45 | ||
37 | public function testTagWithNoMatchingRule() | 46 | public function testTagWithNoMatchingRule() |
@@ -49,6 +58,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
49 | $this->tagger->tag($entry); | 58 | $this->tagger->tag($entry); |
50 | 59 | ||
51 | $this->assertTrue($entry->getTags()->isEmpty()); | 60 | $this->assertTrue($entry->getTags()->isEmpty()); |
61 | $records = $this->handler->getRecords(); | ||
62 | $this->assertCount(0, $records); | ||
52 | } | 63 | } |
53 | 64 | ||
54 | public function testTagWithAMatchingRule() | 65 | public function testTagWithAMatchingRule() |
@@ -70,6 +81,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
70 | $tags = $entry->getTags(); | 81 | $tags = $entry->getTags(); |
71 | $this->assertSame('foo', $tags[0]->getLabel()); | 82 | $this->assertSame('foo', $tags[0]->getLabel()); |
72 | $this->assertSame('bar', $tags[1]->getLabel()); | 83 | $this->assertSame('bar', $tags[1]->getLabel()); |
84 | |||
85 | $records = $this->handler->getRecords(); | ||
86 | $this->assertCount(1, $records); | ||
73 | } | 87 | } |
74 | 88 | ||
75 | public function testTagWithAMixOfMatchingRules() | 89 | public function testTagWithAMixOfMatchingRules() |
@@ -90,6 +104,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
90 | 104 | ||
91 | $tags = $entry->getTags(); | 105 | $tags = $entry->getTags(); |
92 | $this->assertSame('foo', $tags[0]->getLabel()); | 106 | $this->assertSame('foo', $tags[0]->getLabel()); |
107 | $records = $this->handler->getRecords(); | ||
108 | $this->assertCount(1, $records); | ||
93 | } | 109 | } |
94 | 110 | ||
95 | public function testWhenTheTagExists() | 111 | public function testWhenTheTagExists() |
@@ -118,6 +134,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
118 | 134 | ||
119 | $tags = $entry->getTags(); | 135 | $tags = $entry->getTags(); |
120 | $this->assertSame($tag, $tags[0]); | 136 | $this->assertSame($tag, $tags[0]); |
137 | $records = $this->handler->getRecords(); | ||
138 | $this->assertCount(1, $records); | ||
121 | } | 139 | } |
122 | 140 | ||
123 | public function testSameTagWithDifferentfMatchingRules() | 141 | public function testSameTagWithDifferentfMatchingRules() |
@@ -138,6 +156,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
138 | 156 | ||
139 | $tags = $entry->getTags(); | 157 | $tags = $entry->getTags(); |
140 | $this->assertCount(1, $tags); | 158 | $this->assertCount(1, $tags); |
159 | $records = $this->handler->getRecords(); | ||
160 | $this->assertCount(2, $records); | ||
141 | } | 161 | } |
142 | 162 | ||
143 | public function testTagAllEntriesForAUser() | 163 | public function testTagAllEntriesForAUser() |
@@ -209,4 +229,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
209 | ->disableOriginalConstructor() | 229 | ->disableOriginalConstructor() |
210 | ->getMock(); | 230 | ->getMock(); |
211 | } | 231 | } |
232 | |||
233 | private function getLogger() | ||
234 | { | ||
235 | return new Logger('foo'); | ||
236 | } | ||
212 | } | 237 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php new file mode 100644 index 00000000..6d6d6484 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php | |||
@@ -0,0 +1,108 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | ||
7 | use Wallabag\CoreBundle\Helper\TagsAssigner; | ||
8 | use Wallabag\UserBundle\Entity\User; | ||
9 | use Wallabag\CoreBundle\Repository\TagRepository; | ||
10 | |||
11 | class TagsAssignerTest extends \PHPUnit_Framework_TestCase | ||
12 | { | ||
13 | public function testAssignTagsWithArrayAndExtraSpaces() | ||
14 | { | ||
15 | $tagRepo = $this->getTagRepositoryMock(); | ||
16 | $tagsAssigner = new TagsAssigner($tagRepo); | ||
17 | |||
18 | $entry = new Entry(new User()); | ||
19 | |||
20 | $tagsAssigner->assignTagsToEntry($entry, [' tag1', 'tag2 ']); | ||
21 | |||
22 | $this->assertCount(2, $entry->getTags()); | ||
23 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
24 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
25 | } | ||
26 | |||
27 | public function testAssignTagsWithString() | ||
28 | { | ||
29 | $tagRepo = $this->getTagRepositoryMock(); | ||
30 | $tagsAssigner = new TagsAssigner($tagRepo); | ||
31 | |||
32 | $entry = new Entry(new User()); | ||
33 | |||
34 | $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2'); | ||
35 | |||
36 | $this->assertCount(2, $entry->getTags()); | ||
37 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
38 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
39 | } | ||
40 | |||
41 | public function testAssignTagsWithEmptyArray() | ||
42 | { | ||
43 | $tagRepo = $this->getTagRepositoryMock(); | ||
44 | $tagsAssigner = new TagsAssigner($tagRepo); | ||
45 | |||
46 | $entry = new Entry(new User()); | ||
47 | |||
48 | $tagsAssigner->assignTagsToEntry($entry, []); | ||
49 | |||
50 | $this->assertCount(0, $entry->getTags()); | ||
51 | } | ||
52 | |||
53 | public function testAssignTagsWithEmptyString() | ||
54 | { | ||
55 | $tagRepo = $this->getTagRepositoryMock(); | ||
56 | $tagsAssigner = new TagsAssigner($tagRepo); | ||
57 | |||
58 | $entry = new Entry(new User()); | ||
59 | |||
60 | $tagsAssigner->assignTagsToEntry($entry, ''); | ||
61 | |||
62 | $this->assertCount(0, $entry->getTags()); | ||
63 | } | ||
64 | |||
65 | public function testAssignTagsAlreadyAssigned() | ||
66 | { | ||
67 | $tagRepo = $this->getTagRepositoryMock(); | ||
68 | $tagsAssigner = new TagsAssigner($tagRepo); | ||
69 | |||
70 | $tagEntity = new Tag(); | ||
71 | $tagEntity->setLabel('tag1'); | ||
72 | |||
73 | $entry = new Entry(new User()); | ||
74 | $entry->addTag($tagEntity); | ||
75 | |||
76 | $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2'); | ||
77 | |||
78 | $this->assertCount(2, $entry->getTags()); | ||
79 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
80 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
81 | } | ||
82 | |||
83 | public function testAssignTagsNotFlushed() | ||
84 | { | ||
85 | $tagRepo = $this->getTagRepositoryMock(); | ||
86 | $tagRepo->expects($this->never()) | ||
87 | ->method('__call'); | ||
88 | |||
89 | $tagsAssigner = new TagsAssigner($tagRepo); | ||
90 | |||
91 | $tagEntity = new Tag(); | ||
92 | $tagEntity->setLabel('tag1'); | ||
93 | |||
94 | $entry = new Entry(new User()); | ||
95 | |||
96 | $tagsAssigner->assignTagsToEntry($entry, 'tag1', [$tagEntity]); | ||
97 | |||
98 | $this->assertCount(1, $entry->getTags()); | ||
99 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
100 | } | ||
101 | |||
102 | private function getTagRepositoryMock() | ||
103 | { | ||
104 | return $this->getMockBuilder(TagRepository::class) | ||
105 | ->disableOriginalConstructor() | ||
106 | ->getMock(); | ||
107 | } | ||
108 | } | ||
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index 2e6fccfb..ca8e0d50 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php | |||
@@ -136,7 +136,7 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase | |||
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException | 139 | * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
140 | * @expectedExceptionMessage User not found | 140 | * @expectedExceptionMessage User not found |
141 | */ | 141 | */ |
142 | public function testApplyUserNotFound() | 142 | public function testApplyUserNotFound() |
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/CoreBundle/fixtures/image-no-content-type.jpg b/tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg new file mode 100644 index 00000000..0c60e952 --- /dev/null +++ b/tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg | |||
Binary files differ | |||