aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Command/ExportCommandTest.php4
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php173
-rw-r--r--tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php11
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php359
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php59
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php203
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php24
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php18
-rw-r--r--tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php76
12 files changed, 609 insertions, 324 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
index b21f3318..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;
10class ExportCommandTest extends WallabagCoreTestCase 10class 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
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 122a87d4..94fc0b94 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -2,8 +2,11 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Command; 3namespace Tests\Wallabag\CoreBundle\Command;
4 4
5use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
5use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; 6use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
6use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; 7use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
8use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
9use Doctrine\DBAL\Platforms\SqlitePlatform;
7use Symfony\Bundle\FrameworkBundle\Console\Application; 10use Symfony\Bundle\FrameworkBundle\Console\Application;
8use Symfony\Component\Console\Input\ArrayInput; 11use Symfony\Component\Console\Input\ArrayInput;
9use Symfony\Component\Console\Output\NullOutput; 12use 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 ]);
@@ -97,18 +108,13 @@ class InstallCommandTest extends WallabagCoreTestCase
97 108
98 $command = $application->find('wallabag:install'); 109 $command = $application->find('wallabag:install');
99 110
100 // We mock the QuestionHelper
101 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
102 ->disableOriginalConstructor()
103 ->getMock();
104 $question->expects($this->any())
105 ->method('ask')
106 ->will($this->returnValue('yes_'.uniqid('', true)));
107
108 // We override the standard helper with our mock
109 $command->getHelperSet()->set($question, 'question');
110
111 $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 ]);
112 $tester->execute([ 118 $tester->execute([
113 'command' => $command->getName(), 119 'command' => $command->getName(),
114 '--reset' => true, 120 '--reset' => true,
@@ -129,7 +135,7 @@ class InstallCommandTest extends WallabagCoreTestCase
129 { 135 {
130 // 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,
131 // 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
132 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) {
133 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); 139 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.');
134 } 140 }
135 141
@@ -150,18 +156,13 @@ class InstallCommandTest extends WallabagCoreTestCase
150 156
151 $command = $application->find('wallabag:install'); 157 $command = $application->find('wallabag:install');
152 158
153 // We mock the QuestionHelper
154 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
155 ->disableOriginalConstructor()
156 ->getMock();
157 $question->expects($this->any())
158 ->method('ask')
159 ->will($this->returnValue('yes_'.uniqid('', true)));
160
161 // We override the standard helper with our mock
162 $command->getHelperSet()->set($question, 'question');
163
164 $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 ]);
165 $tester->execute([ 166 $tester->execute([
166 'command' => $command->getName(), 167 'command' => $command->getName(),
167 ]); 168 ]);
@@ -183,23 +184,12 @@ class InstallCommandTest extends WallabagCoreTestCase
183 184
184 $command = $application->find('wallabag:install'); 185 $command = $application->find('wallabag:install');
185 186
186 // We mock the QuestionHelper
187 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
188 ->disableOriginalConstructor()
189 ->getMock();
190
191 $question->expects($this->exactly(3))
192 ->method('ask')
193 ->will($this->onConsecutiveCalls(
194 false, // don't want to reset the entire database
195 true, // do want to reset the schema
196 false // don't want to create a new user
197 ));
198
199 // We override the standard helper with our mock
200 $command->getHelperSet()->set($question, 'question');
201
202 $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 ]);
203 $tester->execute([ 193 $tester->execute([
204 'command' => $command->getName(), 194 'command' => $command->getName(),
205 ]); 195 ]);
@@ -239,22 +229,11 @@ class InstallCommandTest extends WallabagCoreTestCase
239 229
240 $command = $application->find('wallabag:install'); 230 $command = $application->find('wallabag:install');
241 231
242 // We mock the QuestionHelper
243 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
244 ->disableOriginalConstructor()
245 ->getMock();
246
247 $question->expects($this->exactly(2))
248 ->method('ask')
249 ->will($this->onConsecutiveCalls(
250 false, // don't want to reset the entire database
251 false // don't want to create a new user
252 ));
253
254 // We override the standard helper with our mock
255 $command->getHelperSet()->set($question, 'question');
256
257 $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 ]);
258 $tester->execute([ 237 $tester->execute([
259 'command' => $command->getName(), 238 'command' => $command->getName(),
260 ]); 239 ]);
@@ -275,21 +254,11 @@ class InstallCommandTest extends WallabagCoreTestCase
275 254
276 $command = $application->find('wallabag:install'); 255 $command = $application->find('wallabag:install');
277 256
278 // We mock the QuestionHelper
279 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
280 ->disableOriginalConstructor()
281 ->getMock();
282 $question->expects($this->any())
283 ->method('ask')
284 ->will($this->returnValue('yes_'.uniqid('', true)));
285
286 // We override the standard helper with our mock
287 $command->getHelperSet()->set($question, 'question');
288
289 $tester = new CommandTester($command); 257 $tester = new CommandTester($command);
290 $tester->execute([ 258 $tester->execute([
291 'command' => $command->getName(), 259 'command' => $command->getName(),
292 '--no-interaction' => true, 260 ], [
261 'interactive' => false,
293 ]); 262 ]);
294 263
295 $this->assertContains('Checking system requirements.', $tester->getDisplay()); 264 $this->assertContains('Checking system requirements.', $tester->getDisplay());
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;
10class TagAllCommandTest extends WallabagCoreTestCase 10class 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 35888f16..5bc815ee 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -67,8 +67,17 @@ class ConfigControllerTest extends WallabagCoreTestCase
67 public function testChangeReadingSpeed() 67 public function testChangeReadingSpeed()
68 { 68 {
69 $this->logInAs('admin'); 69 $this->logInAs('admin');
70 $this->useTheme('baggy');
70 $client = $this->getClient(); 71 $client = $this->getClient();
71 72
73 $entry = new Entry($this->getLoggedInUser());
74 $entry->setUrl('http://0.0.0.0/test-entry1')
75 ->setReadingTime(22);
76 $this->getEntityManager()->persist($entry);
77
78 $this->getEntityManager()->flush();
79 $this->getEntityManager()->clear();
80
72 $crawler = $client->request('GET', '/unread/list'); 81 $crawler = $client->request('GET', '/unread/list');
73 $form = $crawler->filter('button[id=submit-filter]')->form(); 82 $form = $crawler->filter('button[id=submit-filter]')->form();
74 $dataFilters = [ 83 $dataFilters = [
@@ -409,6 +418,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
409 public function testTaggingRuleCreation() 418 public function testTaggingRuleCreation()
410 { 419 {
411 $this->logInAs('admin'); 420 $this->logInAs('admin');
421 $this->useTheme('baggy');
412 $client = $this->getClient(); 422 $client = $this->getClient();
413 423
414 $crawler = $client->request('GET', '/config'); 424 $crawler = $client->request('GET', '/config');
@@ -939,6 +949,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
939 public function testSwitchViewMode() 949 public function testSwitchViewMode()
940 { 950 {
941 $this->logInAs('admin'); 951 $this->logInAs('admin');
952 $this->useTheme('baggy');
942 $client = $this->getClient(); 953 $client = $this->getClient();
943 954
944 $client->request('GET', '/unread/list'); 955 $client->request('GET', '/unread/list');
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 116e5f32..cc7b3672 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -71,6 +71,7 @@ class EntryControllerTest extends WallabagCoreTestCase
71 public function testGetNew() 71 public function testGetNew()
72 { 72 {
73 $this->logInAs('admin'); 73 $this->logInAs('admin');
74 $this->useTheme('baggy');
74 $client = $this->getClient(); 75 $client = $this->getClient();
75 76
76 $crawler = $client->request('GET', '/new'); 77 $crawler = $client->request('GET', '/new');
@@ -84,6 +85,7 @@ class EntryControllerTest extends WallabagCoreTestCase
84 public function testPostNewViaBookmarklet() 85 public function testPostNewViaBookmarklet()
85 { 86 {
86 $this->logInAs('admin'); 87 $this->logInAs('admin');
88 $this->useTheme('baggy');
87 $client = $this->getClient(); 89 $client = $this->getClient();
88 90
89 $crawler = $client->request('GET', '/'); 91 $crawler = $client->request('GET', '/');
@@ -195,6 +197,12 @@ class EntryControllerTest extends WallabagCoreTestCase
195 public function testPostNewOkUrlExist() 197 public function testPostNewOkUrlExist()
196 { 198 {
197 $this->logInAs('admin'); 199 $this->logInAs('admin');
200
201 $entry = new Entry($this->getLoggedInUser());
202 $entry->setUrl($this->url);
203 $this->getEntityManager()->persist($entry);
204 $this->getEntityManager()->flush();
205
198 $client = $this->getClient(); 206 $client = $this->getClient();
199 207
200 $crawler = $client->request('GET', '/new'); 208 $crawler = $client->request('GET', '/new');
@@ -288,7 +296,7 @@ class EntryControllerTest extends WallabagCoreTestCase
288 $tags = $entry->getTags(); 296 $tags = $entry->getTags();
289 297
290 $this->assertCount(2, $tags); 298 $this->assertCount(2, $tags);
291 $this->assertEquals('wallabag', $tags[0]->getLabel()); 299 $this->assertContains('wallabag', $tags);
292 300
293 $em->remove($entry); 301 $em->remove($entry);
294 $em->flush(); 302 $em->flush();
@@ -317,7 +325,7 @@ class EntryControllerTest extends WallabagCoreTestCase
317 $tags = $entry->getTags(); 325 $tags = $entry->getTags();
318 326
319 $this->assertCount(2, $tags); 327 $this->assertCount(2, $tags);
320 $this->assertEquals('wallabag', $tags[1]->getLabel()); 328 $this->assertContains('wallabag', $tags);
321 329
322 $em->remove($entry); 330 $em->remove($entry);
323 $em->flush(); 331 $em->flush();
@@ -364,24 +372,23 @@ class EntryControllerTest extends WallabagCoreTestCase
364 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); 372 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
365 } 373 }
366 374
367 /**
368 * @depends testPostNewOk
369 */
370 public function testView() 375 public function testView()
371 { 376 {
372 $this->logInAs('admin'); 377 $this->logInAs('admin');
373 $client = $this->getClient(); 378 $client = $this->getClient();
374 379
375 $content = $client->getContainer() 380 $entry = new Entry($this->getLoggedInUser());
376 ->get('doctrine.orm.entity_manager') 381 $entry->setUrl('http://example.com/foo');
377 ->getRepository('WallabagCoreBundle:Entry') 382 $entry->setTitle('title foo');
378 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 383 $entry->setContent('foo bar baz');
384 $this->getEntityManager()->persist($entry);
385 $this->getEntityManager()->flush();
379 386
380 $crawler = $client->request('GET', '/view/'.$content->getId()); 387 $crawler = $client->request('GET', '/view/'.$entry->getId());
381 388
382 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 389 $this->assertEquals(200, $client->getResponse()->getStatusCode());
383 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 390 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
384 $this->assertContains($content->getTitle(), $body[0]); 391 $this->assertContains($entry->getTitle(), $body[0]);
385 } 392 }
386 393
387 /** 394 /**
@@ -394,27 +401,23 @@ class EntryControllerTest extends WallabagCoreTestCase
394 $this->logInAs('admin'); 401 $this->logInAs('admin');
395 $client = $this->getClient(); 402 $client = $this->getClient();
396 403
397 $em = $client->getContainer() 404 $entry = new Entry($this->getLoggedInUser());
398 ->get('doctrine.orm.entity_manager'); 405 $entry->setUrl($this->url);
406 $entry->setTitle('title foo');
407 $entry->setContent('');
408 $this->getEntityManager()->persist($entry);
409 $this->getEntityManager()->flush();
410 $this->getEntityManager()->clear();
399 411
400 $content = $em 412 $client->request('GET', '/reload/'.$entry->getId());
401 ->getRepository('WallabagCoreBundle:Entry')
402 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
403
404 // empty content
405 $content->setContent('');
406 $em->persist($content);
407 $em->flush();
408
409 $client->request('GET', '/reload/'.$content->getId());
410 413
411 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 414 $this->assertEquals(302, $client->getResponse()->getStatusCode());
412 415
413 $content = $em 416 $entry = $this->getEntityManager()
414 ->getRepository('WallabagCoreBundle:Entry') 417 ->getRepository('WallabagCoreBundle:Entry')
415 ->find($content->getId()); 418 ->find($entry->getId());
416 419
417 $this->assertNotEmpty($content->getContent()); 420 $this->assertNotEmpty($entry->getContent());
418 } 421 }
419 422
420 /** 423 /**
@@ -425,32 +428,21 @@ class EntryControllerTest extends WallabagCoreTestCase
425 $this->logInAs('admin'); 428 $this->logInAs('admin');
426 $client = $this->getClient(); 429 $client = $this->getClient();
427 430
428 $em = $client->getContainer() 431 $entry = new Entry($this->getLoggedInUser());
429 ->get('doctrine.orm.entity_manager'); 432 $entry->setUrl('http://0.0.0.0/failed.html');
430 433 $this->getEntityManager()->persist($entry);
431 $content = $em 434 $this->getEntityManager()->flush();
432 ->getRepository('WallabagCoreBundle:Entry')
433 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
434
435 // put a known failed url
436 $content->setUrl('http://0.0.0.0/failed.html');
437 $em->persist($content);
438 $em->flush();
439 435
440 $client->request('GET', '/reload/'.$content->getId()); 436 $client->request('GET', '/reload/'.$entry->getId());
441 437
442 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 438 $this->assertEquals(302, $client->getResponse()->getStatusCode());
443 439
444 // force EntityManager to clear previous entity 440 // force EntityManager to clear previous entity
445 // otherwise, retrieve the same entity will retrieve change from the previous request :0 441 // otherwise, retrieve the same entity will retrieve change from the previous request :0
446 $em->clear(); 442 $this->getEntityManager()->clear();
447 $newContent = $em 443 $newContent = $this->getEntityManager()
448 ->getRepository('WallabagCoreBundle:Entry') 444 ->getRepository('WallabagCoreBundle:Entry')
449 ->find($content->getId()); 445 ->find($entry->getId());
450
451 $newContent->setUrl($this->url);
452 $em->persist($newContent);
453 $em->flush();
454 446
455 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); 447 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
456 } 448 }
@@ -460,12 +452,12 @@ class EntryControllerTest extends WallabagCoreTestCase
460 $this->logInAs('admin'); 452 $this->logInAs('admin');
461 $client = $this->getClient(); 453 $client = $this->getClient();
462 454
463 $content = $client->getContainer() 455 $entry = new Entry($this->getLoggedInUser());
464 ->get('doctrine.orm.entity_manager') 456 $entry->setUrl($this->url);
465 ->getRepository('WallabagCoreBundle:Entry') 457 $this->getEntityManager()->persist($entry);
466 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 458 $this->getEntityManager()->flush();
467 459
468 $crawler = $client->request('GET', '/edit/'.$content->getId()); 460 $crawler = $client->request('GET', '/edit/'.$entry->getId());
469 461
470 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 462 $this->assertEquals(200, $client->getResponse()->getStatusCode());
471 463
@@ -478,12 +470,12 @@ class EntryControllerTest extends WallabagCoreTestCase
478 $this->logInAs('admin'); 470 $this->logInAs('admin');
479 $client = $this->getClient(); 471 $client = $this->getClient();
480 472
481 $content = $client->getContainer() 473 $entry = new Entry($this->getLoggedInUser());
482 ->get('doctrine.orm.entity_manager') 474 $entry->setUrl($this->url);
483 ->getRepository('WallabagCoreBundle:Entry') 475 $this->getEntityManager()->persist($entry);
484 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 476 $this->getEntityManager()->flush();
485 477
486 $crawler = $client->request('GET', '/edit/'.$content->getId()); 478 $crawler = $client->request('GET', '/edit/'.$entry->getId());
487 479
488 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 480 $this->assertEquals(200, $client->getResponse()->getStatusCode());
489 481
@@ -508,19 +500,20 @@ class EntryControllerTest extends WallabagCoreTestCase
508 $this->logInAs('admin'); 500 $this->logInAs('admin');
509 $client = $this->getClient(); 501 $client = $this->getClient();
510 502
511 $content = $client->getContainer() 503 $entry = new Entry($this->getLoggedInUser());
512 ->get('doctrine.orm.entity_manager') 504 $entry->setUrl($this->url);
513 ->getRepository('WallabagCoreBundle:Entry') 505 $this->getEntityManager()->persist($entry);
514 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 506 $this->getEntityManager()->flush();
507 $this->getEntityManager()->clear();
515 508
516 $client->request('GET', '/archive/'.$content->getId()); 509 $client->request('GET', '/archive/'.$entry->getId());
517 510
518 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 511 $this->assertEquals(302, $client->getResponse()->getStatusCode());
519 512
520 $res = $client->getContainer() 513 $res = $client->getContainer()
521 ->get('doctrine.orm.entity_manager') 514 ->get('doctrine.orm.entity_manager')
522 ->getRepository('WallabagCoreBundle:Entry') 515 ->getRepository('WallabagCoreBundle:Entry')
523 ->find($content->getId()); 516 ->find($entry->getId());
524 517
525 $this->assertEquals($res->isArchived(), true); 518 $this->assertEquals($res->isArchived(), true);
526 } 519 }
@@ -530,19 +523,20 @@ class EntryControllerTest extends WallabagCoreTestCase
530 $this->logInAs('admin'); 523 $this->logInAs('admin');
531 $client = $this->getClient(); 524 $client = $this->getClient();
532 525
533 $content = $client->getContainer() 526 $entry = new Entry($this->getLoggedInUser());
534 ->get('doctrine.orm.entity_manager') 527 $entry->setUrl($this->url);
535 ->getRepository('WallabagCoreBundle:Entry') 528 $this->getEntityManager()->persist($entry);
536 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 529 $this->getEntityManager()->flush();
530 $this->getEntityManager()->clear();
537 531
538 $client->request('GET', '/star/'.$content->getId()); 532 $client->request('GET', '/star/'.$entry->getId());
539 533
540 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 534 $this->assertEquals(302, $client->getResponse()->getStatusCode());
541 535
542 $res = $client->getContainer() 536 $res = $client->getContainer()
543 ->get('doctrine.orm.entity_manager') 537 ->get('doctrine.orm.entity_manager')
544 ->getRepository('WallabagCoreBundle:Entry') 538 ->getRepository('WallabagCoreBundle:Entry')
545 ->findOneById($content->getId()); 539 ->findOneById($entry->getId());
546 540
547 $this->assertEquals($res->isStarred(), true); 541 $this->assertEquals($res->isStarred(), true);
548 } 542 }
@@ -552,16 +546,16 @@ class EntryControllerTest extends WallabagCoreTestCase
552 $this->logInAs('admin'); 546 $this->logInAs('admin');
553 $client = $this->getClient(); 547 $client = $this->getClient();
554 548
555 $content = $client->getContainer() 549 $entry = new Entry($this->getLoggedInUser());
556 ->get('doctrine.orm.entity_manager') 550 $entry->setUrl($this->url);
557 ->getRepository('WallabagCoreBundle:Entry') 551 $this->getEntityManager()->persist($entry);
558 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 552 $this->getEntityManager()->flush();
559 553
560 $client->request('GET', '/delete/'.$content->getId()); 554 $client->request('GET', '/delete/'.$entry->getId());
561 555
562 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 556 $this->assertEquals(302, $client->getResponse()->getStatusCode());
563 557
564 $client->request('GET', '/delete/'.$content->getId()); 558 $client->request('GET', '/delete/'.$entry->getId());
565 559
566 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 560 $this->assertEquals(404, $client->getResponse()->getStatusCode());
567 } 561 }
@@ -627,7 +621,13 @@ class EntryControllerTest extends WallabagCoreTestCase
627 public function testFilterOnReadingTime() 621 public function testFilterOnReadingTime()
628 { 622 {
629 $this->logInAs('admin'); 623 $this->logInAs('admin');
624 $this->useTheme('baggy');
630 $client = $this->getClient(); 625 $client = $this->getClient();
626 $entry = new Entry($this->getLoggedInUser());
627 $entry->setUrl($this->url);
628 $entry->setReadingTime(22);
629 $this->getEntityManager()->persist($entry);
630 $this->getEntityManager()->flush();
631 631
632 $crawler = $client->request('GET', '/unread/list'); 632 $crawler = $client->request('GET', '/unread/list');
633 633
@@ -666,9 +666,20 @@ class EntryControllerTest extends WallabagCoreTestCase
666 public function testFilterOnReadingTimeOnlyUpper() 666 public function testFilterOnReadingTimeOnlyUpper()
667 { 667 {
668 $this->logInAs('admin'); 668 $this->logInAs('admin');
669 $this->useTheme('baggy');
669 $client = $this->getClient(); 670 $client = $this->getClient();
670 671
671 $crawler = $client->request('GET', '/unread/list'); 672 $crawler = $client->request('GET', '/all/list');
673 $this->assertCount(5, $crawler->filter('div[class=entry]'));
674
675 $entry = new Entry($this->getLoggedInUser());
676 $entry->setUrl($this->url);
677 $entry->setReadingTime(23);
678 $this->getEntityManager()->persist($entry);
679 $this->getEntityManager()->flush();
680
681 $crawler = $client->request('GET', '/all/list');
682 $this->assertCount(6, $crawler->filter('div[class=entry]'));
672 683
673 $form = $crawler->filter('button[id=submit-filter]')->form(); 684 $form = $crawler->filter('button[id=submit-filter]')->form();
674 685
@@ -678,12 +689,13 @@ class EntryControllerTest extends WallabagCoreTestCase
678 689
679 $crawler = $client->submit($form, $data); 690 $crawler = $client->submit($form, $data);
680 691
681 $this->assertCount(3, $crawler->filter('div[class=entry]')); 692 $this->assertCount(5, $crawler->filter('div[class=entry]'));
682 } 693 }
683 694
684 public function testFilterOnReadingTimeOnlyLower() 695 public function testFilterOnReadingTimeOnlyLower()
685 { 696 {
686 $this->logInAs('admin'); 697 $this->logInAs('admin');
698 $this->useTheme('baggy');
687 $client = $this->getClient(); 699 $client = $this->getClient();
688 700
689 $crawler = $client->request('GET', '/unread/list'); 701 $crawler = $client->request('GET', '/unread/list');
@@ -696,12 +708,22 @@ class EntryControllerTest extends WallabagCoreTestCase
696 708
697 $crawler = $client->submit($form, $data); 709 $crawler = $client->submit($form, $data);
698 710
699 $this->assertCount(4, $crawler->filter('div[class=entry]')); 711 $this->assertCount(0, $crawler->filter('div[class=entry]'));
712
713 $entry = new Entry($this->getLoggedInUser());
714 $entry->setUrl($this->url);
715 $entry->setReadingTime(23);
716 $this->getEntityManager()->persist($entry);
717 $this->getEntityManager()->flush();
718
719 $crawler = $client->submit($form, $data);
720 $this->assertCount(1, $crawler->filter('div[class=entry]'));
700 } 721 }
701 722
702 public function testFilterOnUnreadStatus() 723 public function testFilterOnUnreadStatus()
703 { 724 {
704 $this->logInAs('admin'); 725 $this->logInAs('admin');
726 $this->useTheme('baggy');
705 $client = $this->getClient(); 727 $client = $this->getClient();
706 728
707 $crawler = $client->request('GET', '/all/list'); 729 $crawler = $client->request('GET', '/all/list');
@@ -714,12 +736,23 @@ class EntryControllerTest extends WallabagCoreTestCase
714 736
715 $crawler = $client->submit($form, $data); 737 $crawler = $client->submit($form, $data);
716 738
739 $this->assertCount(4, $crawler->filter('div[class=entry]'));
740
741 $entry = new Entry($this->getLoggedInUser());
742 $entry->setUrl($this->url);
743 $entry->setArchived(false);
744 $this->getEntityManager()->persist($entry);
745 $this->getEntityManager()->flush();
746
747 $crawler = $client->submit($form, $data);
748
717 $this->assertCount(5, $crawler->filter('div[class=entry]')); 749 $this->assertCount(5, $crawler->filter('div[class=entry]'));
718 } 750 }
719 751
720 public function testFilterOnCreationDate() 752 public function testFilterOnCreationDate()
721 { 753 {
722 $this->logInAs('admin'); 754 $this->logInAs('admin');
755 $this->useTheme('baggy');
723 $client = $this->getClient(); 756 $client = $this->getClient();
724 757
725 $crawler = $client->request('GET', '/unread/list'); 758 $crawler = $client->request('GET', '/unread/list');
@@ -733,7 +766,7 @@ class EntryControllerTest extends WallabagCoreTestCase
733 766
734 $crawler = $client->submit($form, $data); 767 $crawler = $client->submit($form, $data);
735 768
736 $this->assertCount(6, $crawler->filter('div[class=entry]')); 769 $this->assertCount(5, $crawler->filter('div[class=entry]'));
737 770
738 $data = [ 771 $data = [
739 'entry_filter[createdAt][left_date]' => date('d/m/Y'), 772 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
@@ -742,7 +775,7 @@ class EntryControllerTest extends WallabagCoreTestCase
742 775
743 $crawler = $client->submit($form, $data); 776 $crawler = $client->submit($form, $data);
744 777
745 $this->assertCount(6, $crawler->filter('div[class=entry]')); 778 $this->assertCount(5, $crawler->filter('div[class=entry]'));
746 779
747 $data = [ 780 $data = [
748 'entry_filter[createdAt][left_date]' => '01/01/1970', 781 'entry_filter[createdAt][left_date]' => '01/01/1970',
@@ -786,6 +819,7 @@ class EntryControllerTest extends WallabagCoreTestCase
786 public function testFilterOnDomainName() 819 public function testFilterOnDomainName()
787 { 820 {
788 $this->logInAs('admin'); 821 $this->logInAs('admin');
822 $this->useTheme('baggy');
789 $client = $this->getClient(); 823 $client = $this->getClient();
790 824
791 $crawler = $client->request('GET', '/unread/list'); 825 $crawler = $client->request('GET', '/unread/list');
@@ -818,6 +852,7 @@ class EntryControllerTest extends WallabagCoreTestCase
818 public function testFilterOnStatus() 852 public function testFilterOnStatus()
819 { 853 {
820 $this->logInAs('admin'); 854 $this->logInAs('admin');
855 $this->useTheme('baggy');
821 $client = $this->getClient(); 856 $client = $this->getClient();
822 857
823 $crawler = $client->request('GET', '/unread/list'); 858 $crawler = $client->request('GET', '/unread/list');
@@ -839,6 +874,7 @@ class EntryControllerTest extends WallabagCoreTestCase
839 public function testPreviewPictureFilter() 874 public function testPreviewPictureFilter()
840 { 875 {
841 $this->logInAs('admin'); 876 $this->logInAs('admin');
877 $this->useTheme('baggy');
842 $client = $this->getClient(); 878 $client = $this->getClient();
843 879
844 $crawler = $client->request('GET', '/unread/list'); 880 $crawler = $client->request('GET', '/unread/list');
@@ -846,14 +882,21 @@ class EntryControllerTest extends WallabagCoreTestCase
846 $form['entry_filter[previewPicture]']->tick(); 882 $form['entry_filter[previewPicture]']->tick();
847 883
848 $crawler = $client->submit($form); 884 $crawler = $client->submit($form);
849 $this->assertCount(2, $crawler->filter('div[class=entry]')); 885 $this->assertCount(1, $crawler->filter('div[class=entry]'));
850 } 886 }
851 887
852 public function testFilterOnLanguage() 888 public function testFilterOnLanguage()
853 { 889 {
854 $this->logInAs('admin'); 890 $this->logInAs('admin');
891 $this->useTheme('baggy');
855 $client = $this->getClient(); 892 $client = $this->getClient();
856 893
894 $entry = new Entry($this->getLoggedInUser());
895 $entry->setUrl($this->url);
896 $entry->setLanguage('fr');
897 $this->getEntityManager()->persist($entry);
898 $this->getEntityManager()->flush();
899
857 $crawler = $client->request('GET', '/unread/list'); 900 $crawler = $client->request('GET', '/unread/list');
858 $form = $crawler->filter('button[id=submit-filter]')->form(); 901 $form = $crawler->filter('button[id=submit-filter]')->form();
859 $data = [ 902 $data = [
@@ -877,10 +920,14 @@ class EntryControllerTest extends WallabagCoreTestCase
877 $this->logInAs('admin'); 920 $this->logInAs('admin');
878 $client = $this->getClient(); 921 $client = $this->getClient();
879 922
880 $content = $client->getContainer() 923 // sharing is enabled
881 ->get('doctrine.orm.entity_manager') 924 $client->getContainer()->get('craue_config')->set('share_public', 1);
882 ->getRepository('WallabagCoreBundle:Entry') 925
883 ->findOneByUser($this->getLoggedInUserId()); 926 $content = new Entry($this->getLoggedInUser());
927 $content->setUrl($this->url);
928 $this->getEntityManager()->persist($content);
929 $this->getEntityManager()->flush();
930 $this->getEntityManager()->clear();
884 931
885 // no uid 932 // no uid
886 $client->request('GET', '/share/'.$content->getUid()); 933 $client->request('GET', '/share/'.$content->getUid());
@@ -970,6 +1017,20 @@ class EntryControllerTest extends WallabagCoreTestCase
970 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; 1017 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
971 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); 1018 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
972 1019
1020 $crawler = $client->request('GET', '/new');
1021
1022 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1023
1024 $form = $crawler->filter('form[name=entry]')->form();
1025
1026 $data = [
1027 'entry[url]' => $url,
1028 ];
1029
1030 $client->submit($form, $data);
1031
1032 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1033
973 $content = $client->getContainer() 1034 $content = $client->getContainer()
974 ->get('doctrine.orm.entity_manager') 1035 ->get('doctrine.orm.entity_manager')
975 ->getRepository('WallabagCoreBundle:Entry') 1036 ->getRepository('WallabagCoreBundle:Entry')
@@ -987,28 +1048,19 @@ class EntryControllerTest extends WallabagCoreTestCase
987 $this->logInAs('empty'); 1048 $this->logInAs('empty');
988 $client = $this->getClient(); 1049 $client = $this->getClient();
989 1050
990 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
991 $user = $em
992 ->getRepository('WallabagUserBundle:User')
993 ->find($this->getLoggedInUserId());
994
995 if (!$user) {
996 $this->markTestSkipped('No user found in db.');
997 }
998
999 // Redirect to homepage 1051 // Redirect to homepage
1000 $config = $user->getConfig(); 1052 $config = $this->getLoggedInUser()->getConfig();
1001 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); 1053 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
1002 $em->persist($config); 1054 $this->getEntityManager()->persist($config);
1003 $em->flush();
1004 1055
1005 $content = $client->getContainer() 1056 $entry = new Entry($this->getLoggedInUser());
1006 ->get('doctrine.orm.entity_manager') 1057 $entry->setUrl($this->url);
1007 ->getRepository('WallabagCoreBundle:Entry') 1058 $this->getEntityManager()->persist($entry);
1008 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1009 1059
1010 $client->request('GET', '/view/'.$content->getId()); 1060 $this->getEntityManager()->flush();
1011 $client->request('GET', '/archive/'.$content->getId()); 1061
1062 $client->request('GET', '/view/'.$entry->getId());
1063 $client->request('GET', '/archive/'.$entry->getId());
1012 1064
1013 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 1065 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1014 $this->assertEquals('/', $client->getResponse()->headers->get('location')); 1066 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
@@ -1019,46 +1071,36 @@ class EntryControllerTest extends WallabagCoreTestCase
1019 $this->logInAs('empty'); 1071 $this->logInAs('empty');
1020 $client = $this->getClient(); 1072 $client = $this->getClient();
1021 1073
1022 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1023 $user = $em
1024 ->getRepository('WallabagUserBundle:User')
1025 ->find($this->getLoggedInUserId());
1026
1027 if (!$user) {
1028 $this->markTestSkipped('No user found in db.');
1029 }
1030
1031 // Redirect to current page 1074 // Redirect to current page
1032 $config = $user->getConfig(); 1075 $config = $this->getLoggedInUser()->getConfig();
1033 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); 1076 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
1034 $em->persist($config); 1077 $this->getEntityManager()->persist($config);
1035 $em->flush();
1036 1078
1037 $content = $client->getContainer() 1079 $entry = new Entry($this->getLoggedInUser());
1038 ->get('doctrine.orm.entity_manager') 1080 $entry->setUrl($this->url);
1039 ->getRepository('WallabagCoreBundle:Entry') 1081 $this->getEntityManager()->persist($entry);
1040 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1041 1082
1042 $client->request('GET', '/view/'.$content->getId()); 1083 $this->getEntityManager()->flush();
1043 $client->request('GET', '/archive/'.$content->getId()); 1084
1085 $client->request('GET', '/view/'.$entry->getId());
1086 $client->request('GET', '/archive/'.$entry->getId());
1044 1087
1045 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 1088 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1046 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); 1089 $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location'));
1047 } 1090 }
1048 1091
1049 public function testFilterOnHttpStatus() 1092 public function testFilterOnHttpStatus()
1050 { 1093 {
1051 $this->logInAs('admin'); 1094 $this->logInAs('admin');
1095 $this->useTheme('baggy');
1052 $client = $this->getClient(); 1096 $client = $this->getClient();
1053 1097
1054 $crawler = $client->request('GET', '/new'); 1098 $entry = new Entry($this->getLoggedInUser());
1055 $form = $crawler->filter('form[name=entry]')->form(); 1099 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1100 $entry->setHttpStatus(404);
1101 $this->getEntityManager()->persist($entry);
1056 1102
1057 $data = [ 1103 $this->getEntityManager()->flush();
1058 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
1059 ];
1060
1061 $client->submit($form, $data);
1062 1104
1063 $crawler = $client->request('GET', '/all/list'); 1105 $crawler = $client->request('GET', '/all/list');
1064 $form = $crawler->filter('button[id=submit-filter]')->form(); 1106 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1071,14 +1113,17 @@ class EntryControllerTest extends WallabagCoreTestCase
1071 1113
1072 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1114 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1073 1115
1074 $crawler = $client->request('GET', '/new'); 1116 $entry = new Entry($this->getLoggedInUser());
1075 $form = $crawler->filter('form[name=entry]')->form(); 1117 $entry->setUrl($this->url);
1118 $entry->setHttpStatus(200);
1119 $this->getEntityManager()->persist($entry);
1076 1120
1077 $data = [ 1121 $entry = new Entry($this->getLoggedInUser());
1078 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', 1122 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1079 ]; 1123 $entry->setHttpStatus(200);
1124 $this->getEntityManager()->persist($entry);
1080 1125
1081 $client->submit($form, $data); 1126 $this->getEntityManager()->flush();
1082 1127
1083 $crawler = $client->request('GET', '/all/list'); 1128 $crawler = $client->request('GET', '/all/list');
1084 $form = $crawler->filter('button[id=submit-filter]')->form(); 1129 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1106,8 +1151,15 @@ class EntryControllerTest extends WallabagCoreTestCase
1106 public function testSearch() 1151 public function testSearch()
1107 { 1152 {
1108 $this->logInAs('admin'); 1153 $this->logInAs('admin');
1154 $this->useTheme('baggy');
1109 $client = $this->getClient(); 1155 $client = $this->getClient();
1110 1156
1157 $entry = new Entry($this->getLoggedInUser());
1158 $entry->setUrl($this->url);
1159 $entry->setTitle('test');
1160 $this->getEntityManager()->persist($entry);
1161 $this->getEntityManager()->flush();
1162
1111 // Search on unread list 1163 // Search on unread list
1112 $crawler = $client->request('GET', '/unread/list'); 1164 $crawler = $client->request('GET', '/unread/list');
1113 1165
@@ -1118,35 +1170,37 @@ class EntryControllerTest extends WallabagCoreTestCase
1118 1170
1119 $crawler = $client->submit($form, $data); 1171 $crawler = $client->submit($form, $data);
1120 1172
1121 $this->assertCount(5, $crawler->filter('div[class=entry]')); 1173 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1122 1174
1123 // Search on starred list 1175 // Search on starred list
1124 $crawler = $client->request('GET', '/starred/list'); 1176 $crawler = $client->request('GET', '/starred/list');
1125 1177
1178 $entry = new Entry($this->getLoggedInUser());
1179 $entry->setUrl('http://localhost/foo/bar');
1180 $entry->setTitle('testeur');
1181 $entry->setStarred(true);
1182 $this->getEntityManager()->persist($entry);
1183 $this->getEntityManager()->flush();
1184
1126 $form = $crawler->filter('form[name=search]')->form(); 1185 $form = $crawler->filter('form[name=search]')->form();
1127 $data = [ 1186 $data = [
1128 'search_entry[term]' => 'title', 1187 'search_entry[term]' => 'testeur',
1129 ]; 1188 ];
1130 1189
1131 $crawler = $client->submit($form, $data); 1190 $crawler = $client->submit($form, $data);
1132 1191
1133 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1192 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1134 1193
1135 // Added new article to test on archive list
1136 $crawler = $client->request('GET', '/new');
1137 $form = $crawler->filter('form[name=entry]')->form();
1138 $data = [
1139 'entry[url]' => $this->url,
1140 ];
1141 $client->submit($form, $data);
1142 $content = $client->getContainer()
1143 ->get('doctrine.orm.entity_manager')
1144 ->getRepository('WallabagCoreBundle:Entry')
1145 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1146 $client->request('GET', '/archive/'.$content->getId());
1147
1148 $crawler = $client->request('GET', '/archive/list'); 1194 $crawler = $client->request('GET', '/archive/list');
1149 1195
1196 // Added new article to test on archive list
1197 $entry = new Entry($this->getLoggedInUser());
1198 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1199 $entry->setTitle('Le manège');
1200 $entry->setArchived(true);
1201 $this->getEntityManager()->persist($entry);
1202 $this->getEntityManager()->flush();
1203
1150 $form = $crawler->filter('form[name=search]')->form(); 1204 $form = $crawler->filter('form[name=search]')->form();
1151 $data = [ 1205 $data = [
1152 'search_entry[term]' => 'manège', 1206 'search_entry[term]' => 'manège',
@@ -1155,7 +1209,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1155 $crawler = $client->submit($form, $data); 1209 $crawler = $client->submit($form, $data);
1156 1210
1157 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1211 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1158 $client->request('GET', '/delete/'.$content->getId()); 1212 $client->request('GET', '/delete/'.$entry->getId());
1159 1213
1160 // test on list of all articles 1214 // test on list of all articles
1161 $crawler = $client->request('GET', '/all/list'); 1215 $crawler = $client->request('GET', '/all/list');
@@ -1170,6 +1224,13 @@ class EntryControllerTest extends WallabagCoreTestCase
1170 $this->assertCount(0, $crawler->filter('div[class=entry]')); 1224 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1171 1225
1172 // test url search on list of all articles 1226 // test url search on list of all articles
1227 $entry = new Entry($this->getLoggedInUser());
1228 $entry->setUrl('http://domain/qux');
1229 $entry->setTitle('Le manège');
1230 $entry->setArchived(true);
1231 $this->getEntityManager()->persist($entry);
1232 $this->getEntityManager()->flush();
1233
1173 $crawler = $client->request('GET', '/all/list'); 1234 $crawler = $client->request('GET', '/all/list');
1174 1235
1175 $form = $crawler->filter('form[name=search]')->form(); 1236 $form = $crawler->filter('form[name=search]')->form();
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 63f2c829..b38961d3 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -239,7 +239,7 @@ class ExportControllerTest extends WallabagCoreTestCase
239 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); 239 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
240 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); 240 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
241 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); 241 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
242 $this->assertEquals(['foo bar', 'baz', 'foot'], $content[0]['tags']); 242 $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']);
243 } 243 }
244 244
245 public function testXmlExport() 245 public function testXmlExport()
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index c3b22dcd..af1ad7af 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\CoreBundle\Entity\Tag; 7use Wallabag\CoreBundle\Entity\Tag;
7 8
8class TagControllerTest extends WallabagCoreTestCase 9class TagControllerTest extends WallabagCoreTestCase
@@ -24,10 +25,11 @@ class TagControllerTest extends WallabagCoreTestCase
24 $this->logInAs('admin'); 25 $this->logInAs('admin');
25 $client = $this->getClient(); 26 $client = $this->getClient();
26 27
27 $entry = $client->getContainer() 28 $entry = new Entry($this->getLoggedInUser());
28 ->get('doctrine.orm.entity_manager') 29 $entry->setUrl('http://0.0.0.0/foo');
29 ->getRepository('WallabagCoreBundle:Entry') 30 $this->getEntityManager()->persist($entry);
30 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); 31 $this->getEntityManager()->flush();
32 $this->getEntityManager()->clear();
31 33
32 $crawler = $client->request('GET', '/view/'.$entry->getId()); 34 $crawler = $client->request('GET', '/view/'.$entry->getId());
33 35
@@ -41,23 +43,15 @@ class TagControllerTest extends WallabagCoreTestCase
41 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 43 $this->assertEquals(302, $client->getResponse()->getStatusCode());
42 44
43 // be sure to reload the entry 45 // be sure to reload the entry
44 $entry = $client->getContainer() 46 $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
45 ->get('doctrine.orm.entity_manager') 47 $this->assertCount(1, $entry->getTags());
46 ->getRepository('WallabagCoreBundle:Entry')
47 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
48
49 $this->assertEquals(4, count($entry->getTags()));
50 48
51 // tag already exists and already assigned 49 // tag already exists and already assigned
52 $client->submit($form, $data); 50 $client->submit($form, $data);
53 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 51 $this->assertEquals(302, $client->getResponse()->getStatusCode());
54 52
55 $newEntry = $client->getContainer() 53 $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
56 ->get('doctrine.orm.entity_manager') 54 $this->assertCount(1, $entry->getTags());
57 ->getRepository('WallabagCoreBundle:Entry')
58 ->find($entry->getId());
59
60 $this->assertEquals(4, count($newEntry->getTags()));
61 55
62 // tag already exists but still not assigned to this entry 56 // tag already exists but still not assigned to this entry
63 $data = [ 57 $data = [
@@ -67,12 +61,8 @@ class TagControllerTest extends WallabagCoreTestCase
67 $client->submit($form, $data); 61 $client->submit($form, $data);
68 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 62 $this->assertEquals(302, $client->getResponse()->getStatusCode());
69 63
70 $newEntry = $client->getContainer() 64 $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId());
71 ->get('doctrine.orm.entity_manager') 65 $this->assertCount(2, $entry->getTags());
72 ->getRepository('WallabagCoreBundle:Entry')
73 ->find($entry->getId());
74
75 $this->assertEquals(4, count($newEntry->getTags()));
76 } 66 }
77 67
78 public function testAddMultipleTagToEntry() 68 public function testAddMultipleTagToEntry()
@@ -116,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/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 77dfd5bf..a3570125 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -3,12 +3,14 @@
3namespace Tests\Wallabag\CoreBundle\Helper; 3namespace Tests\Wallabag\CoreBundle\Helper;
4 4
5use Psr\Log\NullLogger; 5use Psr\Log\NullLogger;
6use Monolog\Logger;
7use Monolog\Handler\TestHandler;
6use Wallabag\CoreBundle\Helper\ContentProxy; 8use Wallabag\CoreBundle\Helper\ContentProxy;
7use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\Tag; 10use Wallabag\CoreBundle\Entity\Tag;
9use Wallabag\UserBundle\Entity\User; 11use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Repository\TagRepository;
11use Wallabag\CoreBundle\Helper\RuleBasedTagger; 12use Wallabag\CoreBundle\Helper\RuleBasedTagger;
13use Graby\Graby;
12 14
13class ContentProxyTest extends \PHPUnit_Framework_TestCase 15class ContentProxyTest extends \PHPUnit_Framework_TestCase
14{ 16{
@@ -36,7 +38,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
36 ]); 38 ]);
37 39
38 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 40 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
39 $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); 41 $entry = new Entry(new User());
42 $proxy->updateEntry($entry, 'http://user@:80');
40 43
41 $this->assertEquals('http://user@:80', $entry->getUrl()); 44 $this->assertEquals('http://user@:80', $entry->getUrl());
42 $this->assertEmpty($entry->getTitle()); 45 $this->assertEmpty($entry->getTitle());
@@ -70,7 +73,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
70 ]); 73 ]);
71 74
72 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 75 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
73 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 76 $entry = new Entry(new User());
77 $proxy->updateEntry($entry, 'http://0.0.0.0');
74 78
75 $this->assertEquals('http://0.0.0.0', $entry->getUrl()); 79 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
76 $this->assertEmpty($entry->getTitle()); 80 $this->assertEmpty($entry->getTitle());
@@ -109,7 +113,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
109 ]); 113 ]);
110 114
111 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 115 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
112 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); 116 $entry = new Entry(new User());
117 $proxy->updateEntry($entry, 'http://domain.io');
113 118
114 $this->assertEquals('http://domain.io', $entry->getUrl()); 119 $this->assertEquals('http://domain.io', $entry->getUrl());
115 $this->assertEquals('my title', $entry->getTitle()); 120 $this->assertEquals('my title', $entry->getTitle());
@@ -150,7 +155,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
150 ]); 155 ]);
151 156
152 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 157 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
153 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 158 $entry = new Entry(new User());
159 $proxy->updateEntry($entry, 'http://0.0.0.0');
154 160
155 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 161 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
156 $this->assertEquals('this is my title', $entry->getTitle()); 162 $this->assertEquals('this is my title', $entry->getTitle());
@@ -191,7 +197,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
191 ]); 197 ]);
192 198
193 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 199 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
194 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 200 $entry = new Entry(new User());
201 $proxy->updateEntry($entry, 'http://0.0.0.0');
195 202
196 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 203 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
197 $this->assertEquals('this is my title', $entry->getTitle()); 204 $this->assertEquals('this is my title', $entry->getTitle());
@@ -210,16 +217,62 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
210 $tagger->expects($this->once()) 217 $tagger->expects($this->once())
211 ->method('tag'); 218 ->method('tag');
212 219
213 $graby = $this->getMockBuilder('Graby\Graby')->getMock(); 220 $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
221 $entry = new Entry(new User());
222 $proxy->updateEntry(
223 $entry,
224 'http://0.0.0.0',
225 [
226 'html' => str_repeat('this is my content', 325),
227 'title' => 'this is my title',
228 'url' => 'http://1.1.1.1',
229 'content_type' => 'text/html',
230 'language' => 'fr',
231 'date' => '1395635872',
232 'authors' => ['Jeremy', 'Nico', 'Thomas'],
233 'all_headers' => [
234 'Cache-Control' => 'no-cache',
235 ],
236 ]
237 );
214 238
215 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 239 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
216 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 240 $this->assertEquals('this is my title', $entry->getTitle());
217 'html' => str_repeat('this is my content', 325), 241 $this->assertContains('this is my content', $entry->getContent());
218 'title' => 'this is my title', 242 $this->assertEquals('text/html', $entry->getMimetype());
219 'url' => 'http://1.1.1.1', 243 $this->assertEquals('fr', $entry->getLanguage());
220 'content_type' => 'text/html', 244 $this->assertEquals(4.0, $entry->getReadingTime());
221 'language' => 'fr', 245 $this->assertEquals('1.1.1.1', $entry->getDomainName());
222 ]); 246 $this->assertEquals('24/03/2014', $entry->getPublishedAt()->format('d/m/Y'));
247 $this->assertContains('Jeremy', $entry->getPublishedBy());
248 $this->assertContains('Nico', $entry->getPublishedBy());
249 $this->assertContains('Thomas', $entry->getPublishedBy());
250 $this->assertContains('no-cache', $entry->getHeaders());
251 }
252
253 public function testWithForcedContentAndDatetime()
254 {
255 $tagger = $this->getTaggerMock();
256 $tagger->expects($this->once())
257 ->method('tag');
258
259 $logHandler = new TestHandler();
260 $logger = new Logger('test', [$logHandler]);
261
262 $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage);
263 $entry = new Entry(new User());
264 $proxy->updateEntry(
265 $entry,
266 'http://1.1.1.1',
267 [
268 'html' => str_repeat('this is my content', 325),
269 'title' => 'this is my title',
270 'url' => 'http://1.1.1.1',
271 'content_type' => 'text/html',
272 'language' => 'fr',
273 'date' => '2016-09-08T11:55:58+0200',
274 ]
275 );
223 276
224 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 277 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
225 $this->assertEquals('this is my title', $entry->getTitle()); 278 $this->assertEquals('this is my title', $entry->getTitle());
@@ -228,32 +281,126 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
228 $this->assertEquals('fr', $entry->getLanguage()); 281 $this->assertEquals('fr', $entry->getLanguage());
229 $this->assertEquals(4.0, $entry->getReadingTime()); 282 $this->assertEquals(4.0, $entry->getReadingTime());
230 $this->assertEquals('1.1.1.1', $entry->getDomainName()); 283 $this->assertEquals('1.1.1.1', $entry->getDomainName());
284 $this->assertEquals('08/09/2016', $entry->getPublishedAt()->format('d/m/Y'));
231 } 285 }
232 286
233 public function testTaggerThrowException() 287 public function testWithForcedContentAndBadDate()
234 { 288 {
235 $graby = $this->getMockBuilder('Graby\Graby') 289 $tagger = $this->getTaggerMock();
236 ->disableOriginalConstructor() 290 $tagger->expects($this->once())
237 ->getMock(); 291 ->method('tag');
238 292
293 $logger = new Logger('foo');
294 $handler = new TestHandler();
295 $logger->pushHandler($handler);
296
297 $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage);
298 $entry = new Entry(new User());
299 $proxy->updateEntry(
300 $entry,
301 'http://1.1.1.1',
302 [
303 'html' => str_repeat('this is my content', 325),
304 'title' => 'this is my title',
305 'url' => 'http://1.1.1.1',
306 'content_type' => 'text/html',
307 'language' => 'fr',
308 'date' => '01 02 2012',
309 ]
310 );
311
312 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
313 $this->assertEquals('this is my title', $entry->getTitle());
314 $this->assertContains('this is my content', $entry->getContent());
315 $this->assertEquals('text/html', $entry->getMimetype());
316 $this->assertEquals('fr', $entry->getLanguage());
317 $this->assertEquals(4.0, $entry->getReadingTime());
318 $this->assertEquals('1.1.1.1', $entry->getDomainName());
319 $this->assertNull($entry->getPublishedAt());
320
321 $records = $handler->getRecords();
322
323 $this->assertCount(1, $records);
324 $this->assertContains('Error while defining date', $records[0]['message']);
325 }
326
327 public function testTaggerThrowException()
328 {
239 $tagger = $this->getTaggerMock(); 329 $tagger = $this->getTaggerMock();
240 $tagger->expects($this->once()) 330 $tagger->expects($this->once())
241 ->method('tag') 331 ->method('tag')
242 ->will($this->throwException(new \Exception())); 332 ->will($this->throwException(new \Exception()));
243 333
244 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); 334 $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
245 335 $entry = new Entry(new User());
246 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 336 $proxy->updateEntry(
247 'html' => str_repeat('this is my content', 325), 337 $entry,
248 'title' => 'this is my title', 338 'http://1.1.1.1',
249 'url' => 'http://1.1.1.1', 339 [
250 'content_type' => 'text/html', 340 'html' => str_repeat('this is my content', 325),
251 'language' => 'fr', 341 'title' => 'this is my title',
252 ]); 342 'url' => 'http://1.1.1.1',
343 'content_type' => 'text/html',
344 'language' => 'fr',
345 ]
346 );
253 347
254 $this->assertCount(0, $entry->getTags()); 348 $this->assertCount(0, $entry->getTags());
255 } 349 }
256 350
351 public function dataForCrazyHtml()
352 {
353 return [
354 'script and comment' => [
355 '<strong>Script inside:</strong> <!--[if gte IE 4]><script>alert(\'lol\');</script><![endif]--><br />',
356 'lol',
357 ],
358 'script' => [
359 '<strong>Script inside:</strong><script>alert(\'lol\');</script>',
360 'script',
361 ],
362 ];
363 }
364
365 /**
366 * @dataProvider dataForCrazyHtml
367 */
368 public function testWithCrazyHtmlContent($html, $escapedString)
369 {
370 $tagger = $this->getTaggerMock();
371 $tagger->expects($this->once())
372 ->method('tag');
373
374 $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
375 $entry = new Entry(new User());
376 $proxy->updateEntry(
377 $entry,
378 'http://1.1.1.1',
379 [
380 'html' => $html,
381 'title' => 'this is my title',
382 'url' => 'http://1.1.1.1',
383 'content_type' => 'text/html',
384 'language' => 'fr',
385 'status' => '200',
386 'open_graph' => [
387 'og_title' => 'my OG title',
388 'og_description' => 'OG desc',
389 'og_image' => 'http://3.3.3.3/cover.jpg',
390 ],
391 ]
392 );
393
394 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
395 $this->assertEquals('this is my title', $entry->getTitle());
396 $this->assertNotContains($escapedString, $entry->getContent());
397 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
398 $this->assertEquals('text/html', $entry->getMimetype());
399 $this->assertEquals('fr', $entry->getLanguage());
400 $this->assertEquals('200', $entry->getHttpStatus());
401 $this->assertEquals('1.1.1.1', $entry->getDomainName());
402 }
403
257 private function getTaggerMock() 404 private function getTaggerMock()
258 { 405 {
259 return $this->getMockBuilder(RuleBasedTagger::class) 406 return $this->getMockBuilder(RuleBasedTagger::class)
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
index 85f12d87..9125f8dc 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
13class DownloadImagesTest extends \PHPUnit_Framework_TestCase 13class 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&amp;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()
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/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
3namespace Tests\Wallabag\CoreBundle; 3namespace Tests\Wallabag\CoreBundle;
4 4
5use Symfony\Bundle\FrameworkBundle\Client;
6use Symfony\Bundle\FrameworkBundle\Console\Application;
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 7use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6use Symfony\Component\BrowserKit\Cookie; 8use Symfony\Component\BrowserKit\Cookie;
9use Symfony\Component\Console\Input\ArrayInput;
10use Symfony\Component\Console\Output\NullOutput;
11use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\UserBundle\Entity\User;
7 13
8abstract class WallabagCoreTestCase extends WebTestCase 14abstract 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 */