diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /tests/Wallabag/CoreBundle | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'tests/Wallabag/CoreBundle')
30 files changed, 2187 insertions, 805 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php new file mode 100644 index 00000000..38e8dd07 --- /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 Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
8 | use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; | ||
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..210b2ab6 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php | |||
@@ -4,13 +4,13 @@ namespace Tests\Wallabag\CoreBundle\Command; | |||
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | 5 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
6 | use Symfony\Component\Console\Tester\CommandTester; | 6 | use Symfony\Component\Console\Tester\CommandTester; |
7 | use Wallabag\CoreBundle\Command\ExportCommand; | ||
8 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
8 | use Wallabag\CoreBundle\Command\ExportCommand; | ||
9 | 9 | ||
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,8 @@ 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...', $tester->getDisplay()); |
59 | $this->assertContains('Done', $tester->getDisplay()); | ||
59 | $this->assertFileExists('admin-export.json'); | 60 | $this->assertFileExists('admin-export.json'); |
60 | } | 61 | } |
61 | 62 | ||
@@ -70,7 +71,7 @@ class ExportCommandTest extends WallabagCoreTestCase | |||
70 | $tester->execute([ | 71 | $tester->execute([ |
71 | 'command' => $command->getName(), | 72 | 'command' => $command->getName(), |
72 | 'username' => 'admin', | 73 | 'username' => 'admin', |
73 | 'filepath' => 'specialexport.json' | 74 | 'filepath' => 'specialexport.json', |
74 | ]); | 75 | ]); |
75 | 76 | ||
76 | $this->assertFileExists('specialexport.json'); | 77 | $this->assertFileExists('specialexport.json'); |
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 1bfd41d5..f684a206 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -2,15 +2,18 @@ | |||
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; |
10 | use Symfony\Component\Console\Tester\CommandTester; | 13 | use Symfony\Component\Console\Tester\CommandTester; |
11 | use Wallabag\CoreBundle\Command\InstallCommand; | ||
12 | use Tests\Wallabag\CoreBundle\Mock\InstallCommandMock; | 14 | use Tests\Wallabag\CoreBundle\Mock\InstallCommandMock; |
13 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 15 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
16 | use Wallabag\CoreBundle\Command\InstallCommand; | ||
14 | 17 | ||
15 | class InstallCommandTest extends WallabagCoreTestCase | 18 | class InstallCommandTest extends WallabagCoreTestCase |
16 | { | 19 | { |
@@ -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/ListUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php new file mode 100644 index 00000000..9068cf59 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php | |||
@@ -0,0 +1,75 @@ | |||
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\ListUserCommand; | ||
9 | |||
10 | class ListUserCommandTest extends WallabagCoreTestCase | ||
11 | { | ||
12 | public function testRunListUserCommand() | ||
13 | { | ||
14 | $application = new Application($this->getClient()->getKernel()); | ||
15 | $application->add(new ListUserCommand()); | ||
16 | |||
17 | $command = $application->find('wallabag:user:list'); | ||
18 | |||
19 | $tester = new CommandTester($command); | ||
20 | $tester->execute([ | ||
21 | 'command' => $command->getName(), | ||
22 | ]); | ||
23 | |||
24 | $this->assertContains('3/3 user(s) displayed.', $tester->getDisplay()); | ||
25 | } | ||
26 | |||
27 | public function testRunListUserCommandWithLimit() | ||
28 | { | ||
29 | $application = new Application($this->getClient()->getKernel()); | ||
30 | $application->add(new ListUserCommand()); | ||
31 | |||
32 | $command = $application->find('wallabag:user:list'); | ||
33 | |||
34 | $tester = new CommandTester($command); | ||
35 | $tester->execute([ | ||
36 | 'command' => $command->getName(), | ||
37 | '--limit' => 2, | ||
38 | ]); | ||
39 | |||
40 | $this->assertContains('2/3 user(s) displayed.', $tester->getDisplay()); | ||
41 | } | ||
42 | |||
43 | public function testRunListUserCommandWithSearch() | ||
44 | { | ||
45 | $application = new Application($this->getClient()->getKernel()); | ||
46 | $application->add(new ListUserCommand()); | ||
47 | |||
48 | $command = $application->find('wallabag:user:list'); | ||
49 | |||
50 | $tester = new CommandTester($command); | ||
51 | $tester->execute([ | ||
52 | 'command' => $command->getName(), | ||
53 | 'search' => 'boss', | ||
54 | ]); | ||
55 | |||
56 | $this->assertContains('1/3 (filtered) user(s) displayed.', $tester->getDisplay()); | ||
57 | } | ||
58 | |||
59 | public function testRunListUserCommandWithSearchAndLimit() | ||
60 | { | ||
61 | $application = new Application($this->getClient()->getKernel()); | ||
62 | $application->add(new ListUserCommand()); | ||
63 | |||
64 | $command = $application->find('wallabag:user:list'); | ||
65 | |||
66 | $tester = new CommandTester($command); | ||
67 | $tester->execute([ | ||
68 | 'command' => $command->getName(), | ||
69 | 'search' => 'bo', | ||
70 | '--limit' => 1, | ||
71 | ]); | ||
72 | |||
73 | $this->assertContains('1/3 (filtered) user(s) displayed.', $tester->getDisplay()); | ||
74 | } | ||
75 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php new file mode 100644 index 00000000..63c068b4 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php | |||
@@ -0,0 +1,115 @@ | |||
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\ReloadEntryCommand; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
10 | |||
11 | class ReloadEntryCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | 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'; | ||
14 | |||
15 | /** | ||
16 | * @var entry | ||
17 | */ | ||
18 | public $adminEntry; | ||
19 | |||
20 | /** | ||
21 | * @var Entry | ||
22 | */ | ||
23 | public $bobEntry; | ||
24 | |||
25 | public function setUp() | ||
26 | { | ||
27 | parent::setUp(); | ||
28 | |||
29 | $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); | ||
30 | |||
31 | $user = $userRepository->findOneByUserName('admin'); | ||
32 | $this->adminEntry = new Entry($user); | ||
33 | $this->adminEntry->setUrl($this->url); | ||
34 | $this->adminEntry->setTitle('title foo'); | ||
35 | $this->adminEntry->setContent(''); | ||
36 | $this->getEntityManager()->persist($this->adminEntry); | ||
37 | |||
38 | $user = $userRepository->findOneByUserName('bob'); | ||
39 | $this->bobEntry = new Entry($user); | ||
40 | $this->bobEntry->setUrl($this->url); | ||
41 | $this->bobEntry->setTitle('title foo'); | ||
42 | $this->bobEntry->setContent(''); | ||
43 | $this->getEntityManager()->persist($this->bobEntry); | ||
44 | |||
45 | $this->getEntityManager()->flush(); | ||
46 | } | ||
47 | |||
48 | public function testRunReloadEntryCommand() | ||
49 | { | ||
50 | $application = new Application($this->getClient()->getKernel()); | ||
51 | $application->add(new ReloadEntryCommand()); | ||
52 | |||
53 | $command = $application->find('wallabag:entry:reload'); | ||
54 | $tester = new CommandTester($command); | ||
55 | $tester->execute([ | ||
56 | 'command' => $command->getName(), | ||
57 | ], [ | ||
58 | 'interactive' => false, | ||
59 | ]); | ||
60 | |||
61 | $reloadedEntries = $this->getClient() | ||
62 | ->getContainer() | ||
63 | ->get('wallabag_core.entry_repository') | ||
64 | ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); | ||
65 | |||
66 | foreach ($reloadedEntries as $reloadedEntry) { | ||
67 | $this->assertNotEmpty($reloadedEntry->getContent()); | ||
68 | } | ||
69 | |||
70 | $this->assertContains('Done', $tester->getDisplay()); | ||
71 | } | ||
72 | |||
73 | public function testRunReloadEntryWithUsernameCommand() | ||
74 | { | ||
75 | $application = new Application($this->getClient()->getKernel()); | ||
76 | $application->add(new ReloadEntryCommand()); | ||
77 | |||
78 | $command = $application->find('wallabag:entry:reload'); | ||
79 | $tester = new CommandTester($command); | ||
80 | $tester->execute([ | ||
81 | 'command' => $command->getName(), | ||
82 | 'username' => 'admin', | ||
83 | ], [ | ||
84 | 'interactive' => false, | ||
85 | ]); | ||
86 | |||
87 | $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); | ||
88 | |||
89 | $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); | ||
90 | $this->assertNotEmpty($reloadedAdminEntry->getContent()); | ||
91 | |||
92 | $reloadedBobEntry = $entryRepository->find($this->bobEntry->getId()); | ||
93 | $this->assertEmpty($reloadedBobEntry->getContent()); | ||
94 | |||
95 | $this->assertContains('Done', $tester->getDisplay()); | ||
96 | } | ||
97 | |||
98 | public function testRunReloadEntryWithoutEntryCommand() | ||
99 | { | ||
100 | $application = new Application($this->getClient()->getKernel()); | ||
101 | $application->add(new ReloadEntryCommand()); | ||
102 | |||
103 | $command = $application->find('wallabag:entry:reload'); | ||
104 | $tester = new CommandTester($command); | ||
105 | $tester->execute([ | ||
106 | 'command' => $command->getName(), | ||
107 | 'username' => 'empty', | ||
108 | ], [ | ||
109 | 'interactive' => false, | ||
110 | ]); | ||
111 | |||
112 | $this->assertContains('No entry to reload', $tester->getDisplay()); | ||
113 | $this->assertNotContains('Done', $tester->getDisplay()); | ||
114 | } | ||
115 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php new file mode 100644 index 00000000..9b34f2a0 --- /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..b1e56a10 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php | |||
@@ -4,13 +4,13 @@ namespace Tests\Wallabag\CoreBundle\Command; | |||
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | 5 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
6 | use Symfony\Component\Console\Tester\CommandTester; | 6 | use Symfony\Component\Console\Tester\CommandTester; |
7 | use Wallabag\CoreBundle\Command\TagAllCommand; | ||
8 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
8 | use Wallabag\CoreBundle\Command\TagAllCommand; | ||
9 | 9 | ||
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() |
@@ -55,6 +55,7 @@ class TagAllCommandTest extends WallabagCoreTestCase | |||
55 | 'username' => 'admin', | 55 | 'username' => 'admin', |
56 | ]); | 56 | ]); |
57 | 57 | ||
58 | $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay()); | 58 | $this->assertContains('Tagging entries for user admin...', $tester->getDisplay()); |
59 | $this->assertContains('Done', $tester->getDisplay()); | ||
59 | } | 60 | } |
60 | } | 61 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index beb0598a..e4bf0998 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -3,11 +3,11 @@ | |||
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\AnnotationBundle\Entity\Annotation; | ||
6 | use Wallabag\CoreBundle\Entity\Config; | 7 | use Wallabag\CoreBundle\Entity\Config; |
7 | use Wallabag\UserBundle\Entity\User; | ||
8 | use Wallabag\CoreBundle\Entity\Entry; | 8 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Entity\Tag; | 9 | use Wallabag\CoreBundle\Entity\Tag; |
10 | use Wallabag\AnnotationBundle\Entity\Annotation; | 10 | use Wallabag\UserBundle\Entity\User; |
11 | 11 | ||
12 | class ConfigControllerTest extends WallabagCoreTestCase | 12 | class ConfigControllerTest extends WallabagCoreTestCase |
13 | { | 13 | { |
@@ -17,7 +17,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
17 | 17 | ||
18 | $client->request('GET', '/new'); | 18 | $client->request('GET', '/new'); |
19 | 19 | ||
20 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 20 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
21 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | 21 | $this->assertContains('login', $client->getResponse()->headers->get('location')); |
22 | } | 22 | } |
23 | 23 | ||
@@ -28,7 +28,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
28 | 28 | ||
29 | $crawler = $client->request('GET', '/config'); | 29 | $crawler = $client->request('GET', '/config'); |
30 | 30 | ||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 31 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
32 | 32 | ||
33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | 33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | 34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); |
@@ -43,7 +43,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
43 | 43 | ||
44 | $crawler = $client->request('GET', '/config'); | 44 | $crawler = $client->request('GET', '/config'); |
45 | 45 | ||
46 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 46 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
47 | 47 | ||
48 | $form = $crawler->filter('button[id=config_save]')->form(); | 48 | $form = $crawler->filter('button[id=config_save]')->form(); |
49 | 49 | ||
@@ -57,7 +57,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
57 | 57 | ||
58 | $client->submit($form, $data); | 58 | $client->submit($form, $data); |
59 | 59 | ||
60 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 60 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
61 | 61 | ||
62 | $crawler = $client->followRedirect(); | 62 | $crawler = $client->followRedirect(); |
63 | 63 | ||
@@ -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 = [ |
@@ -122,13 +131,13 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
122 | 131 | ||
123 | $crawler = $client->request('GET', '/config'); | 132 | $crawler = $client->request('GET', '/config'); |
124 | 133 | ||
125 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 134 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
126 | 135 | ||
127 | $form = $crawler->filter('button[id=config_save]')->form(); | 136 | $form = $crawler->filter('button[id=config_save]')->form(); |
128 | 137 | ||
129 | $crawler = $client->submit($form, $data); | 138 | $crawler = $client->submit($form, $data); |
130 | 139 | ||
131 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 140 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
132 | 141 | ||
133 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | 142 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
134 | $this->assertContains('This value should not be blank', $alert[0]); | 143 | $this->assertContains('This value should not be blank', $alert[0]); |
@@ -182,13 +191,13 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
182 | 191 | ||
183 | $crawler = $client->request('GET', '/config'); | 192 | $crawler = $client->request('GET', '/config'); |
184 | 193 | ||
185 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 194 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
186 | 195 | ||
187 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | 196 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); |
188 | 197 | ||
189 | $crawler = $client->submit($form, $data); | 198 | $crawler = $client->submit($form, $data); |
190 | 199 | ||
191 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 200 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
192 | 201 | ||
193 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | 202 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
194 | $this->assertContains($expectedMessage, $alert[0]); | 203 | $this->assertContains($expectedMessage, $alert[0]); |
@@ -201,7 +210,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
201 | 210 | ||
202 | $crawler = $client->request('GET', '/config'); | 211 | $crawler = $client->request('GET', '/config'); |
203 | 212 | ||
204 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 213 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
205 | 214 | ||
206 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | 215 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); |
207 | 216 | ||
@@ -213,7 +222,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
213 | 222 | ||
214 | $client->submit($form, $data); | 223 | $client->submit($form, $data); |
215 | 224 | ||
216 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 225 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
217 | 226 | ||
218 | $crawler = $client->followRedirect(); | 227 | $crawler = $client->followRedirect(); |
219 | 228 | ||
@@ -250,13 +259,13 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
250 | 259 | ||
251 | $crawler = $client->request('GET', '/config'); | 260 | $crawler = $client->request('GET', '/config'); |
252 | 261 | ||
253 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 262 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
254 | 263 | ||
255 | $form = $crawler->filter('button[id=update_user_save]')->form(); | 264 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
256 | 265 | ||
257 | $crawler = $client->submit($form, $data); | 266 | $crawler = $client->submit($form, $data); |
258 | 267 | ||
259 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 268 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
260 | 269 | ||
261 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | 270 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
262 | $this->assertContains($expectedMessage, $alert[0]); | 271 | $this->assertContains($expectedMessage, $alert[0]); |
@@ -269,7 +278,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
269 | 278 | ||
270 | $crawler = $client->request('GET', '/config'); | 279 | $crawler = $client->request('GET', '/config'); |
271 | 280 | ||
272 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 281 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
273 | 282 | ||
274 | $form = $crawler->filter('button[id=update_user_save]')->form(); | 283 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
275 | 284 | ||
@@ -280,7 +289,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
280 | 289 | ||
281 | $client->submit($form, $data); | 290 | $client->submit($form, $data); |
282 | 291 | ||
283 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 292 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
284 | 293 | ||
285 | $crawler = $client->followRedirect(); | 294 | $crawler = $client->followRedirect(); |
286 | 295 | ||
@@ -310,13 +319,13 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
310 | 319 | ||
311 | $crawler = $client->request('GET', '/config'); | 320 | $crawler = $client->request('GET', '/config'); |
312 | 321 | ||
313 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 322 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
314 | 323 | ||
315 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 324 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
316 | $this->assertContains('config.form_rss.no_token', $body[0]); | 325 | $this->assertContains('config.form_rss.no_token', $body[0]); |
317 | 326 | ||
318 | $client->request('GET', '/generate-token'); | 327 | $client->request('GET', '/generate-token'); |
319 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 328 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
320 | 329 | ||
321 | $crawler = $client->followRedirect(); | 330 | $crawler = $client->followRedirect(); |
322 | 331 | ||
@@ -337,7 +346,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
337 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | 346 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] |
338 | ); | 347 | ); |
339 | 348 | ||
340 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 349 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
341 | $content = json_decode($client->getResponse()->getContent(), true); | 350 | $content = json_decode($client->getResponse()->getContent(), true); |
342 | $this->assertArrayHasKey('token', $content); | 351 | $this->assertArrayHasKey('token', $content); |
343 | } | 352 | } |
@@ -349,7 +358,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
349 | 358 | ||
350 | $crawler = $client->request('GET', '/config'); | 359 | $crawler = $client->request('GET', '/config'); |
351 | 360 | ||
352 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 361 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
353 | 362 | ||
354 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 363 | $form = $crawler->filter('button[id=rss_config_save]')->form(); |
355 | 364 | ||
@@ -359,7 +368,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
359 | 368 | ||
360 | $client->submit($form, $data); | 369 | $client->submit($form, $data); |
361 | 370 | ||
362 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 371 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
363 | 372 | ||
364 | $crawler = $client->followRedirect(); | 373 | $crawler = $client->followRedirect(); |
365 | 374 | ||
@@ -394,13 +403,13 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
394 | 403 | ||
395 | $crawler = $client->request('GET', '/config'); | 404 | $crawler = $client->request('GET', '/config'); |
396 | 405 | ||
397 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 406 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
398 | 407 | ||
399 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 408 | $form = $crawler->filter('button[id=rss_config_save]')->form(); |
400 | 409 | ||
401 | $crawler = $client->submit($form, $data); | 410 | $crawler = $client->submit($form, $data); |
402 | 411 | ||
403 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 412 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
404 | 413 | ||
405 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | 414 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
406 | $this->assertContains($expectedMessage, $alert[0]); | 415 | $this->assertContains($expectedMessage, $alert[0]); |
@@ -409,11 +418,12 @@ 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'); |
415 | 425 | ||
416 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 426 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
417 | 427 | ||
418 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | 428 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); |
419 | 429 | ||
@@ -424,7 +434,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
424 | 434 | ||
425 | $client->submit($form, $data); | 435 | $client->submit($form, $data); |
426 | 436 | ||
427 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 437 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
428 | 438 | ||
429 | $crawler = $client->followRedirect(); | 439 | $crawler = $client->followRedirect(); |
430 | 440 | ||
@@ -433,7 +443,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
433 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | 443 | $editLink = $crawler->filter('.mode_edit')->last()->link(); |
434 | 444 | ||
435 | $crawler = $client->click($editLink); | 445 | $crawler = $client->click($editLink); |
436 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 446 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
437 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); | 447 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); |
438 | 448 | ||
439 | $crawler = $client->followRedirect(); | 449 | $crawler = $client->followRedirect(); |
@@ -447,7 +457,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
447 | 457 | ||
448 | $client->submit($form, $data); | 458 | $client->submit($form, $data); |
449 | 459 | ||
450 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 460 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
451 | 461 | ||
452 | $crawler = $client->followRedirect(); | 462 | $crawler = $client->followRedirect(); |
453 | 463 | ||
@@ -458,7 +468,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
458 | $deleteLink = $crawler->filter('.delete')->last()->link(); | 468 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
459 | 469 | ||
460 | $crawler = $client->click($deleteLink); | 470 | $crawler = $client->click($deleteLink); |
461 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 471 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
462 | 472 | ||
463 | $crawler = $client->followRedirect(); | 473 | $crawler = $client->followRedirect(); |
464 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); | 474 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
@@ -500,13 +510,13 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
500 | 510 | ||
501 | $crawler = $client->request('GET', '/config'); | 511 | $crawler = $client->request('GET', '/config'); |
502 | 512 | ||
503 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 513 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
504 | 514 | ||
505 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | 515 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); |
506 | 516 | ||
507 | $crawler = $client->submit($form, $data); | 517 | $crawler = $client->submit($form, $data); |
508 | 518 | ||
509 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 519 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
510 | 520 | ||
511 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 521 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
512 | 522 | ||
@@ -522,7 +532,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
522 | 532 | ||
523 | $crawler = $client->request('GET', '/config'); | 533 | $crawler = $client->request('GET', '/config'); |
524 | 534 | ||
525 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 535 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
526 | 536 | ||
527 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | 537 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); |
528 | 538 | ||
@@ -531,7 +541,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
531 | 'tagging_rule[tags]' => 'cool tag', | 541 | 'tagging_rule[tags]' => 'cool tag', |
532 | ]); | 542 | ]); |
533 | 543 | ||
534 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 544 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
535 | 545 | ||
536 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 546 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
537 | 547 | ||
@@ -547,9 +557,9 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
547 | ->getRepository('WallabagCoreBundle:TaggingRule') | 557 | ->getRepository('WallabagCoreBundle:TaggingRule') |
548 | ->findAll()[0]; | 558 | ->findAll()[0]; |
549 | 559 | ||
550 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); | 560 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); |
551 | 561 | ||
552 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 562 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
553 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 563 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
554 | $this->assertContains('You can not access this tagging rule', $body[0]); | 564 | $this->assertContains('You can not access this tagging rule', $body[0]); |
555 | } | 565 | } |
@@ -563,9 +573,9 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
563 | ->getRepository('WallabagCoreBundle:TaggingRule') | 573 | ->getRepository('WallabagCoreBundle:TaggingRule') |
564 | ->findAll()[0]; | 574 | ->findAll()[0]; |
565 | 575 | ||
566 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); | 576 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); |
567 | 577 | ||
568 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 578 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
569 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 579 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
570 | $this->assertContains('You can not access this tagging rule', $body[0]); | 580 | $this->assertContains('You can not access this tagging rule', $body[0]); |
571 | } | 581 | } |
@@ -581,7 +591,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
581 | 591 | ||
582 | $crawler = $client->request('GET', '/config'); | 592 | $crawler = $client->request('GET', '/config'); |
583 | 593 | ||
584 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 594 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
585 | 595 | ||
586 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | 596 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); |
587 | 597 | ||
@@ -593,7 +603,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
593 | 603 | ||
594 | $client->submit($form, $data); | 604 | $client->submit($form, $data); |
595 | 605 | ||
596 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 606 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
597 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | 607 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
598 | 608 | ||
599 | $config->set('demo_mode_enabled', 0); | 609 | $config->set('demo_mode_enabled', 0); |
@@ -632,7 +642,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
632 | $this->assertNotContains('config.form_user.delete.button', $body[0]); | 642 | $this->assertNotContains('config.form_user.delete.button', $body[0]); |
633 | 643 | ||
634 | $client->request('GET', '/account/delete'); | 644 | $client->request('GET', '/account/delete'); |
635 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 645 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
636 | 646 | ||
637 | $user = $em | 647 | $user = $em |
638 | ->getRepository('WallabagUserBundle:User') | 648 | ->getRepository('WallabagUserBundle:User') |
@@ -682,7 +692,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
682 | // that this entry is also deleted | 692 | // that this entry is also deleted |
683 | $crawler = $client->request('GET', '/new'); | 693 | $crawler = $client->request('GET', '/new'); |
684 | 694 | ||
685 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 695 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
686 | 696 | ||
687 | $form = $crawler->filter('form[name=entry]')->form(); | 697 | $form = $crawler->filter('form[name=entry]')->form(); |
688 | $data = [ | 698 | $data = [ |
@@ -690,14 +700,14 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
690 | ]; | 700 | ]; |
691 | 701 | ||
692 | $client->submit($form, $data); | 702 | $client->submit($form, $data); |
693 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 703 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
694 | 704 | ||
695 | $crawler = $client->request('GET', '/config'); | 705 | $crawler = $client->request('GET', '/config'); |
696 | 706 | ||
697 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); | 707 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); |
698 | 708 | ||
699 | $client->click($deleteLink); | 709 | $client->click($deleteLink); |
700 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 710 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
701 | 711 | ||
702 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 712 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
703 | $user = $em | 713 | $user = $em |
@@ -757,11 +767,11 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
757 | // reset annotations | 767 | // reset annotations |
758 | $crawler = $client->request('GET', '/config#set3'); | 768 | $crawler = $client->request('GET', '/config#set3'); |
759 | 769 | ||
760 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 770 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
761 | 771 | ||
762 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | 772 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); |
763 | 773 | ||
764 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 774 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
765 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | 775 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
766 | 776 | ||
767 | $annotationsReset = $em | 777 | $annotationsReset = $em |
@@ -773,34 +783,110 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
773 | // reset tags | 783 | // reset tags |
774 | $crawler = $client->request('GET', '/config#set3'); | 784 | $crawler = $client->request('GET', '/config#set3'); |
775 | 785 | ||
776 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 786 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
777 | 787 | ||
778 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); | 788 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); |
779 | 789 | ||
780 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 790 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
781 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | 791 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
782 | 792 | ||
783 | $tagReset = $em | 793 | $tagReset = $em |
784 | ->getRepository('WallabagCoreBundle:Tag') | 794 | ->getRepository('WallabagCoreBundle:Tag') |
785 | ->countAllTags($user->getId()); | 795 | ->countAllTags($user->getId()); |
786 | 796 | ||
787 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | 797 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
788 | 798 | ||
789 | // reset entries | 799 | // reset entries |
790 | $crawler = $client->request('GET', '/config#set3'); | 800 | $crawler = $client->request('GET', '/config#set3'); |
791 | 801 | ||
792 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 802 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
793 | 803 | ||
794 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | 804 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); |
795 | 805 | ||
796 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 806 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
797 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | 807 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
798 | 808 | ||
799 | $entryReset = $em | 809 | $entryReset = $em |
800 | ->getRepository('WallabagCoreBundle:Entry') | 810 | ->getRepository('WallabagCoreBundle:Entry') |
801 | ->countAllEntriesByUsername($user->getId()); | 811 | ->countAllEntriesByUser($user->getId()); |
812 | |||
813 | $this->assertSame(0, $entryReset, 'Entries were reset'); | ||
814 | } | ||
815 | |||
816 | public function testResetArchivedEntries() | ||
817 | { | ||
818 | $this->logInAs('empty'); | ||
819 | $client = $this->getClient(); | ||
820 | |||
821 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
802 | 822 | ||
803 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | 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->assertSame(200, $client->getResponse()->getStatusCode()); | ||
867 | |||
868 | $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); | ||
869 | |||
870 | $this->assertSame(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->assertSame(1, $entryReset, 'Entries were reset'); | ||
878 | |||
879 | $tagReset = $em | ||
880 | ->getRepository('WallabagCoreBundle:Tag') | ||
881 | ->countAllTags($user->getId()); | ||
882 | |||
883 | $this->assertSame(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'); | ||
804 | } | 890 | } |
805 | 891 | ||
806 | public function testResetEntriesCascade() | 892 | public function testResetEntriesCascade() |
@@ -834,24 +920,24 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
834 | 920 | ||
835 | $crawler = $client->request('GET', '/config#set3'); | 921 | $crawler = $client->request('GET', '/config#set3'); |
836 | 922 | ||
837 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 923 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
838 | 924 | ||
839 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | 925 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); |
840 | 926 | ||
841 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 927 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
842 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | 928 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
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->assertSame(0, $entryReset, 'Entries were reset'); |
849 | 935 | ||
850 | $tagReset = $em | 936 | $tagReset = $em |
851 | ->getRepository('WallabagCoreBundle:Tag') | 937 | ->getRepository('WallabagCoreBundle:Tag') |
852 | ->countAllTags($user->getId()); | 938 | ->countAllTags($user->getId()); |
853 | 939 | ||
854 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | 940 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
855 | 941 | ||
856 | $annotationsReset = $em | 942 | $annotationsReset = $em |
857 | ->getRepository('WallabagAnnotationBundle:Annotation') | 943 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -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..ca275b32 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -5,18 +5,35 @@ namespace Tests\Wallabag\CoreBundle\Controller; | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Config; | 6 | use Wallabag\CoreBundle\Entity\Config; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\CoreBundle\Entity\SiteCredential; | ||
8 | 9 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | 10 | class EntryControllerTest extends WallabagCoreTestCase |
10 | { | 11 | { |
12 | 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'; | 13 | 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 | 14 | ||
15 | /** | ||
16 | * @after | ||
17 | * | ||
18 | * Ensure download_images_enabled is disabled after each script | ||
19 | */ | ||
20 | public function tearDownImagesEnabled() | ||
21 | { | ||
22 | if ($this->downloadImagesEnabled) { | ||
23 | $client = static::createClient(); | ||
24 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | ||
25 | |||
26 | $this->downloadImagesEnabled = false; | ||
27 | } | ||
28 | } | ||
29 | |||
13 | public function testLogin() | 30 | public function testLogin() |
14 | { | 31 | { |
15 | $client = $this->getClient(); | 32 | $client = $this->getClient(); |
16 | 33 | ||
17 | $client->request('GET', '/new'); | 34 | $client->request('GET', '/new'); |
18 | 35 | ||
19 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 36 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
20 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | 37 | $this->assertContains('login', $client->getResponse()->headers->get('location')); |
21 | } | 38 | } |
22 | 39 | ||
@@ -26,16 +43,17 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
26 | $client = $this->getClient(); | 43 | $client = $this->getClient(); |
27 | 44 | ||
28 | $client->request('GET', '/unread/list'); | 45 | $client->request('GET', '/unread/list'); |
46 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
29 | $crawler = $client->followRedirect(); | 47 | $crawler = $client->followRedirect(); |
30 | 48 | ||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 49 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
32 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 50 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
33 | $this->assertContains('quickstart.intro.title', $body[0]); | 51 | $this->assertContains('quickstart.intro.title', $body[0]); |
34 | 52 | ||
35 | // Test if quickstart is disabled when user has 1 entry | 53 | // Test if quickstart is disabled when user has 1 entry |
36 | $crawler = $client->request('GET', '/new'); | 54 | $crawler = $client->request('GET', '/new'); |
37 | 55 | ||
38 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 56 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
39 | 57 | ||
40 | $form = $crawler->filter('form[name=entry]')->form(); | 58 | $form = $crawler->filter('form[name=entry]')->form(); |
41 | 59 | ||
@@ -44,7 +62,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
44 | ]; | 62 | ]; |
45 | 63 | ||
46 | $client->submit($form, $data); | 64 | $client->submit($form, $data); |
47 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 65 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
48 | $client->followRedirect(); | 66 | $client->followRedirect(); |
49 | 67 | ||
50 | $crawler = $client->request('GET', '/unread/list'); | 68 | $crawler = $client->request('GET', '/unread/list'); |
@@ -55,11 +73,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
55 | public function testGetNew() | 73 | public function testGetNew() |
56 | { | 74 | { |
57 | $this->logInAs('admin'); | 75 | $this->logInAs('admin'); |
76 | $this->useTheme('baggy'); | ||
58 | $client = $this->getClient(); | 77 | $client = $this->getClient(); |
59 | 78 | ||
60 | $crawler = $client->request('GET', '/new'); | 79 | $crawler = $client->request('GET', '/new'); |
61 | 80 | ||
62 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 81 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
63 | 82 | ||
64 | $this->assertCount(1, $crawler->filter('input[type=url]')); | 83 | $this->assertCount(1, $crawler->filter('input[type=url]')); |
65 | $this->assertCount(1, $crawler->filter('form[name=entry]')); | 84 | $this->assertCount(1, $crawler->filter('form[name=entry]')); |
@@ -68,6 +87,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
68 | public function testPostNewViaBookmarklet() | 87 | public function testPostNewViaBookmarklet() |
69 | { | 88 | { |
70 | $this->logInAs('admin'); | 89 | $this->logInAs('admin'); |
90 | $this->useTheme('baggy'); | ||
71 | $client = $this->getClient(); | 91 | $client = $this->getClient(); |
72 | 92 | ||
73 | $crawler = $client->request('GET', '/'); | 93 | $crawler = $client->request('GET', '/'); |
@@ -76,7 +96,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
76 | 96 | ||
77 | // Good URL | 97 | // Good URL |
78 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); | 98 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); |
79 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 99 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
80 | $client->followRedirect(); | 100 | $client->followRedirect(); |
81 | $crawler = $client->request('GET', '/'); | 101 | $crawler = $client->request('GET', '/'); |
82 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 102 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
@@ -97,15 +117,15 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
97 | 117 | ||
98 | $crawler = $client->request('GET', '/new'); | 118 | $crawler = $client->request('GET', '/new'); |
99 | 119 | ||
100 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 120 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
101 | 121 | ||
102 | $form = $crawler->filter('form[name=entry]')->form(); | 122 | $form = $crawler->filter('form[name=entry]')->form(); |
103 | 123 | ||
104 | $crawler = $client->submit($form); | 124 | $crawler = $client->submit($form); |
105 | 125 | ||
106 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 126 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
107 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); | 127 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); |
108 | $this->assertEquals('This value should not be blank.', $alert[0]); | 128 | $this->assertSame('This value should not be blank.', $alert[0]); |
109 | } | 129 | } |
110 | 130 | ||
111 | /** | 131 | /** |
@@ -118,7 +138,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
118 | 138 | ||
119 | $crawler = $client->request('GET', '/new'); | 139 | $crawler = $client->request('GET', '/new'); |
120 | 140 | ||
121 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 141 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
122 | 142 | ||
123 | $form = $crawler->filter('form[name=entry]')->form(); | 143 | $form = $crawler->filter('form[name=entry]')->form(); |
124 | 144 | ||
@@ -128,26 +148,70 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
128 | 148 | ||
129 | $client->submit($form, $data); | 149 | $client->submit($form, $data); |
130 | 150 | ||
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 151 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
132 | 152 | ||
133 | $content = $client->getContainer() | 153 | $content = $client->getContainer() |
134 | ->get('doctrine.orm.entity_manager') | 154 | ->get('doctrine.orm.entity_manager') |
135 | ->getRepository('WallabagCoreBundle:Entry') | 155 | ->getRepository('WallabagCoreBundle:Entry') |
136 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 156 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
137 | 157 | ||
158 | $author = $content->getPublishedBy(); | ||
159 | |||
138 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 160 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
139 | $this->assertEquals($this->url, $content->getUrl()); | 161 | $this->assertSame($this->url, $content->getUrl()); |
140 | $this->assertContains('Google', $content->getTitle()); | 162 | $this->assertContains('Google', $content->getTitle()); |
163 | $this->assertSame('fr', $content->getLanguage()); | ||
164 | $this->assertSame('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
165 | $this->assertSame('Morgane Tual', $author[0]); | ||
166 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); | ||
167 | } | ||
168 | |||
169 | public function testPostWithMultipleAuthors() | ||
170 | { | ||
171 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | ||
172 | $this->logInAs('admin'); | ||
173 | $client = $this->getClient(); | ||
174 | |||
175 | $crawler = $client->request('GET', '/new'); | ||
176 | |||
177 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
178 | |||
179 | $form = $crawler->filter('form[name=entry]')->form(); | ||
180 | |||
181 | $data = [ | ||
182 | 'entry[url]' => $url, | ||
183 | ]; | ||
184 | |||
185 | $client->submit($form, $data); | ||
186 | |||
187 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
188 | |||
189 | $content = $client->getContainer() | ||
190 | ->get('doctrine.orm.entity_manager') | ||
191 | ->getRepository('WallabagCoreBundle:Entry') | ||
192 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
193 | |||
194 | $authors = $content->getPublishedBy(); | ||
195 | $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
196 | $this->assertSame('fr', $content->getLanguage()); | ||
197 | $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | ||
198 | $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]); | ||
141 | } | 199 | } |
142 | 200 | ||
143 | public function testPostNewOkUrlExist() | 201 | public function testPostNewOkUrlExist() |
144 | { | 202 | { |
145 | $this->logInAs('admin'); | 203 | $this->logInAs('admin'); |
204 | |||
205 | $entry = new Entry($this->getLoggedInUser()); | ||
206 | $entry->setUrl($this->url); | ||
207 | $this->getEntityManager()->persist($entry); | ||
208 | $this->getEntityManager()->flush(); | ||
209 | |||
146 | $client = $this->getClient(); | 210 | $client = $this->getClient(); |
147 | 211 | ||
148 | $crawler = $client->request('GET', '/new'); | 212 | $crawler = $client->request('GET', '/new'); |
149 | 213 | ||
150 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 214 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
151 | 215 | ||
152 | $form = $crawler->filter('form[name=entry]')->form(); | 216 | $form = $crawler->filter('form[name=entry]')->form(); |
153 | 217 | ||
@@ -157,7 +221,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
157 | 221 | ||
158 | $client->submit($form, $data); | 222 | $client->submit($form, $data); |
159 | 223 | ||
160 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 224 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
161 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | 225 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
162 | } | 226 | } |
163 | 227 | ||
@@ -170,7 +234,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
170 | 234 | ||
171 | $crawler = $client->request('GET', '/new'); | 235 | $crawler = $client->request('GET', '/new'); |
172 | 236 | ||
173 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 237 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
174 | 238 | ||
175 | $form = $crawler->filter('form[name=entry]')->form(); | 239 | $form = $crawler->filter('form[name=entry]')->form(); |
176 | 240 | ||
@@ -182,7 +246,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
182 | 246 | ||
183 | $crawler = $client->request('GET', '/new'); | 247 | $crawler = $client->request('GET', '/new'); |
184 | 248 | ||
185 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 249 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
186 | 250 | ||
187 | $form = $crawler->filter('form[name=entry]')->form(); | 251 | $form = $crawler->filter('form[name=entry]')->form(); |
188 | 252 | ||
@@ -192,17 +256,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
192 | 256 | ||
193 | $client->submit($form, $data); | 257 | $client->submit($form, $data); |
194 | 258 | ||
195 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 259 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
196 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | 260 | $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 | } | 261 | } |
207 | 262 | ||
208 | /** | 263 | /** |
@@ -215,7 +270,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
215 | 270 | ||
216 | $crawler = $client->request('GET', '/new'); | 271 | $crawler = $client->request('GET', '/new'); |
217 | 272 | ||
218 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 273 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
219 | 274 | ||
220 | $form = $crawler->filter('form[name=entry]')->form(); | 275 | $form = $crawler->filter('form[name=entry]')->form(); |
221 | 276 | ||
@@ -225,7 +280,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
225 | 280 | ||
226 | $client->submit($form, $data); | 281 | $client->submit($form, $data); |
227 | 282 | ||
228 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 283 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
229 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | 284 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
230 | 285 | ||
231 | $em = $client->getContainer() | 286 | $em = $client->getContainer() |
@@ -235,8 +290,9 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
235 | ->findOneByUrl($url); | 290 | ->findOneByUrl($url); |
236 | $tags = $entry->getTags(); | 291 | $tags = $entry->getTags(); |
237 | 292 | ||
238 | $this->assertCount(1, $tags); | 293 | $this->assertCount(2, $tags); |
239 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 294 | $this->assertContains('wallabag', $tags); |
295 | $this->assertSame('en', $entry->getLanguage()); | ||
240 | 296 | ||
241 | $em->remove($entry); | 297 | $em->remove($entry); |
242 | $em->flush(); | 298 | $em->flush(); |
@@ -245,7 +301,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
245 | // related https://github.com/wallabag/wallabag/issues/2121 | 301 | // related https://github.com/wallabag/wallabag/issues/2121 |
246 | $crawler = $client->request('GET', '/new'); | 302 | $crawler = $client->request('GET', '/new'); |
247 | 303 | ||
248 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 304 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
249 | 305 | ||
250 | $form = $crawler->filter('form[name=entry]')->form(); | 306 | $form = $crawler->filter('form[name=entry]')->form(); |
251 | 307 | ||
@@ -255,7 +311,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
255 | 311 | ||
256 | $client->submit($form, $data); | 312 | $client->submit($form, $data); |
257 | 313 | ||
258 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 314 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
259 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | 315 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
260 | 316 | ||
261 | $entry = $em | 317 | $entry = $em |
@@ -264,8 +320,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
264 | 320 | ||
265 | $tags = $entry->getTags(); | 321 | $tags = $entry->getTags(); |
266 | 322 | ||
267 | $this->assertCount(1, $tags); | 323 | $this->assertCount(2, $tags); |
268 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 324 | $this->assertContains('wallabag', $tags); |
269 | 325 | ||
270 | $em->remove($entry); | 326 | $em->remove($entry); |
271 | $em->flush(); | 327 | $em->flush(); |
@@ -278,7 +334,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
278 | 334 | ||
279 | $client->request('GET', '/archive/list'); | 335 | $client->request('GET', '/archive/list'); |
280 | 336 | ||
281 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 337 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
282 | } | 338 | } |
283 | 339 | ||
284 | public function testUntagged() | 340 | public function testUntagged() |
@@ -288,7 +344,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
288 | 344 | ||
289 | $client->request('GET', '/untagged/list'); | 345 | $client->request('GET', '/untagged/list'); |
290 | 346 | ||
291 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 347 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
292 | } | 348 | } |
293 | 349 | ||
294 | public function testStarred() | 350 | public function testStarred() |
@@ -298,7 +354,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
298 | 354 | ||
299 | $client->request('GET', '/starred/list'); | 355 | $client->request('GET', '/starred/list'); |
300 | 356 | ||
301 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 357 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
302 | } | 358 | } |
303 | 359 | ||
304 | public function testRangeException() | 360 | public function testRangeException() |
@@ -308,33 +364,30 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
308 | 364 | ||
309 | $client->request('GET', '/all/list/900'); | 365 | $client->request('GET', '/all/list/900'); |
310 | 366 | ||
311 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 367 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
312 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | 368 | $this->assertSame('/all/list', $client->getResponse()->getTargetUrl()); |
313 | } | 369 | } |
314 | 370 | ||
315 | /** | ||
316 | * @depends testPostNewOk | ||
317 | */ | ||
318 | public function testView() | 371 | public function testView() |
319 | { | 372 | { |
320 | $this->logInAs('admin'); | 373 | $this->logInAs('admin'); |
321 | $client = $this->getClient(); | 374 | $client = $this->getClient(); |
322 | 375 | ||
323 | $content = $client->getContainer() | 376 | $entry = new Entry($this->getLoggedInUser()); |
324 | ->get('doctrine.orm.entity_manager') | 377 | $entry->setUrl('http://example.com/foo'); |
325 | ->getRepository('WallabagCoreBundle:Entry') | 378 | $entry->setTitle('title foo'); |
326 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 379 | $entry->setContent('foo bar baz'); |
380 | $this->getEntityManager()->persist($entry); | ||
381 | $this->getEntityManager()->flush(); | ||
327 | 382 | ||
328 | $crawler = $client->request('GET', '/view/'.$content->getId()); | 383 | $crawler = $client->request('GET', '/view/' . $entry->getId()); |
329 | 384 | ||
330 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 385 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
331 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 386 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
332 | $this->assertContains($content->getTitle(), $body[0]); | 387 | $this->assertContains($entry->getTitle(), $body[0]); |
333 | } | 388 | } |
334 | 389 | ||
335 | /** | 390 | /** |
336 | * @depends testPostNewOk | ||
337 | * | ||
338 | * This test will require an internet connection. | 391 | * This test will require an internet connection. |
339 | */ | 392 | */ |
340 | public function testReload() | 393 | public function testReload() |
@@ -342,65 +395,47 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
342 | $this->logInAs('admin'); | 395 | $this->logInAs('admin'); |
343 | $client = $this->getClient(); | 396 | $client = $this->getClient(); |
344 | 397 | ||
345 | $em = $client->getContainer() | 398 | $entry = new Entry($this->getLoggedInUser()); |
346 | ->get('doctrine.orm.entity_manager'); | 399 | $entry->setUrl($this->url); |
347 | 400 | $entry->setTitle('title foo'); | |
348 | $content = $em | 401 | $entry->setContent(''); |
349 | ->getRepository('WallabagCoreBundle:Entry') | 402 | $this->getEntityManager()->persist($entry); |
350 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 403 | $this->getEntityManager()->flush(); |
351 | 404 | $this->getEntityManager()->clear(); | |
352 | // empty content | ||
353 | $content->setContent(''); | ||
354 | $em->persist($content); | ||
355 | $em->flush(); | ||
356 | 405 | ||
357 | $client->request('GET', '/reload/'.$content->getId()); | 406 | $client->request('GET', '/reload/' . $entry->getId()); |
358 | 407 | ||
359 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 408 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
360 | 409 | ||
361 | $content = $em | 410 | $entry = $this->getEntityManager() |
362 | ->getRepository('WallabagCoreBundle:Entry') | 411 | ->getRepository('WallabagCoreBundle:Entry') |
363 | ->find($content->getId()); | 412 | ->find($entry->getId()); |
364 | 413 | ||
365 | $this->assertNotEmpty($content->getContent()); | 414 | $this->assertNotEmpty($entry->getContent()); |
366 | } | 415 | } |
367 | 416 | ||
368 | /** | ||
369 | * @depends testPostNewOk | ||
370 | */ | ||
371 | public function testReloadWithFetchingFailed() | 417 | public function testReloadWithFetchingFailed() |
372 | { | 418 | { |
373 | $this->logInAs('admin'); | 419 | $this->logInAs('admin'); |
374 | $client = $this->getClient(); | 420 | $client = $this->getClient(); |
375 | 421 | ||
376 | $em = $client->getContainer() | 422 | $entry = new Entry($this->getLoggedInUser()); |
377 | ->get('doctrine.orm.entity_manager'); | 423 | $entry->setUrl('http://0.0.0.0/failed.html'); |
424 | $this->getEntityManager()->persist($entry); | ||
425 | $this->getEntityManager()->flush(); | ||
378 | 426 | ||
379 | $content = $em | 427 | $client->request('GET', '/reload/' . $entry->getId()); |
380 | ->getRepository('WallabagCoreBundle:Entry') | ||
381 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
382 | 428 | ||
383 | // put a known failed url | 429 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
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 | |||
390 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
391 | 430 | ||
392 | // force EntityManager to clear previous entity | 431 | // force EntityManager to clear previous entity |
393 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | 432 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 |
394 | $em->clear(); | 433 | $this->getEntityManager()->clear(); |
395 | $newContent = $em | 434 | $newContent = $this->getEntityManager() |
396 | ->getRepository('WallabagCoreBundle:Entry') | 435 | ->getRepository('WallabagCoreBundle:Entry') |
397 | ->find($content->getId()); | 436 | ->find($entry->getId()); |
398 | 437 | ||
399 | $newContent->setUrl($this->url); | 438 | $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); |
400 | $em->persist($newContent); | ||
401 | $em->flush(); | ||
402 | |||
403 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | ||
404 | } | 439 | } |
405 | 440 | ||
406 | public function testEdit() | 441 | public function testEdit() |
@@ -408,14 +443,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
408 | $this->logInAs('admin'); | 443 | $this->logInAs('admin'); |
409 | $client = $this->getClient(); | 444 | $client = $this->getClient(); |
410 | 445 | ||
411 | $content = $client->getContainer() | 446 | $entry = new Entry($this->getLoggedInUser()); |
412 | ->get('doctrine.orm.entity_manager') | 447 | $entry->setUrl($this->url); |
413 | ->getRepository('WallabagCoreBundle:Entry') | 448 | $this->getEntityManager()->persist($entry); |
414 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 449 | $this->getEntityManager()->flush(); |
415 | 450 | ||
416 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 451 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); |
417 | 452 | ||
418 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 453 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
419 | 454 | ||
420 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | 455 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); |
421 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | 456 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); |
@@ -426,14 +461,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
426 | $this->logInAs('admin'); | 461 | $this->logInAs('admin'); |
427 | $client = $this->getClient(); | 462 | $client = $this->getClient(); |
428 | 463 | ||
429 | $content = $client->getContainer() | 464 | $entry = new Entry($this->getLoggedInUser()); |
430 | ->get('doctrine.orm.entity_manager') | 465 | $entry->setUrl($this->url); |
431 | ->getRepository('WallabagCoreBundle:Entry') | 466 | $this->getEntityManager()->persist($entry); |
432 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 467 | $this->getEntityManager()->flush(); |
433 | 468 | ||
434 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 469 | $crawler = $client->request('GET', '/edit/' . $entry->getId()); |
435 | 470 | ||
436 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 471 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
437 | 472 | ||
438 | $form = $crawler->filter('button[type=submit]')->form(); | 473 | $form = $crawler->filter('button[type=submit]')->form(); |
439 | 474 | ||
@@ -443,7 +478,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
443 | 478 | ||
444 | $client->submit($form, $data); | 479 | $client->submit($form, $data); |
445 | 480 | ||
446 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 481 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
447 | 482 | ||
448 | $crawler = $client->followRedirect(); | 483 | $crawler = $client->followRedirect(); |
449 | 484 | ||
@@ -456,21 +491,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
456 | $this->logInAs('admin'); | 491 | $this->logInAs('admin'); |
457 | $client = $this->getClient(); | 492 | $client = $this->getClient(); |
458 | 493 | ||
459 | $content = $client->getContainer() | 494 | $entry = new Entry($this->getLoggedInUser()); |
460 | ->get('doctrine.orm.entity_manager') | 495 | $entry->setUrl($this->url); |
461 | ->getRepository('WallabagCoreBundle:Entry') | 496 | $this->getEntityManager()->persist($entry); |
462 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 497 | $this->getEntityManager()->flush(); |
498 | $this->getEntityManager()->clear(); | ||
463 | 499 | ||
464 | $client->request('GET', '/archive/'.$content->getId()); | 500 | $client->request('GET', '/archive/' . $entry->getId()); |
465 | 501 | ||
466 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 502 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
467 | 503 | ||
468 | $res = $client->getContainer() | 504 | $res = $client->getContainer() |
469 | ->get('doctrine.orm.entity_manager') | 505 | ->get('doctrine.orm.entity_manager') |
470 | ->getRepository('WallabagCoreBundle:Entry') | 506 | ->getRepository('WallabagCoreBundle:Entry') |
471 | ->find($content->getId()); | 507 | ->find($entry->getId()); |
472 | 508 | ||
473 | $this->assertEquals($res->isArchived(), true); | 509 | $this->assertSame(1, $res->isArchived()); |
474 | } | 510 | } |
475 | 511 | ||
476 | public function testToggleStar() | 512 | public function testToggleStar() |
@@ -478,21 +514,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
478 | $this->logInAs('admin'); | 514 | $this->logInAs('admin'); |
479 | $client = $this->getClient(); | 515 | $client = $this->getClient(); |
480 | 516 | ||
481 | $content = $client->getContainer() | 517 | $entry = new Entry($this->getLoggedInUser()); |
482 | ->get('doctrine.orm.entity_manager') | 518 | $entry->setUrl($this->url); |
483 | ->getRepository('WallabagCoreBundle:Entry') | 519 | $this->getEntityManager()->persist($entry); |
484 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 520 | $this->getEntityManager()->flush(); |
521 | $this->getEntityManager()->clear(); | ||
485 | 522 | ||
486 | $client->request('GET', '/star/'.$content->getId()); | 523 | $client->request('GET', '/star/' . $entry->getId()); |
487 | 524 | ||
488 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 525 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
489 | 526 | ||
490 | $res = $client->getContainer() | 527 | $res = $client->getContainer() |
491 | ->get('doctrine.orm.entity_manager') | 528 | ->get('doctrine.orm.entity_manager') |
492 | ->getRepository('WallabagCoreBundle:Entry') | 529 | ->getRepository('WallabagCoreBundle:Entry') |
493 | ->findOneById($content->getId()); | 530 | ->findOneById($entry->getId()); |
494 | 531 | ||
495 | $this->assertEquals($res->isStarred(), true); | 532 | $this->assertSame(1, $res->isStarred()); |
496 | } | 533 | } |
497 | 534 | ||
498 | public function testDelete() | 535 | public function testDelete() |
@@ -500,18 +537,18 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
500 | $this->logInAs('admin'); | 537 | $this->logInAs('admin'); |
501 | $client = $this->getClient(); | 538 | $client = $this->getClient(); |
502 | 539 | ||
503 | $content = $client->getContainer() | 540 | $entry = new Entry($this->getLoggedInUser()); |
504 | ->get('doctrine.orm.entity_manager') | 541 | $entry->setUrl($this->url); |
505 | ->getRepository('WallabagCoreBundle:Entry') | 542 | $this->getEntityManager()->persist($entry); |
506 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 543 | $this->getEntityManager()->flush(); |
507 | 544 | ||
508 | $client->request('GET', '/delete/'.$content->getId()); | 545 | $client->request('GET', '/delete/' . $entry->getId()); |
509 | 546 | ||
510 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 547 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
511 | 548 | ||
512 | $client->request('GET', '/delete/'.$content->getId()); | 549 | $client->request('GET', '/delete/' . $entry->getId()); |
513 | 550 | ||
514 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 551 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
515 | } | 552 | } |
516 | 553 | ||
517 | /** | 554 | /** |
@@ -547,14 +584,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
547 | $em->persist($content); | 584 | $em->persist($content); |
548 | $em->flush(); | 585 | $em->flush(); |
549 | 586 | ||
550 | $client->request('GET', '/view/'.$content->getId()); | 587 | $client->request('GET', '/view/' . $content->getId()); |
551 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 588 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
552 | 589 | ||
553 | $client->request('GET', '/delete/'.$content->getId()); | 590 | $client->request('GET', '/delete/' . $content->getId()); |
554 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 591 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
555 | 592 | ||
556 | $client->followRedirect(); | 593 | $client->followRedirect(); |
557 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 594 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
558 | } | 595 | } |
559 | 596 | ||
560 | public function testViewOtherUserEntry() | 597 | public function testViewOtherUserEntry() |
@@ -567,15 +604,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
567 | ->getRepository('WallabagCoreBundle:Entry') | 604 | ->getRepository('WallabagCoreBundle:Entry') |
568 | ->findOneByUsernameAndNotArchived('bob'); | 605 | ->findOneByUsernameAndNotArchived('bob'); |
569 | 606 | ||
570 | $client->request('GET', '/view/'.$content->getId()); | 607 | $client->request('GET', '/view/' . $content->getId()); |
571 | 608 | ||
572 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 609 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
573 | } | 610 | } |
574 | 611 | ||
575 | public function testFilterOnReadingTime() | 612 | public function testFilterOnReadingTime() |
576 | { | 613 | { |
577 | $this->logInAs('admin'); | 614 | $this->logInAs('admin'); |
615 | $this->useTheme('baggy'); | ||
578 | $client = $this->getClient(); | 616 | $client = $this->getClient(); |
617 | $entry = new Entry($this->getLoggedInUser()); | ||
618 | $entry->setUrl($this->url); | ||
619 | $entry->setReadingTime(22); | ||
620 | $this->getEntityManager()->persist($entry); | ||
621 | $this->getEntityManager()->flush(); | ||
579 | 622 | ||
580 | $crawler = $client->request('GET', '/unread/list'); | 623 | $crawler = $client->request('GET', '/unread/list'); |
581 | 624 | ||
@@ -614,9 +657,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
614 | public function testFilterOnReadingTimeOnlyUpper() | 657 | public function testFilterOnReadingTimeOnlyUpper() |
615 | { | 658 | { |
616 | $this->logInAs('admin'); | 659 | $this->logInAs('admin'); |
660 | $this->useTheme('baggy'); | ||
617 | $client = $this->getClient(); | 661 | $client = $this->getClient(); |
618 | 662 | ||
619 | $crawler = $client->request('GET', '/unread/list'); | 663 | $crawler = $client->request('GET', '/all/list'); |
664 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
665 | |||
666 | $entry = new Entry($this->getLoggedInUser()); | ||
667 | $entry->setUrl($this->url); | ||
668 | $entry->setReadingTime(23); | ||
669 | $this->getEntityManager()->persist($entry); | ||
670 | $this->getEntityManager()->flush(); | ||
671 | |||
672 | $crawler = $client->request('GET', '/all/list'); | ||
673 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | ||
620 | 674 | ||
621 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 675 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
622 | 676 | ||
@@ -626,12 +680,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
626 | 680 | ||
627 | $crawler = $client->submit($form, $data); | 681 | $crawler = $client->submit($form, $data); |
628 | 682 | ||
629 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 683 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
630 | } | 684 | } |
631 | 685 | ||
632 | public function testFilterOnReadingTimeOnlyLower() | 686 | public function testFilterOnReadingTimeOnlyLower() |
633 | { | 687 | { |
634 | $this->logInAs('admin'); | 688 | $this->logInAs('admin'); |
689 | $this->useTheme('baggy'); | ||
635 | $client = $this->getClient(); | 690 | $client = $this->getClient(); |
636 | 691 | ||
637 | $crawler = $client->request('GET', '/unread/list'); | 692 | $crawler = $client->request('GET', '/unread/list'); |
@@ -644,12 +699,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
644 | 699 | ||
645 | $crawler = $client->submit($form, $data); | 700 | $crawler = $client->submit($form, $data); |
646 | 701 | ||
647 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 702 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
703 | |||
704 | $entry = new Entry($this->getLoggedInUser()); | ||
705 | $entry->setUrl($this->url); | ||
706 | $entry->setReadingTime(23); | ||
707 | $this->getEntityManager()->persist($entry); | ||
708 | $this->getEntityManager()->flush(); | ||
709 | |||
710 | $crawler = $client->submit($form, $data); | ||
711 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | ||
648 | } | 712 | } |
649 | 713 | ||
650 | public function testFilterOnUnreadStatus() | 714 | public function testFilterOnUnreadStatus() |
651 | { | 715 | { |
652 | $this->logInAs('admin'); | 716 | $this->logInAs('admin'); |
717 | $this->useTheme('baggy'); | ||
653 | $client = $this->getClient(); | 718 | $client = $this->getClient(); |
654 | 719 | ||
655 | $crawler = $client->request('GET', '/all/list'); | 720 | $crawler = $client->request('GET', '/all/list'); |
@@ -663,11 +728,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
663 | $crawler = $client->submit($form, $data); | 728 | $crawler = $client->submit($form, $data); |
664 | 729 | ||
665 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 730 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
731 | |||
732 | $entry = new Entry($this->getLoggedInUser()); | ||
733 | $entry->setUrl($this->url); | ||
734 | $entry->setArchived(false); | ||
735 | $this->getEntityManager()->persist($entry); | ||
736 | $this->getEntityManager()->flush(); | ||
737 | |||
738 | $crawler = $client->submit($form, $data); | ||
739 | |||
740 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
666 | } | 741 | } |
667 | 742 | ||
668 | public function testFilterOnCreationDate() | 743 | public function testFilterOnCreationDate() |
669 | { | 744 | { |
670 | $this->logInAs('admin'); | 745 | $this->logInAs('admin'); |
746 | $this->useTheme('baggy'); | ||
671 | $client = $this->getClient(); | 747 | $client = $this->getClient(); |
672 | 748 | ||
673 | $crawler = $client->request('GET', '/unread/list'); | 749 | $crawler = $client->request('GET', '/unread/list'); |
@@ -718,7 +794,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
718 | 794 | ||
719 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | 795 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; |
720 | 796 | ||
721 | $client->request('GET', 'unread/list'.$parameters); | 797 | $client->request('GET', 'unread/list' . $parameters); |
722 | 798 | ||
723 | $this->assertContains($parameters, $client->getResponse()->getContent()); | 799 | $this->assertContains($parameters, $client->getResponse()->getContent()); |
724 | 800 | ||
@@ -734,6 +810,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
734 | public function testFilterOnDomainName() | 810 | public function testFilterOnDomainName() |
735 | { | 811 | { |
736 | $this->logInAs('admin'); | 812 | $this->logInAs('admin'); |
813 | $this->useTheme('baggy'); | ||
737 | $client = $this->getClient(); | 814 | $client = $this->getClient(); |
738 | 815 | ||
739 | $crawler = $client->request('GET', '/unread/list'); | 816 | $crawler = $client->request('GET', '/unread/list'); |
@@ -766,6 +843,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
766 | public function testFilterOnStatus() | 843 | public function testFilterOnStatus() |
767 | { | 844 | { |
768 | $this->logInAs('admin'); | 845 | $this->logInAs('admin'); |
846 | $this->useTheme('baggy'); | ||
769 | $client = $this->getClient(); | 847 | $client = $this->getClient(); |
770 | 848 | ||
771 | $crawler = $client->request('GET', '/unread/list'); | 849 | $crawler = $client->request('GET', '/unread/list'); |
@@ -784,9 +862,24 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
784 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 862 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
785 | } | 863 | } |
786 | 864 | ||
865 | public function testFilterOnIsPublic() | ||
866 | { | ||
867 | $this->logInAs('admin'); | ||
868 | $this->useTheme('baggy'); | ||
869 | $client = $this->getClient(); | ||
870 | |||
871 | $crawler = $client->request('GET', '/unread/list'); | ||
872 | $form = $crawler->filter('button[id=submit-filter]')->form(); | ||
873 | $form['entry_filter[isPublic]']->tick(); | ||
874 | |||
875 | $crawler = $client->submit($form); | ||
876 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | ||
877 | } | ||
878 | |||
787 | public function testPreviewPictureFilter() | 879 | public function testPreviewPictureFilter() |
788 | { | 880 | { |
789 | $this->logInAs('admin'); | 881 | $this->logInAs('admin'); |
882 | $this->useTheme('baggy'); | ||
790 | $client = $this->getClient(); | 883 | $client = $this->getClient(); |
791 | 884 | ||
792 | $crawler = $client->request('GET', '/unread/list'); | 885 | $crawler = $client->request('GET', '/unread/list'); |
@@ -800,8 +893,15 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
800 | public function testFilterOnLanguage() | 893 | public function testFilterOnLanguage() |
801 | { | 894 | { |
802 | $this->logInAs('admin'); | 895 | $this->logInAs('admin'); |
896 | $this->useTheme('baggy'); | ||
803 | $client = $this->getClient(); | 897 | $client = $this->getClient(); |
804 | 898 | ||
899 | $entry = new Entry($this->getLoggedInUser()); | ||
900 | $entry->setUrl($this->url); | ||
901 | $entry->setLanguage('fr'); | ||
902 | $this->getEntityManager()->persist($entry); | ||
903 | $this->getEntityManager()->flush(); | ||
904 | |||
805 | $crawler = $client->request('GET', '/unread/list'); | 905 | $crawler = $client->request('GET', '/unread/list'); |
806 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 906 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
807 | $data = [ | 907 | $data = [ |
@@ -809,7 +909,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
809 | ]; | 909 | ]; |
810 | 910 | ||
811 | $crawler = $client->submit($form, $data); | 911 | $crawler = $client->submit($form, $data); |
812 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 912 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
813 | 913 | ||
814 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 914 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
815 | $data = [ | 915 | $data = [ |
@@ -825,22 +925,26 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
825 | $this->logInAs('admin'); | 925 | $this->logInAs('admin'); |
826 | $client = $this->getClient(); | 926 | $client = $this->getClient(); |
827 | 927 | ||
828 | $content = $client->getContainer() | 928 | // sharing is enabled |
829 | ->get('doctrine.orm.entity_manager') | 929 | $client->getContainer()->get('craue_config')->set('share_public', 1); |
830 | ->getRepository('WallabagCoreBundle:Entry') | 930 | |
831 | ->findOneByUser($this->getLoggedInUserId()); | 931 | $content = new Entry($this->getLoggedInUser()); |
932 | $content->setUrl($this->url); | ||
933 | $this->getEntityManager()->persist($content); | ||
934 | $this->getEntityManager()->flush(); | ||
935 | $this->getEntityManager()->clear(); | ||
832 | 936 | ||
833 | // no uid | 937 | // no uid |
834 | $client->request('GET', '/share/'.$content->getUid()); | 938 | $client->request('GET', '/share/' . $content->getUid()); |
835 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 939 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
836 | 940 | ||
837 | // generating the uid | 941 | // generating the uid |
838 | $client->request('GET', '/share/'.$content->getId()); | 942 | $client->request('GET', '/share/' . $content->getId()); |
839 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 943 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
840 | 944 | ||
841 | // follow link with uid | 945 | // follow link with uid |
842 | $crawler = $client->followRedirect(); | 946 | $crawler = $client->followRedirect(); |
843 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 947 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
844 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | 948 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); |
845 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | 949 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); |
846 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | 950 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); |
@@ -852,23 +956,24 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
852 | 956 | ||
853 | // sharing is now disabled | 957 | // sharing is now disabled |
854 | $client->getContainer()->get('craue_config')->set('share_public', 0); | 958 | $client->getContainer()->get('craue_config')->set('share_public', 0); |
855 | $client->request('GET', '/share/'.$content->getUid()); | 959 | $client->request('GET', '/share/' . $content->getUid()); |
856 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 960 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
857 | 961 | ||
858 | $client->request('GET', '/view/'.$content->getId()); | 962 | $client->request('GET', '/view/' . $content->getId()); |
859 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | 963 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); |
860 | 964 | ||
861 | // removing the share | 965 | // removing the share |
862 | $client->request('GET', '/share/delete/'.$content->getId()); | 966 | $client->request('GET', '/share/delete/' . $content->getId()); |
863 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 967 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
864 | 968 | ||
865 | // share is now disable | 969 | // share is now disable |
866 | $client->request('GET', '/share/'.$content->getUid()); | 970 | $client->request('GET', '/share/' . $content->getUid()); |
867 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 971 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
868 | } | 972 | } |
869 | 973 | ||
870 | public function testNewEntryWithDownloadImagesEnabled() | 974 | public function testNewEntryWithDownloadImagesEnabled() |
871 | { | 975 | { |
976 | $this->downloadImagesEnabled = true; | ||
872 | $this->logInAs('admin'); | 977 | $this->logInAs('admin'); |
873 | $client = $this->getClient(); | 978 | $client = $this->getClient(); |
874 | 979 | ||
@@ -877,7 +982,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
877 | 982 | ||
878 | $crawler = $client->request('GET', '/new'); | 983 | $crawler = $client->request('GET', '/new'); |
879 | 984 | ||
880 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 985 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
881 | 986 | ||
882 | $form = $crawler->filter('form[name=entry]')->form(); | 987 | $form = $crawler->filter('form[name=entry]')->form(); |
883 | 988 | ||
@@ -887,7 +992,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
887 | 992 | ||
888 | $client->submit($form, $data); | 993 | $client->submit($form, $data); |
889 | 994 | ||
890 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 995 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
891 | 996 | ||
892 | $em = $client->getContainer() | 997 | $em = $client->getContainer() |
893 | ->get('doctrine.orm.entity_manager'); | 998 | ->get('doctrine.orm.entity_manager'); |
@@ -897,9 +1002,10 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
897 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | 1002 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); |
898 | 1003 | ||
899 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | 1004 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); |
900 | $this->assertEquals($url, $entry->getUrl()); | 1005 | $this->assertSame($url, $entry->getUrl()); |
901 | $this->assertContains('Perpignan', $entry->getTitle()); | 1006 | $this->assertContains('Perpignan', $entry->getTitle()); |
902 | $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); | 1007 | // instead of checking for the filename (which might change) check that the image is now local |
1008 | $this->assertContains($client->getContainer()->getParameter('domain_name') . '/assets/images/', $entry->getContent()); | ||
903 | 1009 | ||
904 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 1010 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
905 | } | 1011 | } |
@@ -909,20 +1015,35 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
909 | */ | 1015 | */ |
910 | public function testRemoveEntryWithDownloadImagesEnabled() | 1016 | public function testRemoveEntryWithDownloadImagesEnabled() |
911 | { | 1017 | { |
1018 | $this->downloadImagesEnabled = true; | ||
912 | $this->logInAs('admin'); | 1019 | $this->logInAs('admin'); |
913 | $client = $this->getClient(); | 1020 | $client = $this->getClient(); |
914 | 1021 | ||
915 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | 1022 | $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); | 1023 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
917 | 1024 | ||
1025 | $crawler = $client->request('GET', '/new'); | ||
1026 | |||
1027 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1028 | |||
1029 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1030 | |||
1031 | $data = [ | ||
1032 | 'entry[url]' => $url, | ||
1033 | ]; | ||
1034 | |||
1035 | $client->submit($form, $data); | ||
1036 | |||
1037 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1038 | |||
918 | $content = $client->getContainer() | 1039 | $content = $client->getContainer() |
919 | ->get('doctrine.orm.entity_manager') | 1040 | ->get('doctrine.orm.entity_manager') |
920 | ->getRepository('WallabagCoreBundle:Entry') | 1041 | ->getRepository('WallabagCoreBundle:Entry') |
921 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | 1042 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); |
922 | 1043 | ||
923 | $client->request('GET', '/delete/'.$content->getId()); | 1044 | $client->request('GET', '/delete/' . $content->getId()); |
924 | 1045 | ||
925 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1046 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
926 | 1047 | ||
927 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 1048 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
928 | } | 1049 | } |
@@ -932,31 +1053,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
932 | $this->logInAs('empty'); | 1053 | $this->logInAs('empty'); |
933 | $client = $this->getClient(); | 1054 | $client = $this->getClient(); |
934 | 1055 | ||
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 | 1056 | // Redirect to homepage |
945 | $config = $user->getConfig(); | 1057 | $config = $this->getLoggedInUser()->getConfig(); |
946 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | 1058 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
947 | $em->persist($config); | 1059 | $this->getEntityManager()->persist($config); |
948 | $em->flush(); | ||
949 | 1060 | ||
950 | $content = $client->getContainer() | 1061 | $entry = new Entry($this->getLoggedInUser()); |
951 | ->get('doctrine.orm.entity_manager') | 1062 | $entry->setUrl($this->url); |
952 | ->getRepository('WallabagCoreBundle:Entry') | 1063 | $this->getEntityManager()->persist($entry); |
953 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 1064 | |
1065 | $this->getEntityManager()->flush(); | ||
954 | 1066 | ||
955 | $client->request('GET', '/view/'.$content->getId()); | 1067 | $client->request('GET', '/view/' . $entry->getId()); |
956 | $client->request('GET', '/archive/'.$content->getId()); | 1068 | $client->request('GET', '/archive/' . $entry->getId()); |
957 | 1069 | ||
958 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1070 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
959 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | 1071 | $this->assertSame('/', $client->getResponse()->headers->get('location')); |
960 | } | 1072 | } |
961 | 1073 | ||
962 | public function testRedirectToCurrentPage() | 1074 | public function testRedirectToCurrentPage() |
@@ -964,46 +1076,36 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
964 | $this->logInAs('empty'); | 1076 | $this->logInAs('empty'); |
965 | $client = $this->getClient(); | 1077 | $client = $this->getClient(); |
966 | 1078 | ||
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 | 1079 | // Redirect to current page |
977 | $config = $user->getConfig(); | 1080 | $config = $this->getLoggedInUser()->getConfig(); |
978 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | 1081 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
979 | $em->persist($config); | 1082 | $this->getEntityManager()->persist($config); |
980 | $em->flush(); | ||
981 | 1083 | ||
982 | $content = $client->getContainer() | 1084 | $entry = new Entry($this->getLoggedInUser()); |
983 | ->get('doctrine.orm.entity_manager') | 1085 | $entry->setUrl($this->url); |
984 | ->getRepository('WallabagCoreBundle:Entry') | 1086 | $this->getEntityManager()->persist($entry); |
985 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 1087 | |
1088 | $this->getEntityManager()->flush(); | ||
986 | 1089 | ||
987 | $client->request('GET', '/view/'.$content->getId()); | 1090 | $client->request('GET', '/view/' . $entry->getId()); |
988 | $client->request('GET', '/archive/'.$content->getId()); | 1091 | $client->request('GET', '/archive/' . $entry->getId()); |
989 | 1092 | ||
990 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1093 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
991 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | 1094 | $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location')); |
992 | } | 1095 | } |
993 | 1096 | ||
994 | public function testFilterOnHttpStatus() | 1097 | public function testFilterOnHttpStatus() |
995 | { | 1098 | { |
996 | $this->logInAs('admin'); | 1099 | $this->logInAs('admin'); |
1100 | $this->useTheme('baggy'); | ||
997 | $client = $this->getClient(); | 1101 | $client = $this->getClient(); |
998 | 1102 | ||
999 | $crawler = $client->request('GET', '/new'); | 1103 | $entry = new Entry($this->getLoggedInUser()); |
1000 | $form = $crawler->filter('form[name=entry]')->form(); | 1104 | $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); |
1105 | $entry->setHttpStatus(404); | ||
1106 | $this->getEntityManager()->persist($entry); | ||
1001 | 1107 | ||
1002 | $data = [ | 1108 | $this->getEntityManager()->flush(); |
1003 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | ||
1004 | ]; | ||
1005 | |||
1006 | $client->submit($form, $data); | ||
1007 | 1109 | ||
1008 | $crawler = $client->request('GET', '/all/list'); | 1110 | $crawler = $client->request('GET', '/all/list'); |
1009 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1111 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1016,14 +1118,17 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1016 | 1118 | ||
1017 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1119 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1018 | 1120 | ||
1019 | $crawler = $client->request('GET', '/new'); | 1121 | $entry = new Entry($this->getLoggedInUser()); |
1020 | $form = $crawler->filter('form[name=entry]')->form(); | 1122 | $entry->setUrl($this->url); |
1123 | $entry->setHttpStatus(200); | ||
1124 | $this->getEntityManager()->persist($entry); | ||
1021 | 1125 | ||
1022 | $data = [ | 1126 | $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', | 1127 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); |
1024 | ]; | 1128 | $entry->setHttpStatus(200); |
1129 | $this->getEntityManager()->persist($entry); | ||
1025 | 1130 | ||
1026 | $client->submit($form, $data); | 1131 | $this->getEntityManager()->flush(); |
1027 | 1132 | ||
1028 | $crawler = $client->request('GET', '/all/list'); | 1133 | $crawler = $client->request('GET', '/all/list'); |
1029 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1134 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1034,7 +1139,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1034 | 1139 | ||
1035 | $crawler = $client->submit($form, $data); | 1140 | $crawler = $client->submit($form, $data); |
1036 | 1141 | ||
1037 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1142 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
1038 | 1143 | ||
1039 | $crawler = $client->request('GET', '/all/list'); | 1144 | $crawler = $client->request('GET', '/all/list'); |
1040 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1145 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1045,14 +1150,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1045 | 1150 | ||
1046 | $crawler = $client->submit($form, $data); | 1151 | $crawler = $client->submit($form, $data); |
1047 | 1152 | ||
1048 | $this->assertCount(7, $crawler->filter('div[class=entry]')); | 1153 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
1049 | } | 1154 | } |
1050 | 1155 | ||
1051 | public function testSearch() | 1156 | public function testSearch() |
1052 | { | 1157 | { |
1053 | $this->logInAs('admin'); | 1158 | $this->logInAs('admin'); |
1159 | $this->useTheme('baggy'); | ||
1054 | $client = $this->getClient(); | 1160 | $client = $this->getClient(); |
1055 | 1161 | ||
1162 | $entry = new Entry($this->getLoggedInUser()); | ||
1163 | $entry->setUrl($this->url); | ||
1164 | $entry->setTitle('test'); | ||
1165 | $this->getEntityManager()->persist($entry); | ||
1166 | $this->getEntityManager()->flush(); | ||
1167 | |||
1056 | // Search on unread list | 1168 | // Search on unread list |
1057 | $crawler = $client->request('GET', '/unread/list'); | 1169 | $crawler = $client->request('GET', '/unread/list'); |
1058 | 1170 | ||
@@ -1063,35 +1175,37 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1063 | 1175 | ||
1064 | $crawler = $client->submit($form, $data); | 1176 | $crawler = $client->submit($form, $data); |
1065 | 1177 | ||
1066 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 1178 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
1067 | 1179 | ||
1068 | // Search on starred list | 1180 | // Search on starred list |
1069 | $crawler = $client->request('GET', '/starred/list'); | 1181 | $crawler = $client->request('GET', '/starred/list'); |
1070 | 1182 | ||
1183 | $entry = new Entry($this->getLoggedInUser()); | ||
1184 | $entry->setUrl('http://localhost/foo/bar'); | ||
1185 | $entry->setTitle('testeur'); | ||
1186 | $entry->setStarred(true); | ||
1187 | $this->getEntityManager()->persist($entry); | ||
1188 | $this->getEntityManager()->flush(); | ||
1189 | |||
1071 | $form = $crawler->filter('form[name=search]')->form(); | 1190 | $form = $crawler->filter('form[name=search]')->form(); |
1072 | $data = [ | 1191 | $data = [ |
1073 | 'search_entry[term]' => 'title', | 1192 | 'search_entry[term]' => 'testeur', |
1074 | ]; | 1193 | ]; |
1075 | 1194 | ||
1076 | $crawler = $client->submit($form, $data); | 1195 | $crawler = $client->submit($form, $data); |
1077 | 1196 | ||
1078 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1197 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1079 | 1198 | ||
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'); | 1199 | $crawler = $client->request('GET', '/archive/list'); |
1094 | 1200 | ||
1201 | // Added new article to test on archive list | ||
1202 | $entry = new Entry($this->getLoggedInUser()); | ||
1203 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | ||
1204 | $entry->setTitle('Le manège'); | ||
1205 | $entry->setArchived(true); | ||
1206 | $this->getEntityManager()->persist($entry); | ||
1207 | $this->getEntityManager()->flush(); | ||
1208 | |||
1095 | $form = $crawler->filter('form[name=search]')->form(); | 1209 | $form = $crawler->filter('form[name=search]')->form(); |
1096 | $data = [ | 1210 | $data = [ |
1097 | 'search_entry[term]' => 'manège', | 1211 | 'search_entry[term]' => 'manège', |
@@ -1100,7 +1214,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1100 | $crawler = $client->submit($form, $data); | 1214 | $crawler = $client->submit($form, $data); |
1101 | 1215 | ||
1102 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1216 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1103 | $client->request('GET', '/delete/'.$content->getId()); | 1217 | $client->request('GET', '/delete/' . $entry->getId()); |
1104 | 1218 | ||
1105 | // test on list of all articles | 1219 | // test on list of all articles |
1106 | $crawler = $client->request('GET', '/all/list'); | 1220 | $crawler = $client->request('GET', '/all/list'); |
@@ -1115,6 +1229,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1115 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | 1229 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
1116 | 1230 | ||
1117 | // test url search on list of all articles | 1231 | // test url search on list of all articles |
1232 | $entry = new Entry($this->getLoggedInUser()); | ||
1233 | $entry->setUrl('http://domain/qux'); | ||
1234 | $entry->setTitle('Le manège'); | ||
1235 | $entry->setArchived(true); | ||
1236 | $this->getEntityManager()->persist($entry); | ||
1237 | $this->getEntityManager()->flush(); | ||
1238 | |||
1118 | $crawler = $client->request('GET', '/all/list'); | 1239 | $crawler = $client->request('GET', '/all/list'); |
1119 | 1240 | ||
1120 | $form = $crawler->filter('form[name=search]')->form(); | 1241 | $form = $crawler->filter('form[name=search]')->form(); |
@@ -1138,4 +1259,134 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1138 | 1259 | ||
1139 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1260 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1140 | } | 1261 | } |
1262 | |||
1263 | public function dataForLanguage() | ||
1264 | { | ||
1265 | return [ | ||
1266 | 'ru' => [ | ||
1267 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | ||
1268 | 'ru', | ||
1269 | ], | ||
1270 | 'fr-FR' => [ | ||
1271 | 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', | ||
1272 | 'fr_FR', | ||
1273 | ], | ||
1274 | 'de' => [ | ||
1275 | 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', | ||
1276 | 'de', | ||
1277 | ], | ||
1278 | 'it' => [ | ||
1279 | 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | ||
1280 | 'it', | ||
1281 | ], | ||
1282 | 'zh_CN' => [ | ||
1283 | 'http://www.hao123.com/shequ?__noscript__-=1', | ||
1284 | 'zh_CN', | ||
1285 | ], | ||
1286 | 'de_AT' => [ | ||
1287 | 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728', | ||
1288 | 'de_AT', | ||
1289 | ], | ||
1290 | 'ru_RU' => [ | ||
1291 | 'http://netler.ru/ikt/windows-error-reporting.htm', | ||
1292 | 'ru_RU', | ||
1293 | ], | ||
1294 | 'pt_BR' => [ | ||
1295 | 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', | ||
1296 | 'pt_BR', | ||
1297 | ], | ||
1298 | 'fucked_list_of_languages' => [ | ||
1299 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', | ||
1300 | null, | ||
1301 | ], | ||
1302 | 'es-ES' => [ | ||
1303 | 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/', | ||
1304 | 'es_ES', | ||
1305 | ], | ||
1306 | ]; | ||
1307 | } | ||
1308 | |||
1309 | /** | ||
1310 | * @dataProvider dataForLanguage | ||
1311 | */ | ||
1312 | public function testLanguageValidation($url, $expectedLanguage) | ||
1313 | { | ||
1314 | $this->logInAs('admin'); | ||
1315 | $client = $this->getClient(); | ||
1316 | |||
1317 | $crawler = $client->request('GET', '/new'); | ||
1318 | |||
1319 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1320 | |||
1321 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1322 | |||
1323 | $data = [ | ||
1324 | 'entry[url]' => $url, | ||
1325 | ]; | ||
1326 | |||
1327 | $client->submit($form, $data); | ||
1328 | |||
1329 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1330 | |||
1331 | $content = $client->getContainer() | ||
1332 | ->get('doctrine.orm.entity_manager') | ||
1333 | ->getRepository('WallabagCoreBundle:Entry') | ||
1334 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
1335 | |||
1336 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
1337 | $this->assertSame($url, $content->getUrl()); | ||
1338 | $this->assertSame($expectedLanguage, $content->getLanguage()); | ||
1339 | } | ||
1340 | |||
1341 | /** | ||
1342 | * This test will require an internet connection. | ||
1343 | */ | ||
1344 | public function testRestrictedArticle() | ||
1345 | { | ||
1346 | $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475'; | ||
1347 | $this->logInAs('admin'); | ||
1348 | $client = $this->getClient(); | ||
1349 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
1350 | |||
1351 | // enable restricted access | ||
1352 | $client->getContainer()->get('craue_config')->set('restricted_access', 1); | ||
1353 | |||
1354 | // create a new site_credential | ||
1355 | $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
1356 | $credential = new SiteCredential($user); | ||
1357 | $credential->setHost('monde-diplomatique.fr'); | ||
1358 | $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo')); | ||
1359 | $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); | ||
1360 | |||
1361 | $em->persist($credential); | ||
1362 | $em->flush(); | ||
1363 | |||
1364 | $crawler = $client->request('GET', '/new'); | ||
1365 | |||
1366 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1367 | |||
1368 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1369 | |||
1370 | $data = [ | ||
1371 | 'entry[url]' => $url, | ||
1372 | ]; | ||
1373 | |||
1374 | $client->submit($form, $data); | ||
1375 | |||
1376 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1377 | |||
1378 | $crawler = $client->followRedirect(); | ||
1379 | |||
1380 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1381 | $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); | ||
1382 | |||
1383 | $content = $em | ||
1384 | ->getRepository('WallabagCoreBundle:Entry') | ||
1385 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
1386 | |||
1387 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
1388 | $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); | ||
1389 | |||
1390 | $client->getContainer()->get('craue_config')->set('restricted_access', 0); | ||
1391 | } | ||
1141 | } | 1392 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 32a18e26..ab7f23cc 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | |||
@@ -12,7 +12,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
12 | 12 | ||
13 | $client->request('GET', '/export/unread.csv'); | 13 | $client->request('GET', '/export/unread.csv'); |
14 | 14 | ||
15 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 15 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
16 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | 16 | $this->assertContains('login', $client->getResponse()->headers->get('location')); |
17 | } | 17 | } |
18 | 18 | ||
@@ -23,7 +23,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
23 | 23 | ||
24 | $client->request('GET', '/export/awesomeness.epub'); | 24 | $client->request('GET', '/export/awesomeness.epub'); |
25 | 25 | ||
26 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 26 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
27 | } | 27 | } |
28 | 28 | ||
29 | public function testUnknownFormatExport() | 29 | public function testUnknownFormatExport() |
@@ -33,7 +33,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
33 | 33 | ||
34 | $client->request('GET', '/export/unread.xslx'); | 34 | $client->request('GET', '/export/unread.xslx'); |
35 | 35 | ||
36 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 36 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
37 | } | 37 | } |
38 | 38 | ||
39 | public function testUnsupportedFormatExport() | 39 | public function testUnsupportedFormatExport() |
@@ -42,15 +42,15 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
42 | $client = $this->getClient(); | 42 | $client = $this->getClient(); |
43 | 43 | ||
44 | $client->request('GET', '/export/unread.doc'); | 44 | $client->request('GET', '/export/unread.doc'); |
45 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 45 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
46 | 46 | ||
47 | $content = $client->getContainer() | 47 | $content = $client->getContainer() |
48 | ->get('doctrine.orm.entity_manager') | 48 | ->get('doctrine.orm.entity_manager') |
49 | ->getRepository('WallabagCoreBundle:Entry') | 49 | ->getRepository('WallabagCoreBundle:Entry') |
50 | ->findOneByUsernameAndNotArchived('admin'); | 50 | ->findOneByUsernameAndNotArchived('admin'); |
51 | 51 | ||
52 | $client->request('GET', '/export/'.$content->getId().'.doc'); | 52 | $client->request('GET', '/export/' . $content->getId() . '.doc'); |
53 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 53 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
54 | } | 54 | } |
55 | 55 | ||
56 | public function testBadEntryId() | 56 | public function testBadEntryId() |
@@ -60,7 +60,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
60 | 60 | ||
61 | $client->request('GET', '/export/0.mobi'); | 61 | $client->request('GET', '/export/0.mobi'); |
62 | 62 | ||
63 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 63 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
64 | } | 64 | } |
65 | 65 | ||
66 | public function testEpubExport() | 66 | public function testEpubExport() |
@@ -72,12 +72,12 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
72 | $crawler = $client->request('GET', '/export/archive.epub'); | 72 | $crawler = $client->request('GET', '/export/archive.epub'); |
73 | ob_end_clean(); | 73 | ob_end_clean(); |
74 | 74 | ||
75 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 75 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
76 | 76 | ||
77 | $headers = $client->getResponse()->headers; | 77 | $headers = $client->getResponse()->headers; |
78 | $this->assertEquals('application/epub+zip', $headers->get('content-type')); | 78 | $this->assertSame('application/epub+zip', $headers->get('content-type')); |
79 | $this->assertEquals('attachment; filename="Archive articles.epub"', $headers->get('content-disposition')); | 79 | $this->assertSame('attachment; filename="Archive articles.epub"', $headers->get('content-disposition')); |
80 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | 80 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); |
81 | } | 81 | } |
82 | 82 | ||
83 | public function testMobiExport() | 83 | public function testMobiExport() |
@@ -91,15 +91,15 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
91 | ->findOneByUsernameAndNotArchived('admin'); | 91 | ->findOneByUsernameAndNotArchived('admin'); |
92 | 92 | ||
93 | ob_start(); | 93 | ob_start(); |
94 | $crawler = $client->request('GET', '/export/'.$content->getId().'.mobi'); | 94 | $crawler = $client->request('GET', '/export/' . $content->getId() . '.mobi'); |
95 | ob_end_clean(); | 95 | ob_end_clean(); |
96 | 96 | ||
97 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 97 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
98 | 98 | ||
99 | $headers = $client->getResponse()->headers; | 99 | $headers = $client->getResponse()->headers; |
100 | $this->assertEquals('application/x-mobipocket-ebook', $headers->get('content-type')); | 100 | $this->assertSame('application/x-mobipocket-ebook', $headers->get('content-type')); |
101 | $this->assertEquals('attachment; filename="'.preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()).'.mobi"', $headers->get('content-disposition')); | 101 | $this->assertSame('attachment; filename="' . preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()) . '.mobi"', $headers->get('content-disposition')); |
102 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | 102 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); |
103 | } | 103 | } |
104 | 104 | ||
105 | public function testPdfExport() | 105 | public function testPdfExport() |
@@ -111,23 +111,23 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
111 | $crawler = $client->request('GET', '/export/all.pdf'); | 111 | $crawler = $client->request('GET', '/export/all.pdf'); |
112 | ob_end_clean(); | 112 | ob_end_clean(); |
113 | 113 | ||
114 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 114 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
115 | 115 | ||
116 | $headers = $client->getResponse()->headers; | 116 | $headers = $client->getResponse()->headers; |
117 | $this->assertEquals('application/pdf', $headers->get('content-type')); | 117 | $this->assertSame('application/pdf', $headers->get('content-type')); |
118 | $this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition')); | 118 | $this->assertSame('attachment; filename="All articles.pdf"', $headers->get('content-disposition')); |
119 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | 119 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); |
120 | 120 | ||
121 | ob_start(); | 121 | ob_start(); |
122 | $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo-bar'); | 122 | $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo-bar'); |
123 | ob_end_clean(); | 123 | ob_end_clean(); |
124 | 124 | ||
125 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 125 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
126 | 126 | ||
127 | $headers = $client->getResponse()->headers; | 127 | $headers = $client->getResponse()->headers; |
128 | $this->assertEquals('application/pdf', $headers->get('content-type')); | 128 | $this->assertSame('application/pdf', $headers->get('content-type')); |
129 | $this->assertEquals('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); | 129 | $this->assertSame('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); |
130 | $this->assertEquals('binary', $headers->get('content-transfer-encoding')); | 130 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); |
131 | } | 131 | } |
132 | 132 | ||
133 | public function testTxtExport() | 133 | public function testTxtExport() |
@@ -139,12 +139,12 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
139 | $crawler = $client->request('GET', '/export/all.txt'); | 139 | $crawler = $client->request('GET', '/export/all.txt'); |
140 | ob_end_clean(); | 140 | ob_end_clean(); |
141 | 141 | ||
142 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 142 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
143 | 143 | ||
144 | $headers = $client->getResponse()->headers; | 144 | $headers = $client->getResponse()->headers; |
145 | $this->assertEquals('text/plain; charset=UTF-8', $headers->get('content-type')); | 145 | $this->assertSame('text/plain; charset=UTF-8', $headers->get('content-type')); |
146 | $this->assertEquals('attachment; filename="All articles.txt"', $headers->get('content-disposition')); | 146 | $this->assertSame('attachment; filename="All articles.txt"', $headers->get('content-disposition')); |
147 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 147 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); |
148 | } | 148 | } |
149 | 149 | ||
150 | public function testCsvExport() | 150 | public function testCsvExport() |
@@ -169,19 +169,19 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
169 | $crawler = $client->request('GET', '/export/archive.csv'); | 169 | $crawler = $client->request('GET', '/export/archive.csv'); |
170 | ob_end_clean(); | 170 | ob_end_clean(); |
171 | 171 | ||
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 172 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
173 | 173 | ||
174 | $headers = $client->getResponse()->headers; | 174 | $headers = $client->getResponse()->headers; |
175 | $this->assertEquals('application/csv', $headers->get('content-type')); | 175 | $this->assertSame('application/csv', $headers->get('content-type')); |
176 | $this->assertEquals('attachment; filename="Archive articles.csv"', $headers->get('content-disposition')); | 176 | $this->assertSame('attachment; filename="Archive articles.csv"', $headers->get('content-disposition')); |
177 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 177 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); |
178 | 178 | ||
179 | $csv = str_getcsv($client->getResponse()->getContent(), "\n"); | 179 | $csv = str_getcsv($client->getResponse()->getContent(), "\n"); |
180 | 180 | ||
181 | $this->assertGreaterThan(1, $csv); | 181 | $this->assertGreaterThan(1, $csv); |
182 | // +1 for title line | 182 | // +1 for title line |
183 | $this->assertEquals(count($contentInDB) + 1, count($csv)); | 183 | $this->assertSame(count($contentInDB) + 1, count($csv)); |
184 | $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); | 184 | $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); |
185 | $this->assertContains($contentInDB[0]['title'], $csv[1]); | 185 | $this->assertContains($contentInDB[0]['title'], $csv[1]); |
186 | $this->assertContains($contentInDB[0]['url'], $csv[1]); | 186 | $this->assertContains($contentInDB[0]['url'], $csv[1]); |
187 | $this->assertContains($contentInDB[0]['content'], $csv[1]); | 187 | $this->assertContains($contentInDB[0]['content'], $csv[1]); |
@@ -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() |
@@ -207,15 +205,15 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
207 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 205 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
208 | 206 | ||
209 | ob_start(); | 207 | ob_start(); |
210 | $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); | 208 | $crawler = $client->request('GET', '/export/' . $contentInDB->getId() . '.json'); |
211 | ob_end_clean(); | 209 | ob_end_clean(); |
212 | 210 | ||
213 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 211 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
214 | 212 | ||
215 | $headers = $client->getResponse()->headers; | 213 | $headers = $client->getResponse()->headers; |
216 | $this->assertEquals('application/json', $headers->get('content-type')); | 214 | $this->assertSame('application/json', $headers->get('content-type')); |
217 | $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition')); | 215 | $this->assertSame('attachment; filename="' . $contentInDB->getTitle() . '.json"', $headers->get('content-disposition')); |
218 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 216 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); |
219 | 217 | ||
220 | $content = json_decode($client->getResponse()->getContent(), true); | 218 | $content = json_decode($client->getResponse()->getContent(), true); |
221 | $this->assertArrayHasKey('id', $content[0]); | 219 | $this->assertArrayHasKey('id', $content[0]); |
@@ -232,16 +230,17 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
232 | $this->assertArrayHasKey('created_at', $content[0]); | 230 | $this->assertArrayHasKey('created_at', $content[0]); |
233 | $this->assertArrayHasKey('updated_at', $content[0]); | 231 | $this->assertArrayHasKey('updated_at', $content[0]); |
234 | 232 | ||
235 | $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']); | 233 | $this->assertSame((int) $contentInDB->isArchived(), $content[0]['is_archived']); |
236 | $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']); | 234 | $this->assertSame((int) $contentInDB->isStarred(), $content[0]['is_starred']); |
237 | $this->assertEquals($contentInDB->getTitle(), $content[0]['title']); | 235 | $this->assertSame($contentInDB->getTitle(), $content[0]['title']); |
238 | $this->assertEquals($contentInDB->getUrl(), $content[0]['url']); | 236 | $this->assertSame($contentInDB->getUrl(), $content[0]['url']); |
239 | $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); | 237 | $this->assertSame([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); |
240 | $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']); | 238 | $this->assertSame($contentInDB->getMimetype(), $content[0]['mimetype']); |
241 | $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); | 239 | $this->assertSame($contentInDB->getLanguage(), $content[0]['language']); |
242 | $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); | 240 | $this->assertSame($contentInDB->getReadingtime(), $content[0]['reading_time']); |
243 | $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); | 241 | $this->assertSame($contentInDB->getDomainname(), $content[0]['domain_name']); |
244 | $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']); | 242 | $this->assertContains('baz', $content[0]['tags']); |
243 | $this->assertContains('foo', $content[0]['tags']); | ||
245 | } | 244 | } |
246 | 245 | ||
247 | public function testXmlExport() | 246 | public function testXmlExport() |
@@ -264,16 +263,16 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
264 | $crawler = $client->request('GET', '/export/unread.xml'); | 263 | $crawler = $client->request('GET', '/export/unread.xml'); |
265 | ob_end_clean(); | 264 | ob_end_clean(); |
266 | 265 | ||
267 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 266 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
268 | 267 | ||
269 | $headers = $client->getResponse()->headers; | 268 | $headers = $client->getResponse()->headers; |
270 | $this->assertEquals('application/xml', $headers->get('content-type')); | 269 | $this->assertSame('application/xml', $headers->get('content-type')); |
271 | $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); | 270 | $this->assertSame('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); |
272 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 271 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); |
273 | 272 | ||
274 | $content = new \SimpleXMLElement($client->getResponse()->getContent()); | 273 | $content = new \SimpleXMLElement($client->getResponse()->getContent()); |
275 | $this->assertGreaterThan(0, $content->count()); | 274 | $this->assertGreaterThan(0, $content->count()); |
276 | $this->assertEquals(count($contentInDB), $content->count()); | 275 | $this->assertSame(count($contentInDB), $content->count()); |
277 | $this->assertNotEmpty('id', (string) $content->entry[0]->id); | 276 | $this->assertNotEmpty('id', (string) $content->entry[0]->id); |
278 | $this->assertNotEmpty('title', (string) $content->entry[0]->title); | 277 | $this->assertNotEmpty('title', (string) $content->entry[0]->title); |
279 | $this->assertNotEmpty('url', (string) $content->entry[0]->url); | 278 | $this->assertNotEmpty('url', (string) $content->entry[0]->url); |
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 5a59654d..c6ca4937 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | |||
@@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |||
6 | 6 | ||
7 | class RssControllerTest extends WallabagCoreTestCase | 7 | class RssControllerTest extends WallabagCoreTestCase |
8 | { | 8 | { |
9 | public function validateDom($xml, $type, $nb = null) | 9 | public function validateDom($xml, $type, $urlPagination, $nb = null) |
10 | { | 10 | { |
11 | $doc = new \DOMDocument(); | 11 | $doc = new \DOMDocument(); |
12 | $doc->loadXML($xml); | 12 | $doc->loadXML($xml); |
@@ -16,36 +16,36 @@ class RssControllerTest extends WallabagCoreTestCase | |||
16 | if (null === $nb) { | 16 | if (null === $nb) { |
17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); | 17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); |
18 | } else { | 18 | } else { |
19 | $this->assertEquals($nb, $xpath->query('//item')->length); | 19 | $this->assertSame($nb, $xpath->query('//item')->length); |
20 | } | 20 | } |
21 | 21 | ||
22 | $this->assertEquals(1, $xpath->query('/rss')->length); | 22 | $this->assertSame(1, $xpath->query('/rss')->length); |
23 | $this->assertEquals(1, $xpath->query('/rss/channel')->length); | 23 | $this->assertSame(1, $xpath->query('/rss/channel')->length); |
24 | 24 | ||
25 | $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); | 25 | $this->assertSame(1, $xpath->query('/rss/channel/title')->length); |
26 | $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); | 26 | $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); |
27 | 27 | ||
28 | $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); | 28 | $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); |
29 | 29 | ||
30 | $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length); | 30 | $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); |
31 | $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); | 31 | $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); |
32 | 32 | ||
33 | $this->assertEquals(1, $xpath->query('/rss/channel/description')->length); | 33 | $this->assertSame(1, $xpath->query('/rss/channel/description')->length); |
34 | $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); | 34 | $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); |
35 | 35 | ||
36 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); | 36 | $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); |
37 | $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); | 37 | $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); |
38 | 38 | ||
39 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); | 39 | $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); |
40 | $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); | 40 | $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); |
41 | 41 | ||
42 | foreach ($xpath->query('//item') as $item) { | 42 | foreach ($xpath->query('//item') as $item) { |
43 | $this->assertEquals(1, $xpath->query('title', $item)->length); | 43 | $this->assertSame(1, $xpath->query('title', $item)->length); |
44 | $this->assertEquals(1, $xpath->query('source', $item)->length); | 44 | $this->assertSame(1, $xpath->query('source', $item)->length); |
45 | $this->assertEquals(1, $xpath->query('link', $item)->length); | 45 | $this->assertSame(1, $xpath->query('link', $item)->length); |
46 | $this->assertEquals(1, $xpath->query('guid', $item)->length); | 46 | $this->assertSame(1, $xpath->query('guid', $item)->length); |
47 | $this->assertEquals(1, $xpath->query('pubDate', $item)->length); | 47 | $this->assertSame(1, $xpath->query('pubDate', $item)->length); |
48 | $this->assertEquals(1, $xpath->query('description', $item)->length); | 48 | $this->assertSame(1, $xpath->query('description', $item)->length); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
@@ -73,7 +73,7 @@ class RssControllerTest extends WallabagCoreTestCase | |||
73 | 73 | ||
74 | $client->request('GET', $url); | 74 | $client->request('GET', $url); |
75 | 75 | ||
76 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 76 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
77 | } | 77 | } |
78 | 78 | ||
79 | public function testUnread() | 79 | public function testUnread() |
@@ -92,9 +92,9 @@ class RssControllerTest extends WallabagCoreTestCase | |||
92 | 92 | ||
93 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | 93 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); |
94 | 94 | ||
95 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 95 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
96 | 96 | ||
97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 2); | 97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); |
98 | } | 98 | } |
99 | 99 | ||
100 | public function testStarred() | 100 | public function testStarred() |
@@ -114,9 +114,9 @@ class RssControllerTest extends WallabagCoreTestCase | |||
114 | $client = $this->getClient(); | 114 | $client = $this->getClient(); |
115 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); | 115 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); |
116 | 116 | ||
117 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); | 117 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); |
118 | 118 | ||
119 | $this->validateDom($client->getResponse()->getContent(), 'starred'); | 119 | $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); |
120 | } | 120 | } |
121 | 121 | ||
122 | public function testArchives() | 122 | public function testArchives() |
@@ -136,9 +136,9 @@ class RssControllerTest extends WallabagCoreTestCase | |||
136 | $client = $this->getClient(); | 136 | $client = $this->getClient(); |
137 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); | 137 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); |
138 | 138 | ||
139 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 139 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
140 | 140 | ||
141 | $this->validateDom($client->getResponse()->getContent(), 'archive'); | 141 | $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); |
142 | } | 142 | } |
143 | 143 | ||
144 | public function testPagination() | 144 | public function testPagination() |
@@ -158,14 +158,39 @@ class RssControllerTest extends WallabagCoreTestCase | |||
158 | $client = $this->getClient(); | 158 | $client = $this->getClient(); |
159 | 159 | ||
160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | 160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); |
161 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 161 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
162 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | 162 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
163 | 163 | ||
164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); | 164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); |
165 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 165 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
166 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | 166 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
167 | 167 | ||
168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); | 168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); |
169 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 169 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
170 | } | ||
171 | |||
172 | public function testTags() | ||
173 | { | ||
174 | $client = $this->getClient(); | ||
175 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
176 | $user = $em | ||
177 | ->getRepository('WallabagUserBundle:User') | ||
178 | ->findOneByUsername('admin'); | ||
179 | |||
180 | $config = $user->getConfig(); | ||
181 | $config->setRssToken('SUPERTOKEN'); | ||
182 | $config->setRssLimit(null); | ||
183 | $em->persist($config); | ||
184 | $em->flush(); | ||
185 | |||
186 | $client = $this->getClient(); | ||
187 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); | ||
188 | |||
189 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
190 | |||
191 | $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); | ||
192 | |||
193 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); | ||
194 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
170 | } | 195 | } |
171 | } | 196 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php index 9b8b5702..6005c0df 100644 --- a/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php | |||
@@ -17,7 +17,7 @@ class SettingsControllerTest extends WallabagCoreTestCase | |||
17 | 17 | ||
18 | $crawler = $client->request('GET', '/settings'); | 18 | $crawler = $client->request('GET', '/settings'); |
19 | 19 | ||
20 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 20 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
21 | } | 21 | } |
22 | 22 | ||
23 | public function testSettingsWithNormalUser() | 23 | public function testSettingsWithNormalUser() |
@@ -27,6 +27,6 @@ class SettingsControllerTest extends WallabagCoreTestCase | |||
27 | 27 | ||
28 | $crawler = $client->request('GET', '/settings'); | 28 | $crawler = $client->request('GET', '/settings'); |
29 | 29 | ||
30 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 30 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
31 | } | 31 | } |
32 | } | 32 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php new file mode 100644 index 00000000..87ea2867 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php | |||
@@ -0,0 +1,139 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Client; | ||
6 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
7 | use Wallabag\CoreBundle\Entity\SiteCredential; | ||
8 | |||
9 | class SiteCredentialControllerTest extends WallabagCoreTestCase | ||
10 | { | ||
11 | public function testListSiteCredential() | ||
12 | { | ||
13 | $this->logInAs('admin'); | ||
14 | $client = $this->getClient(); | ||
15 | |||
16 | $crawler = $client->request('GET', '/site-credentials/'); | ||
17 | |||
18 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
19 | |||
20 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
21 | |||
22 | $this->assertContains('site_credential.description', $body); | ||
23 | $this->assertContains('site_credential.list.create_new_one', $body); | ||
24 | } | ||
25 | |||
26 | public function testNewSiteCredential() | ||
27 | { | ||
28 | $this->logInAs('admin'); | ||
29 | $client = $this->getClient(); | ||
30 | |||
31 | $crawler = $client->request('GET', '/site-credentials/new'); | ||
32 | |||
33 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
34 | |||
35 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
36 | |||
37 | $this->assertContains('site_credential.new_site_credential', $body); | ||
38 | $this->assertContains('site_credential.form.back_to_list', $body); | ||
39 | |||
40 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | ||
41 | |||
42 | $data = [ | ||
43 | 'site_credential[host]' => 'google.io', | ||
44 | 'site_credential[username]' => 'sergei', | ||
45 | 'site_credential[password]' => 'microsoft', | ||
46 | ]; | ||
47 | |||
48 | $client->submit($form, $data); | ||
49 | |||
50 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
51 | |||
52 | $crawler = $client->followRedirect(); | ||
53 | |||
54 | $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); | ||
55 | } | ||
56 | |||
57 | public function testEditSiteCredential() | ||
58 | { | ||
59 | $this->logInAs('admin'); | ||
60 | $client = $this->getClient(); | ||
61 | |||
62 | $credential = $this->createSiteCredential($client); | ||
63 | |||
64 | $crawler = $client->request('GET', '/site-credentials/' . $credential->getId() . '/edit'); | ||
65 | |||
66 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
67 | |||
68 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
69 | |||
70 | $this->assertContains('site_credential.edit_site_credential', $body); | ||
71 | $this->assertContains('site_credential.form.back_to_list', $body); | ||
72 | |||
73 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | ||
74 | |||
75 | $data = [ | ||
76 | 'site_credential[host]' => 'google.io', | ||
77 | 'site_credential[username]' => 'larry', | ||
78 | 'site_credential[password]' => 'microsoft', | ||
79 | ]; | ||
80 | |||
81 | $client->submit($form, $data); | ||
82 | |||
83 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
84 | |||
85 | $crawler = $client->followRedirect(); | ||
86 | |||
87 | $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); | ||
88 | } | ||
89 | |||
90 | public function testEditFromADifferentUserSiteCredential() | ||
91 | { | ||
92 | $this->logInAs('admin'); | ||
93 | $client = $this->getClient(); | ||
94 | |||
95 | $credential = $this->createSiteCredential($client); | ||
96 | |||
97 | $this->logInAs('bob'); | ||
98 | |||
99 | $client->request('GET', '/site-credentials/' . $credential->getId() . '/edit'); | ||
100 | |||
101 | $this->assertSame(403, $client->getResponse()->getStatusCode()); | ||
102 | } | ||
103 | |||
104 | public function testDeleteSiteCredential() | ||
105 | { | ||
106 | $this->logInAs('admin'); | ||
107 | $client = $this->getClient(); | ||
108 | |||
109 | $credential = $this->createSiteCredential($client); | ||
110 | |||
111 | $crawler = $client->request('GET', '/site-credentials/' . $credential->getId() . '/edit'); | ||
112 | |||
113 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
114 | |||
115 | $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form(); | ||
116 | |||
117 | $client->submit($deleteForm, []); | ||
118 | |||
119 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
120 | |||
121 | $crawler = $client->followRedirect(); | ||
122 | |||
123 | $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); | ||
124 | } | ||
125 | |||
126 | private function createSiteCredential(Client $client) | ||
127 | { | ||
128 | $credential = new SiteCredential($this->getLoggedInUser()); | ||
129 | $credential->setHost('google.io'); | ||
130 | $credential->setUsername('sergei'); | ||
131 | $credential->setPassword('microsoft'); | ||
132 | |||
133 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
134 | $em->persist($credential); | ||
135 | $em->flush(); | ||
136 | |||
137 | return $credential; | ||
138 | } | ||
139 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php b/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php index 98a37b50..17847937 100644 --- a/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php | |||
@@ -13,7 +13,7 @@ class StaticControllerTest extends WallabagCoreTestCase | |||
13 | 13 | ||
14 | $client->request('GET', '/about'); | 14 | $client->request('GET', '/about'); |
15 | 15 | ||
16 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 16 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
17 | } | 17 | } |
18 | 18 | ||
19 | public function testHowto() | 19 | public function testHowto() |
@@ -23,6 +23,6 @@ class StaticControllerTest extends WallabagCoreTestCase | |||
23 | 23 | ||
24 | $client->request('GET', '/howto'); | 24 | $client->request('GET', '/howto'); |
25 | 25 | ||
26 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 26 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
27 | } | 27 | } |
28 | } | 28 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index fa1a3539..5a973a7e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -3,11 +3,13 @@ | |||
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 |
9 | { | 10 | { |
10 | public $tagName = 'opensource'; | 11 | public $tagName = 'opensource'; |
12 | public $caseTagName = 'OpenSource'; | ||
11 | 13 | ||
12 | public function testList() | 14 | public function testList() |
13 | { | 15 | { |
@@ -16,7 +18,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
16 | 18 | ||
17 | $client->request('GET', '/tag/list'); | 19 | $client->request('GET', '/tag/list'); |
18 | 20 | ||
19 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 21 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
20 | } | 22 | } |
21 | 23 | ||
22 | public function testAddTagToEntry() | 24 | public function testAddTagToEntry() |
@@ -24,40 +26,34 @@ class TagControllerTest extends WallabagCoreTestCase | |||
24 | $this->logInAs('admin'); | 26 | $this->logInAs('admin'); |
25 | $client = $this->getClient(); | 27 | $client = $this->getClient(); |
26 | 28 | ||
27 | $entry = $client->getContainer() | 29 | $entry = new Entry($this->getLoggedInUser()); |
28 | ->get('doctrine.orm.entity_manager') | 30 | $entry->setUrl('http://0.0.0.0/foo'); |
29 | ->getRepository('WallabagCoreBundle:Entry') | 31 | $this->getEntityManager()->persist($entry); |
30 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 32 | $this->getEntityManager()->flush(); |
33 | $this->getEntityManager()->clear(); | ||
31 | 34 | ||
32 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 35 | $crawler = $client->request('GET', '/view/' . $entry->getId()); |
33 | 36 | ||
34 | $form = $crawler->filter('form[name=tag]')->form(); | 37 | $form = $crawler->filter('form[name=tag]')->form(); |
35 | 38 | ||
36 | $data = [ | 39 | $data = [ |
37 | 'tag[label]' => $this->tagName, | 40 | 'tag[label]' => $this->caseTagName, |
38 | ]; | 41 | ]; |
39 | 42 | ||
40 | $client->submit($form, $data); | 43 | $client->submit($form, $data); |
41 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 44 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
42 | 45 | ||
43 | // be sure to reload the entry | 46 | // be sure to reload the entry |
44 | $entry = $client->getContainer() | 47 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
45 | ->get('doctrine.orm.entity_manager') | 48 | $this->assertCount(1, $entry->getTags()); |
46 | ->getRepository('WallabagCoreBundle:Entry') | 49 | $this->assertContains($this->tagName, $entry->getTags()); |
47 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | ||
48 | |||
49 | $this->assertEquals(3, count($entry->getTags())); | ||
50 | 50 | ||
51 | // tag already exists and already assigned | 51 | // tag already exists and already assigned |
52 | $client->submit($form, $data); | 52 | $client->submit($form, $data); |
53 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 53 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
54 | 54 | ||
55 | $newEntry = $client->getContainer() | 55 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
56 | ->get('doctrine.orm.entity_manager') | 56 | $this->assertCount(1, $entry->getTags()); |
57 | ->getRepository('WallabagCoreBundle:Entry') | ||
58 | ->find($entry->getId()); | ||
59 | |||
60 | $this->assertEquals(3, count($newEntry->getTags())); | ||
61 | 57 | ||
62 | // tag already exists but still not assigned to this entry | 58 | // tag already exists but still not assigned to this entry |
63 | $data = [ | 59 | $data = [ |
@@ -65,14 +61,10 @@ class TagControllerTest extends WallabagCoreTestCase | |||
65 | ]; | 61 | ]; |
66 | 62 | ||
67 | $client->submit($form, $data); | 63 | $client->submit($form, $data); |
68 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 64 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
69 | |||
70 | $newEntry = $client->getContainer() | ||
71 | ->get('doctrine.orm.entity_manager') | ||
72 | ->getRepository('WallabagCoreBundle:Entry') | ||
73 | ->find($entry->getId()); | ||
74 | 65 | ||
75 | $this->assertEquals(3, count($newEntry->getTags())); | 66 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
67 | $this->assertCount(2, $entry->getTags()); | ||
76 | } | 68 | } |
77 | 69 | ||
78 | public function testAddMultipleTagToEntry() | 70 | public function testAddMultipleTagToEntry() |
@@ -85,16 +77,16 @@ class TagControllerTest extends WallabagCoreTestCase | |||
85 | ->getRepository('WallabagCoreBundle:Entry') | 77 | ->getRepository('WallabagCoreBundle:Entry') |
86 | ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); | 78 | ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); |
87 | 79 | ||
88 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 80 | $crawler = $client->request('GET', '/view/' . $entry->getId()); |
89 | 81 | ||
90 | $form = $crawler->filter('form[name=tag]')->form(); | 82 | $form = $crawler->filter('form[name=tag]')->form(); |
91 | 83 | ||
92 | $data = [ | 84 | $data = [ |
93 | 'tag[label]' => 'foo2, bar2', | 85 | 'tag[label]' => 'foo2, Bar2', |
94 | ]; | 86 | ]; |
95 | 87 | ||
96 | $client->submit($form, $data); | 88 | $client->submit($form, $data); |
97 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 89 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
98 | 90 | ||
99 | $newEntry = $client->getContainer() | 91 | $newEntry = $client->getContainer() |
100 | ->get('doctrine.orm.entity_manager') | 92 | ->get('doctrine.orm.entity_manager') |
@@ -107,8 +99,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
107 | } | 99 | } |
108 | 100 | ||
109 | $this->assertGreaterThanOrEqual(2, count($tags)); | 101 | $this->assertGreaterThanOrEqual(2, count($tags)); |
110 | $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | 102 | $this->assertNotFalse(array_search('foo2', $tags, true), 'Tag foo2 is assigned to the entry'); |
111 | $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); | 103 | $this->assertNotFalse(array_search('bar2', $tags, true), 'Tag bar2 is assigned to the entry'); |
112 | } | 104 | } |
113 | 105 | ||
114 | public function testRemoveTagFromEntry() | 106 | public function testRemoveTagFromEntry() |
@@ -116,32 +108,37 @@ class TagControllerTest extends WallabagCoreTestCase | |||
116 | $this->logInAs('admin'); | 108 | $this->logInAs('admin'); |
117 | $client = $this->getClient(); | 109 | $client = $this->getClient(); |
118 | 110 | ||
119 | $entry = $client->getContainer() | 111 | $tag = new Tag(); |
120 | ->get('doctrine.orm.entity_manager') | 112 | $tag->setLabel($this->tagName); |
121 | ->getRepository('WallabagCoreBundle:Entry') | 113 | $entry = new Entry($this->getLoggedInUser()); |
122 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 114 | $entry->setUrl('http://0.0.0.0/foo'); |
123 | 115 | $entry->addTag($tag); | |
124 | $tag = $client->getContainer() | 116 | $this->getEntityManager()->persist($entry); |
125 | ->get('doctrine.orm.entity_manager') | 117 | $this->getEntityManager()->flush(); |
126 | ->getRepository('WallabagCoreBundle:Tag') | 118 | $this->getEntityManager()->clear(); |
127 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | 119 | |
128 | 120 | // We make a first request to set an history and test redirection after tag deletion | |
129 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 121 | $client->request('GET', '/view/' . $entry->getId()); |
130 | 122 | $entryUri = $client->getRequest()->getUri(); | |
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); |
132 | 124 | ||
125 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
126 | $this->assertSame($entryUri, $client->getResponse()->getTargetUrl()); | ||
127 | |||
128 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) | ||
129 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); | ||
133 | $this->assertNotContains($this->tagName, $entry->getTags()); | 130 | $this->assertNotContains($this->tagName, $entry->getTags()); |
134 | 131 | ||
135 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 132 | $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); |
136 | 133 | ||
137 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 134 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
138 | 135 | ||
139 | $tag = $client->getContainer() | 136 | $tag = $client->getContainer() |
140 | ->get('doctrine.orm.entity_manager') | 137 | ->get('doctrine.orm.entity_manager') |
141 | ->getRepository('WallabagCoreBundle:Tag') | 138 | ->getRepository('WallabagCoreBundle:Tag') |
142 | ->findOneByLabel($this->tagName); | 139 | ->findOneByLabel($this->tagName); |
143 | 140 | ||
144 | $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag'); | 141 | $this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag'); |
145 | } | 142 | } |
146 | 143 | ||
147 | public function testShowEntriesForTagAction() | 144 | public function testShowEntriesForTagAction() |
@@ -170,9 +167,9 @@ class TagControllerTest extends WallabagCoreTestCase | |||
170 | ->getRepository('WallabagCoreBundle:Tag') | 167 | ->getRepository('WallabagCoreBundle:Tag') |
171 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | 168 | ->findOneByEntryAndTagLabel($entry, $this->tagName); |
172 | 169 | ||
173 | $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); | 170 | $crawler = $client->request('GET', '/tag/list/' . $tag->getSlug()); |
174 | 171 | ||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 172 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
176 | $this->assertCount(1, $crawler->filter('[id*="entry-"]')); | 173 | $this->assertCount(1, $crawler->filter('[id*="entry-"]')); |
177 | 174 | ||
178 | $entry->removeTag($tag); | 175 | $entry->removeTag($tag); |
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php index 84a54d3a..0dbd9f70 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php | |||
@@ -13,15 +13,6 @@ use Wallabag\CoreBundle\Event\Listener\LocaleListener; | |||
13 | 13 | ||
14 | class LocaleListenerTest extends \PHPUnit_Framework_TestCase | 14 | class LocaleListenerTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
16 | private function getEvent(Request $request) | ||
17 | { | ||
18 | $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') | ||
19 | ->disableOriginalConstructor() | ||
20 | ->getMock(); | ||
21 | |||
22 | return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); | ||
23 | } | ||
24 | |||
25 | public function testWithoutSession() | 16 | public function testWithoutSession() |
26 | { | 17 | { |
27 | $request = Request::create('/'); | 18 | $request = Request::create('/'); |
@@ -30,7 +21,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
30 | $event = $this->getEvent($request); | 21 | $event = $this->getEvent($request); |
31 | 22 | ||
32 | $listener->onKernelRequest($event); | 23 | $listener->onKernelRequest($event); |
33 | $this->assertEquals('en', $request->getLocale()); | 24 | $this->assertSame('en', $request->getLocale()); |
34 | } | 25 | } |
35 | 26 | ||
36 | public function testWithPreviousSession() | 27 | public function testWithPreviousSession() |
@@ -44,7 +35,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
44 | $event = $this->getEvent($request); | 35 | $event = $this->getEvent($request); |
45 | 36 | ||
46 | $listener->onKernelRequest($event); | 37 | $listener->onKernelRequest($event); |
47 | $this->assertEquals('fr', $request->getLocale()); | 38 | $this->assertSame('fr', $request->getLocale()); |
48 | } | 39 | } |
49 | 40 | ||
50 | public function testLocaleFromRequestAttribute() | 41 | public function testLocaleFromRequestAttribute() |
@@ -59,8 +50,8 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
59 | $event = $this->getEvent($request); | 50 | $event = $this->getEvent($request); |
60 | 51 | ||
61 | $listener->onKernelRequest($event); | 52 | $listener->onKernelRequest($event); |
62 | $this->assertEquals('en', $request->getLocale()); | 53 | $this->assertSame('en', $request->getLocale()); |
63 | $this->assertEquals('es', $request->getSession()->get('_locale')); | 54 | $this->assertSame('es', $request->getSession()->get('_locale')); |
64 | } | 55 | } |
65 | 56 | ||
66 | public function testSubscribedEvents() | 57 | public function testSubscribedEvents() |
@@ -81,6 +72,15 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
81 | $event | 72 | $event |
82 | ); | 73 | ); |
83 | 74 | ||
84 | $this->assertEquals('fr', $request->getLocale()); | 75 | $this->assertSame('fr', $request->getLocale()); |
76 | } | ||
77 | |||
78 | private function getEvent(Request $request) | ||
79 | { | ||
80 | $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') | ||
81 | ->disableOriginalConstructor() | ||
82 | ->getMock(); | ||
83 | |||
84 | return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); | ||
85 | } | 85 | } |
86 | } | 86 | } |
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index 45aecc63..5ffe1ca6 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php | |||
@@ -32,7 +32,7 @@ class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
32 | 32 | ||
33 | $listener->onInteractiveLogin($event); | 33 | $listener->onInteractiveLogin($event); |
34 | 34 | ||
35 | $this->assertEquals('fr', $session->get('_locale')); | 35 | $this->assertSame('fr', $session->get('_locale')); |
36 | } | 36 | } |
37 | 37 | ||
38 | public function testWithoutLanguage() | 38 | public function testWithoutLanguage() |
@@ -53,6 +53,6 @@ class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
53 | 53 | ||
54 | $listener->onInteractiveLogin($event); | 54 | $listener->onInteractiveLogin($event); |
55 | 55 | ||
56 | $this->assertEquals('', $session->get('_locale')); | 56 | $this->assertNull($session->get('_locale')); |
57 | } | 57 | } |
58 | } | 58 | } |
diff --git a/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php index b8cd0fad..64e3c6d9 100644 --- a/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php +++ b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php | |||
@@ -46,12 +46,12 @@ class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase | |||
46 | 46 | ||
47 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); | 47 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); |
48 | 48 | ||
49 | $this->assertEquals($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName()); | 49 | $this->assertSame($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName()); |
50 | 50 | ||
51 | $subscriber->loadClassMetadata($metaDataEvent); | 51 | $subscriber->loadClassMetadata($metaDataEvent); |
52 | 52 | ||
53 | $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); | 53 | $this->assertSame($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); |
54 | $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); | 54 | $this->assertSame($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); |
55 | } | 55 | } |
56 | 56 | ||
57 | /** | 57 | /** |
@@ -75,8 +75,8 @@ class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase | |||
75 | 75 | ||
76 | $evm->dispatchEvent('loadClassMetadata', $metaDataEvent); | 76 | $evm->dispatchEvent('loadClassMetadata', $metaDataEvent); |
77 | 77 | ||
78 | $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); | 78 | $this->assertSame($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); |
79 | $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); | 79 | $this->assertSame($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); |
80 | } | 80 | } |
81 | 81 | ||
82 | public function testPrefixManyToMany() | 82 | public function testPrefixManyToMany() |
@@ -103,12 +103,12 @@ class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase | |||
103 | 103 | ||
104 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); | 104 | $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); |
105 | 105 | ||
106 | $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName()); | 106 | $this->assertSame('entry', $metaDataEvent->getClassMetadata()->getTableName()); |
107 | 107 | ||
108 | $subscriber->loadClassMetadata($metaDataEvent); | 108 | $subscriber->loadClassMetadata($metaDataEvent); |
109 | 109 | ||
110 | $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName()); | 110 | $this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getTableName()); |
111 | $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']); | 111 | $this->assertSame('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']); |
112 | $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform())); | 112 | $this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform())); |
113 | } | 113 | } |
114 | } | 114 | } |
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index aee67259..5d6a29fe 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -2,12 +2,14 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; | 3 | namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; |
4 | 4 | ||
5 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; | ||
6 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; | 5 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; |
7 | use PHPUnit_Framework_TestCase; | 6 | use Monolog\Handler\TestHandler; |
7 | use Monolog\Logger; | ||
8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
9 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
8 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; | 10 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; |
9 | 11 | ||
10 | class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | 12 | class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase |
11 | { | 13 | { |
12 | /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */ | 14 | /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */ |
13 | protected $builder; | 15 | protected $builder; |
@@ -15,16 +17,16 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
15 | public function testBuildConfigExists() | 17 | public function testBuildConfigExists() |
16 | { | 18 | { |
17 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | 19 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ |
18 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | 20 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') |
19 | ->disableOriginalConstructor() | 21 | ->disableOriginalConstructor() |
20 | ->getMock(); | 22 | ->getMock(); |
21 | 23 | ||
22 | $grabySiteConfig = new GrabySiteConfig(); | 24 | $grabySiteConfig = new GrabySiteConfig(); |
23 | $grabySiteConfig->requires_login = true; | 25 | $grabySiteConfig->requires_login = true; |
24 | $grabySiteConfig->login_uri = 'http://example.com/login'; | 26 | $grabySiteConfig->login_uri = 'http://www.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,27 +34,52 @@ 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 | |||
41 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
42 | ->disableOriginalConstructor() | ||
43 | ->getMock(); | ||
44 | $siteCrentialRepo->expects($this->once()) | ||
45 | ->method('findOneByHostAndUser') | ||
46 | ->with('example.com', 1) | ||
47 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | ||
48 | |||
49 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
50 | ->disableOriginalConstructor() | ||
51 | ->getMock(); | ||
52 | $user->expects($this->once()) | ||
53 | ->method('getId') | ||
54 | ->willReturn(1); | ||
55 | |||
56 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
57 | |||
58 | $tokenStorage = new TokenStorage(); | ||
59 | $tokenStorage->setToken($token); | ||
60 | |||
35 | $this->builder = new GrabySiteConfigBuilder( | 61 | $this->builder = new GrabySiteConfigBuilder( |
36 | $grabyConfigBuilderMock, | 62 | $grabyConfigBuilderMock, |
37 | ['example.com' => ['username' => 'foo', 'password' => 'bar']] | 63 | $tokenStorage, |
64 | $siteCrentialRepo, | ||
65 | $logger | ||
38 | ); | 66 | ); |
39 | 67 | ||
40 | $config = $this->builder->buildForHost('example.com'); | 68 | $config = $this->builder->buildForHost('www.example.com'); |
41 | 69 | ||
42 | self::assertEquals( | 70 | $this->assertSame('example.com', $config->getHost()); |
43 | new SiteConfig([ | 71 | $this->assertSame(true, $config->requiresLogin()); |
44 | 'host' => 'example.com', | 72 | $this->assertSame('http://www.example.com/login', $config->getLoginUri()); |
45 | 'requiresLogin' => true, | 73 | $this->assertSame('login', $config->getUsernameField()); |
46 | 'loginUri' => 'http://example.com/login', | 74 | $this->assertSame('password', $config->getPasswordField()); |
47 | 'usernameField' => 'login', | 75 | $this->assertSame(['field' => 'value'], $config->getExtraFields()); |
48 | 'passwordField' => 'password', | 76 | $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); |
49 | 'extraFields' => ['field' => 'value'], | 77 | $this->assertSame('foo', $config->getUsername()); |
50 | 'notLoggedInXpath' => '//div[@class="need-login"]', | 78 | $this->assertSame('bar', $config->getPassword()); |
51 | 'username' => 'foo', | 79 | |
52 | 'password' => 'bar', | 80 | $records = $handler->getRecords(); |
53 | ]), | 81 | |
54 | $config | 82 | $this->assertCount(1, $records, 'One log was recorded'); |
55 | ); | ||
56 | } | 83 | } |
57 | 84 | ||
58 | public function testBuildConfigDoesntExist() | 85 | public function testBuildConfigDoesntExist() |
@@ -67,19 +94,43 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase | |||
67 | ->with('unknown.com') | 94 | ->with('unknown.com') |
68 | ->will($this->returnValue(new GrabySiteConfig())); | 95 | ->will($this->returnValue(new GrabySiteConfig())); |
69 | 96 | ||
70 | $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []); | 97 | $logger = new Logger('foo'); |
98 | $handler = new TestHandler(); | ||
99 | $logger->pushHandler($handler); | ||
71 | 100 | ||
72 | $config = $this->builder->buildForHost('unknown.com'); | 101 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') |
102 | ->disableOriginalConstructor() | ||
103 | ->getMock(); | ||
104 | $siteCrentialRepo->expects($this->once()) | ||
105 | ->method('findOneByHostAndUser') | ||
106 | ->with('unknown.com', 1) | ||
107 | ->willReturn(null); | ||
108 | |||
109 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
110 | ->disableOriginalConstructor() | ||
111 | ->getMock(); | ||
112 | $user->expects($this->once()) | ||
113 | ->method('getId') | ||
114 | ->willReturn(1); | ||
115 | |||
116 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
117 | |||
118 | $tokenStorage = new TokenStorage(); | ||
119 | $tokenStorage->setToken($token); | ||
73 | 120 | ||
74 | self::assertEquals( | 121 | $this->builder = new GrabySiteConfigBuilder( |
75 | new SiteConfig([ | 122 | $grabyConfigBuilderMock, |
76 | 'host' => 'unknown.com', | 123 | $tokenStorage, |
77 | 'requiresLogin' => false, | 124 | $siteCrentialRepo, |
78 | 'username' => null, | 125 | $logger |
79 | 'password' => null, | ||
80 | 'extraFields' => [], | ||
81 | ]), | ||
82 | $config | ||
83 | ); | 126 | ); |
127 | |||
128 | $config = $this->builder->buildForHost('unknown.com'); | ||
129 | |||
130 | $this->assertFalse($config); | ||
131 | |||
132 | $records = $handler->getRecords(); | ||
133 | |||
134 | $this->assertCount(1, $records, 'One log was recorded'); | ||
84 | } | 135 | } |
85 | } | 136 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 4f70ed0c..f94c2137 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -2,10 +2,17 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Graby\Graby; | ||
6 | use Monolog\Handler\TestHandler; | ||
7 | use Monolog\Logger; | ||
5 | use Psr\Log\NullLogger; | 8 | use Psr\Log\NullLogger; |
6 | use Wallabag\CoreBundle\Helper\ContentProxy; | 9 | use Symfony\Component\Validator\ConstraintViolation; |
10 | use Symfony\Component\Validator\ConstraintViolationList; | ||
11 | use Symfony\Component\Validator\Validator\RecursiveValidator; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | 12 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\CoreBundle\Entity\Tag; | 13 | use Wallabag\CoreBundle\Entity\Tag; |
14 | use Wallabag\CoreBundle\Helper\ContentProxy; | ||
15 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; | ||
9 | use Wallabag\UserBundle\Entity\User; | 16 | use Wallabag\UserBundle\Entity\User; |
10 | 17 | ||
11 | class ContentProxyTest extends \PHPUnit_Framework_TestCase | 18 | class ContentProxyTest extends \PHPUnit_Framework_TestCase |
@@ -33,17 +40,18 @@ 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->assertSame('http://user@:80', $entry->getUrl()); |
40 | $this->assertEmpty($entry->getTitle()); | 48 | $this->assertEmpty($entry->getTitle()); |
41 | $this->assertEquals($this->fetchingErrorMessage, $entry->getContent()); | 49 | $this->assertSame($this->fetchingErrorMessage, $entry->getContent()); |
42 | $this->assertEmpty($entry->getPreviewPicture()); | 50 | $this->assertEmpty($entry->getPreviewPicture()); |
43 | $this->assertEmpty($entry->getMimetype()); | 51 | $this->assertEmpty($entry->getMimetype()); |
44 | $this->assertEmpty($entry->getLanguage()); | 52 | $this->assertEmpty($entry->getLanguage()); |
45 | $this->assertEquals(0.0, $entry->getReadingTime()); | 53 | $this->assertSame(0.0, $entry->getReadingTime()); |
46 | $this->assertEquals(false, $entry->getDomainName()); | 54 | $this->assertSame(null, $entry->getDomainName()); |
47 | } | 55 | } |
48 | 56 | ||
49 | public function testWithEmptyContent() | 57 | public function testWithEmptyContent() |
@@ -67,17 +75,18 @@ 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->assertSame('http://0.0.0.0', $entry->getUrl()); |
74 | $this->assertEmpty($entry->getTitle()); | 83 | $this->assertEmpty($entry->getTitle()); |
75 | $this->assertEquals($this->fetchingErrorMessage, $entry->getContent()); | 84 | $this->assertSame($this->fetchingErrorMessage, $entry->getContent()); |
76 | $this->assertEmpty($entry->getPreviewPicture()); | 85 | $this->assertEmpty($entry->getPreviewPicture()); |
77 | $this->assertEmpty($entry->getMimetype()); | 86 | $this->assertEmpty($entry->getMimetype()); |
78 | $this->assertEmpty($entry->getLanguage()); | 87 | $this->assertEmpty($entry->getLanguage()); |
79 | $this->assertEquals(0.0, $entry->getReadingTime()); | 88 | $this->assertSame(0.0, $entry->getReadingTime()); |
80 | $this->assertEquals('0.0.0.0', $entry->getDomainName()); | 89 | $this->assertSame('0.0.0.0', $entry->getDomainName()); |
81 | } | 90 | } |
82 | 91 | ||
83 | public function testWithEmptyContentButOG() | 92 | public function testWithEmptyContentButOG() |
@@ -106,18 +115,19 @@ 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->assertSame('http://domain.io', $entry->getUrl()); |
113 | $this->assertEquals('my title', $entry->getTitle()); | 123 | $this->assertSame('my title', $entry->getTitle()); |
114 | $this->assertEquals($this->fetchingErrorMessage . '<p><i>But we found a short description: </i></p>desc', $entry->getContent()); | 124 | $this->assertSame($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()); |
118 | $this->assertEmpty($entry->getMimetype()); | 128 | $this->assertEmpty($entry->getMimetype()); |
119 | $this->assertEquals(0.0, $entry->getReadingTime()); | 129 | $this->assertSame(0.0, $entry->getReadingTime()); |
120 | $this->assertEquals('domain.io', $entry->getDomainName()); | 130 | $this->assertSame('domain.io', $entry->getDomainName()); |
121 | } | 131 | } |
122 | 132 | ||
123 | public function testWithContent() | 133 | public function testWithContent() |
@@ -147,18 +157,19 @@ 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->assertSame('http://1.1.1.1', $entry->getUrl()); |
154 | $this->assertEquals('this is my title', $entry->getTitle()); | 165 | $this->assertSame('this is my title', $entry->getTitle()); |
155 | $this->assertContains('this is my content', $entry->getContent()); | 166 | $this->assertContains('this is my content', $entry->getContent()); |
156 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | 167 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); |
157 | $this->assertEquals('text/html', $entry->getMimetype()); | 168 | $this->assertSame('text/html', $entry->getMimetype()); |
158 | $this->assertEquals('fr', $entry->getLanguage()); | 169 | $this->assertSame('fr', $entry->getLanguage()); |
159 | $this->assertEquals('200', $entry->getHttpStatus()); | 170 | $this->assertSame('200', $entry->getHttpStatus()); |
160 | $this->assertEquals(4.0, $entry->getReadingTime()); | 171 | $this->assertSame(4.0, $entry->getReadingTime()); |
161 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | 172 | $this->assertSame('1.1.1.1', $entry->getDomainName()); |
162 | } | 173 | } |
163 | 174 | ||
164 | public function testWithContentAndNoOgImage() | 175 | public function testWithContentAndNoOgImage() |
@@ -184,205 +195,359 @@ 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->assertSame('http://1.1.1.1', $entry->getUrl()); |
195 | $this->assertEquals('this is my title', $entry->getTitle()); | 207 | $this->assertSame('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->assertNull($entry->getPreviewPicture()); |
198 | $this->assertEquals('text/html', $entry->getMimetype()); | 210 | $this->assertSame('text/html', $entry->getMimetype()); |
199 | $this->assertEquals('fr', $entry->getLanguage()); | 211 | $this->assertSame('fr', $entry->getLanguage()); |
200 | $this->assertEquals('200', $entry->getHttpStatus()); | 212 | $this->assertSame('200', $entry->getHttpStatus()); |
201 | $this->assertEquals(4.0, $entry->getReadingTime()); | 213 | $this->assertSame(4.0, $entry->getReadingTime()); |
202 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | 214 | $this->assertSame('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(); |
212 | 224 | $validator->expects($this->once()) | |
213 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | 225 | ->method('validate') |
214 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ | 226 | ->willReturn(new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')])); |
215 | 'html' => str_repeat('this is my content', 325), | ||
216 | 'title' => 'this is my title', | ||
217 | 'url' => 'http://1.1.1.1', | ||
218 | 'content_type' => 'text/html', | ||
219 | 'language' => 'fr', | ||
220 | ]); | ||
221 | |||
222 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
223 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
224 | $this->assertContains('this is my content', $entry->getContent()); | ||
225 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
226 | $this->assertEquals('fr', $entry->getLanguage()); | ||
227 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
228 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
229 | } | ||
230 | 227 | ||
231 | public function testTaggerThrowException() | ||
232 | { | ||
233 | $graby = $this->getMockBuilder('Graby\Graby') | 228 | $graby = $this->getMockBuilder('Graby\Graby') |
229 | ->setMethods(['fetchContent']) | ||
234 | ->disableOriginalConstructor() | 230 | ->disableOriginalConstructor() |
235 | ->getMock(); | 231 | ->getMock(); |
236 | 232 | ||
237 | $tagger = $this->getTaggerMock(); | 233 | $graby->expects($this->any()) |
238 | $tagger->expects($this->once()) | 234 | ->method('fetchContent') |
239 | ->method('tag') | 235 | ->willReturn([ |
240 | ->will($this->throwException(new \Exception())); | 236 | 'html' => str_repeat('this is my content', 325), |
241 | 237 | 'title' => 'this is my title', | |
242 | $tagRepo = $this->getTagRepositoryMock(); | 238 | 'url' => 'http://1.1.1.1', |
243 | $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 239 | 'content_type' => 'text/html', |
240 | 'language' => 'dontexist', | ||
241 | 'status' => '200', | ||
242 | ]); | ||
244 | 243 | ||
245 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ | 244 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
246 | 'html' => str_repeat('this is my content', 325), | 245 | $entry = new Entry(new User()); |
247 | 'title' => 'this is my title', | 246 | $proxy->updateEntry($entry, 'http://0.0.0.0'); |
248 | 'url' => 'http://1.1.1.1', | ||
249 | 'content_type' => 'text/html', | ||
250 | 'language' => 'fr', | ||
251 | ]); | ||
252 | 247 | ||
253 | $this->assertCount(0, $entry->getTags()); | 248 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
249 | $this->assertSame('this is my title', $entry->getTitle()); | ||
250 | $this->assertContains('this is my content', $entry->getContent()); | ||
251 | $this->assertSame('text/html', $entry->getMimetype()); | ||
252 | $this->assertNull($entry->getLanguage()); | ||
253 | $this->assertSame('200', $entry->getHttpStatus()); | ||
254 | $this->assertSame(4.0, $entry->getReadingTime()); | ||
255 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
254 | } | 256 | } |
255 | 257 | ||
256 | public function testAssignTagsWithArrayAndExtraSpaces() | 258 | public function testWithContentAndBadOgImage() |
257 | { | 259 | { |
260 | $tagger = $this->getTaggerMock(); | ||
261 | $tagger->expects($this->once()) | ||
262 | ->method('tag'); | ||
263 | |||
264 | $validator = $this->getValidator(); | ||
265 | $validator->expects($this->exactly(2)) | ||
266 | ->method('validate') | ||
267 | ->will($this->onConsecutiveCalls( | ||
268 | new ConstraintViolationList(), | ||
269 | new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'url', 'https://')]) | ||
270 | )); | ||
271 | |||
258 | $graby = $this->getMockBuilder('Graby\Graby') | 272 | $graby = $this->getMockBuilder('Graby\Graby') |
273 | ->setMethods(['fetchContent']) | ||
259 | ->disableOriginalConstructor() | 274 | ->disableOriginalConstructor() |
260 | ->getMock(); | 275 | ->getMock(); |
261 | 276 | ||
262 | $tagRepo = $this->getTagRepositoryMock(); | 277 | $graby->expects($this->any()) |
263 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 278 | ->method('fetchContent') |
279 | ->willReturn([ | ||
280 | 'html' => str_repeat('this is my content', 325), | ||
281 | 'title' => 'this is my title', | ||
282 | 'url' => 'http://1.1.1.1', | ||
283 | 'content_type' => 'text/html', | ||
284 | 'language' => 'fr', | ||
285 | 'status' => '200', | ||
286 | 'open_graph' => [ | ||
287 | 'og_title' => 'my OG title', | ||
288 | 'og_description' => 'OG desc', | ||
289 | 'og_image' => 'https://', | ||
290 | ], | ||
291 | ]); | ||
264 | 292 | ||
293 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | ||
265 | $entry = new Entry(new User()); | 294 | $entry = new Entry(new User()); |
295 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
266 | 296 | ||
267 | $proxy->assignTagsToEntry($entry, [' tag1', 'tag2 ']); | 297 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
268 | 298 | $this->assertSame('this is my title', $entry->getTitle()); | |
269 | $this->assertCount(2, $entry->getTags()); | 299 | $this->assertContains('this is my content', $entry->getContent()); |
270 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 300 | $this->assertNull($entry->getPreviewPicture()); |
271 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | 301 | $this->assertSame('text/html', $entry->getMimetype()); |
302 | $this->assertSame('fr', $entry->getLanguage()); | ||
303 | $this->assertSame('200', $entry->getHttpStatus()); | ||
304 | $this->assertSame(4.0, $entry->getReadingTime()); | ||
305 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
272 | } | 306 | } |
273 | 307 | ||
274 | public function testAssignTagsWithString() | 308 | public function testWithForcedContent() |
275 | { | 309 | { |
276 | $graby = $this->getMockBuilder('Graby\Graby') | 310 | $tagger = $this->getTaggerMock(); |
277 | ->disableOriginalConstructor() | 311 | $tagger->expects($this->once()) |
278 | ->getMock(); | 312 | ->method('tag'); |
279 | |||
280 | $tagRepo = $this->getTagRepositoryMock(); | ||
281 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | ||
282 | 313 | ||
314 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
283 | $entry = new Entry(new User()); | 315 | $entry = new Entry(new User()); |
316 | $proxy->updateEntry( | ||
317 | $entry, | ||
318 | 'http://0.0.0.0', | ||
319 | [ | ||
320 | 'html' => str_repeat('this is my content', 325), | ||
321 | 'title' => 'this is my title', | ||
322 | 'url' => 'http://1.1.1.1', | ||
323 | 'content_type' => 'text/html', | ||
324 | 'language' => 'fr', | ||
325 | 'date' => '1395635872', | ||
326 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], | ||
327 | 'all_headers' => [ | ||
328 | 'Cache-Control' => 'no-cache', | ||
329 | ], | ||
330 | ] | ||
331 | ); | ||
284 | 332 | ||
285 | $proxy->assignTagsToEntry($entry, 'tag1, tag2'); | 333 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
286 | 334 | $this->assertSame('this is my title', $entry->getTitle()); | |
287 | $this->assertCount(2, $entry->getTags()); | 335 | $this->assertContains('this is my content', $entry->getContent()); |
288 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 336 | $this->assertSame('text/html', $entry->getMimetype()); |
289 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | 337 | $this->assertSame('fr', $entry->getLanguage()); |
338 | $this->assertSame(4.0, $entry->getReadingTime()); | ||
339 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
340 | $this->assertSame('24/03/2014', $entry->getPublishedAt()->format('d/m/Y')); | ||
341 | $this->assertContains('Jeremy', $entry->getPublishedBy()); | ||
342 | $this->assertContains('Nico', $entry->getPublishedBy()); | ||
343 | $this->assertContains('Thomas', $entry->getPublishedBy()); | ||
344 | $this->assertContains('no-cache', $entry->getHeaders()); | ||
290 | } | 345 | } |
291 | 346 | ||
292 | public function testAssignTagsWithEmptyArray() | 347 | public function testWithForcedContentAndDatetime() |
293 | { | 348 | { |
294 | $graby = $this->getMockBuilder('Graby\Graby') | 349 | $tagger = $this->getTaggerMock(); |
295 | ->disableOriginalConstructor() | 350 | $tagger->expects($this->once()) |
296 | ->getMock(); | 351 | ->method('tag'); |
297 | 352 | ||
298 | $tagRepo = $this->getTagRepositoryMock(); | 353 | $logHandler = new TestHandler(); |
299 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 354 | $logger = new Logger('test', [$logHandler]); |
300 | 355 | ||
356 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); | ||
301 | $entry = new Entry(new User()); | 357 | $entry = new Entry(new User()); |
358 | $proxy->updateEntry( | ||
359 | $entry, | ||
360 | 'http://1.1.1.1', | ||
361 | [ | ||
362 | 'html' => str_repeat('this is my content', 325), | ||
363 | 'title' => 'this is my title', | ||
364 | 'url' => 'http://1.1.1.1', | ||
365 | 'content_type' => 'text/html', | ||
366 | 'language' => 'fr', | ||
367 | 'date' => '2016-09-08T11:55:58+0200', | ||
368 | ] | ||
369 | ); | ||
302 | 370 | ||
303 | $proxy->assignTagsToEntry($entry, []); | 371 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
304 | 372 | $this->assertSame('this is my title', $entry->getTitle()); | |
305 | $this->assertCount(0, $entry->getTags()); | 373 | $this->assertContains('this is my content', $entry->getContent()); |
374 | $this->assertSame('text/html', $entry->getMimetype()); | ||
375 | $this->assertSame('fr', $entry->getLanguage()); | ||
376 | $this->assertSame(4.0, $entry->getReadingTime()); | ||
377 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
378 | $this->assertSame('08/09/2016', $entry->getPublishedAt()->format('d/m/Y')); | ||
306 | } | 379 | } |
307 | 380 | ||
308 | public function testAssignTagsWithEmptyString() | 381 | public function testWithForcedContentAndBadDate() |
309 | { | 382 | { |
310 | $graby = $this->getMockBuilder('Graby\Graby') | 383 | $tagger = $this->getTaggerMock(); |
311 | ->disableOriginalConstructor() | 384 | $tagger->expects($this->once()) |
312 | ->getMock(); | 385 | ->method('tag'); |
313 | 386 | ||
314 | $tagRepo = $this->getTagRepositoryMock(); | 387 | $logger = new Logger('foo'); |
315 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 388 | $handler = new TestHandler(); |
389 | $logger->pushHandler($handler); | ||
316 | 390 | ||
391 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); | ||
317 | $entry = new Entry(new User()); | 392 | $entry = new Entry(new User()); |
393 | $proxy->updateEntry( | ||
394 | $entry, | ||
395 | 'http://1.1.1.1', | ||
396 | [ | ||
397 | 'html' => str_repeat('this is my content', 325), | ||
398 | 'title' => 'this is my title', | ||
399 | 'url' => 'http://1.1.1.1', | ||
400 | 'content_type' => 'text/html', | ||
401 | 'language' => 'fr', | ||
402 | 'date' => '01 02 2012', | ||
403 | ] | ||
404 | ); | ||
318 | 405 | ||
319 | $proxy->assignTagsToEntry($entry, ''); | 406 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
407 | $this->assertSame('this is my title', $entry->getTitle()); | ||
408 | $this->assertContains('this is my content', $entry->getContent()); | ||
409 | $this->assertSame('text/html', $entry->getMimetype()); | ||
410 | $this->assertSame('fr', $entry->getLanguage()); | ||
411 | $this->assertSame(4.0, $entry->getReadingTime()); | ||
412 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
413 | $this->assertNull($entry->getPublishedAt()); | ||
320 | 414 | ||
321 | $this->assertCount(0, $entry->getTags()); | 415 | $records = $handler->getRecords(); |
416 | |||
417 | $this->assertCount(1, $records); | ||
418 | $this->assertContains('Error while defining date', $records[0]['message']); | ||
322 | } | 419 | } |
323 | 420 | ||
324 | public function testAssignTagsAlreadyAssigned() | 421 | public function testTaggerThrowException() |
325 | { | 422 | { |
326 | $graby = $this->getMockBuilder('Graby\Graby') | 423 | $tagger = $this->getTaggerMock(); |
327 | ->disableOriginalConstructor() | 424 | $tagger->expects($this->once()) |
328 | ->getMock(); | 425 | ->method('tag') |
426 | ->will($this->throwException(new \Exception())); | ||
329 | 427 | ||
330 | $tagRepo = $this->getTagRepositoryMock(); | 428 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
331 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 429 | $entry = new Entry(new User()); |
430 | $proxy->updateEntry( | ||
431 | $entry, | ||
432 | 'http://1.1.1.1', | ||
433 | [ | ||
434 | 'html' => str_repeat('this is my content', 325), | ||
435 | 'title' => 'this is my title', | ||
436 | 'url' => 'http://1.1.1.1', | ||
437 | 'content_type' => 'text/html', | ||
438 | 'language' => 'fr', | ||
439 | ] | ||
440 | ); | ||
332 | 441 | ||
333 | $tagEntity = new Tag(); | 442 | $this->assertCount(0, $entry->getTags()); |
334 | $tagEntity->setLabel('tag1'); | 443 | } |
335 | 444 | ||
336 | $entry = new Entry(new User()); | 445 | public function dataForCrazyHtml() |
337 | $entry->addTag($tagEntity); | 446 | { |
447 | return [ | ||
448 | 'script and comment' => [ | ||
449 | '<strong>Script inside:</strong> <!--[if gte IE 4]><script>alert(\'lol\');</script><![endif]--><br />', | ||
450 | 'lol', | ||
451 | ], | ||
452 | 'script' => [ | ||
453 | '<strong>Script inside:</strong><script>alert(\'lol\');</script>', | ||
454 | 'script', | ||
455 | ], | ||
456 | ]; | ||
457 | } | ||
338 | 458 | ||
339 | $proxy->assignTagsToEntry($entry, 'tag1, tag2'); | 459 | /** |
460 | * @dataProvider dataForCrazyHtml | ||
461 | */ | ||
462 | public function testWithCrazyHtmlContent($html, $escapedString) | ||
463 | { | ||
464 | $tagger = $this->getTaggerMock(); | ||
465 | $tagger->expects($this->once()) | ||
466 | ->method('tag'); | ||
340 | 467 | ||
341 | $this->assertCount(2, $entry->getTags()); | 468 | $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
342 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 469 | $entry = new Entry(new User()); |
343 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | 470 | $proxy->updateEntry( |
471 | $entry, | ||
472 | 'http://1.1.1.1', | ||
473 | [ | ||
474 | 'html' => $html, | ||
475 | 'title' => 'this is my title', | ||
476 | 'url' => 'http://1.1.1.1', | ||
477 | 'content_type' => 'text/html', | ||
478 | 'language' => 'fr', | ||
479 | 'status' => '200', | ||
480 | 'open_graph' => [ | ||
481 | 'og_title' => 'my OG title', | ||
482 | 'og_description' => 'OG desc', | ||
483 | 'og_image' => 'http://3.3.3.3/cover.jpg', | ||
484 | ], | ||
485 | ] | ||
486 | ); | ||
487 | |||
488 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | ||
489 | $this->assertSame('this is my title', $entry->getTitle()); | ||
490 | $this->assertNotContains($escapedString, $entry->getContent()); | ||
491 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
492 | $this->assertSame('text/html', $entry->getMimetype()); | ||
493 | $this->assertSame('fr', $entry->getLanguage()); | ||
494 | $this->assertSame('200', $entry->getHttpStatus()); | ||
495 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
344 | } | 496 | } |
345 | 497 | ||
346 | public function testAssignTagsNotFlushed() | 498 | public function testWithImageAsContent() |
347 | { | 499 | { |
500 | $tagger = $this->getTaggerMock(); | ||
501 | $tagger->expects($this->once()) | ||
502 | ->method('tag'); | ||
503 | |||
348 | $graby = $this->getMockBuilder('Graby\Graby') | 504 | $graby = $this->getMockBuilder('Graby\Graby') |
505 | ->setMethods(['fetchContent']) | ||
349 | ->disableOriginalConstructor() | 506 | ->disableOriginalConstructor() |
350 | ->getMock(); | 507 | ->getMock(); |
351 | 508 | ||
352 | $tagRepo = $this->getTagRepositoryMock(); | 509 | $graby->expects($this->any()) |
353 | $tagRepo->expects($this->never()) | 510 | ->method('fetchContent') |
354 | ->method('__call'); | 511 | ->willReturn([ |
355 | 512 | 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', | |
356 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); | 513 | 'title' => 'this is my title', |
357 | 514 | 'url' => 'http://1.1.1.1/image.jpg', | |
358 | $tagEntity = new Tag(); | 515 | 'content_type' => 'image/jpeg', |
359 | $tagEntity->setLabel('tag1'); | 516 | 'status' => '200', |
517 | 'open_graph' => [], | ||
518 | ]); | ||
360 | 519 | ||
520 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
361 | $entry = new Entry(new User()); | 521 | $entry = new Entry(new User()); |
362 | 522 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | |
363 | $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]); | 523 | |
364 | 524 | $this->assertSame('http://1.1.1.1/image.jpg', $entry->getUrl()); | |
365 | $this->assertCount(1, $entry->getTags()); | 525 | $this->assertSame('this is my title', $entry->getTitle()); |
366 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | 526 | $this->assertContains('http://1.1.1.1/image.jpg', $entry->getContent()); |
527 | $this->assertSame('http://1.1.1.1/image.jpg', $entry->getPreviewPicture()); | ||
528 | $this->assertSame('image/jpeg', $entry->getMimetype()); | ||
529 | $this->assertSame('200', $entry->getHttpStatus()); | ||
530 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
367 | } | 531 | } |
368 | 532 | ||
369 | private function getTaggerMock() | 533 | private function getTaggerMock() |
370 | { | 534 | { |
371 | return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') | 535 | return $this->getMockBuilder(RuleBasedTagger::class) |
372 | ->setMethods(['tag']) | 536 | ->setMethods(['tag']) |
373 | ->disableOriginalConstructor() | 537 | ->disableOriginalConstructor() |
374 | ->getMock(); | 538 | ->getMock(); |
375 | } | 539 | } |
376 | 540 | ||
377 | private function getTagRepositoryMock() | 541 | private function getLogger() |
378 | { | 542 | { |
379 | return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | 543 | return new NullLogger(); |
380 | ->disableOriginalConstructor() | ||
381 | ->getMock(); | ||
382 | } | 544 | } |
383 | 545 | ||
384 | private function getLogger() | 546 | private function getValidator() |
385 | { | 547 | { |
386 | return new NullLogger(); | 548 | return $this->getMockBuilder(RecursiveValidator::class) |
549 | ->setMethods(['validate']) | ||
550 | ->disableOriginalConstructor() | ||
551 | ->getMock(); | ||
387 | } | 552 | } |
388 | } | 553 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php new file mode 100644 index 00000000..782c29c3 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php | |||
@@ -0,0 +1,40 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Monolog\Handler\TestHandler; | ||
6 | use Monolog\Logger; | ||
7 | use Psr\Log\NullLogger; | ||
8 | use Wallabag\CoreBundle\Helper\CryptoProxy; | ||
9 | |||
10 | class CryptoProxyTest extends \PHPUnit_Framework_TestCase | ||
11 | { | ||
12 | public function testCrypto() | ||
13 | { | ||
14 | $logHandler = new TestHandler(); | ||
15 | $logger = new Logger('test', [$logHandler]); | ||
16 | |||
17 | $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger); | ||
18 | $crypted = $crypto->crypt('test'); | ||
19 | $decrypted = $crypto->decrypt($crypted); | ||
20 | |||
21 | $this->assertSame('test', $decrypted); | ||
22 | |||
23 | $records = $logHandler->getRecords(); | ||
24 | $this->assertCount(2, $records); | ||
25 | $this->assertContains('Crypto: crypting value', $records[0]['message']); | ||
26 | $this->assertContains('Crypto: decrypting value', $records[1]['message']); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * @expectedException \RuntimeException | ||
31 | * @expectedExceptionMessage Decrypt fail | ||
32 | * | ||
33 | * @return [type] [description] | ||
34 | */ | ||
35 | public function testDecryptBadValue() | ||
36 | { | ||
37 | $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger()); | ||
38 | $crypto->decrypt('badvalue'); | ||
39 | } | ||
40 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 85f12d87..c61f65d0 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -2,34 +2,52 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Helper\DownloadImages; | ||
6 | use Monolog\Logger; | ||
7 | use Monolog\Handler\TestHandler; | ||
8 | use GuzzleHttp\Client; | 5 | use GuzzleHttp\Client; |
9 | use GuzzleHttp\Subscriber\Mock; | ||
10 | use GuzzleHttp\Message\Response; | 6 | use GuzzleHttp\Message\Response; |
11 | use GuzzleHttp\Stream\Stream; | 7 | use GuzzleHttp\Stream\Stream; |
8 | use GuzzleHttp\Subscriber\Mock; | ||
9 | use Monolog\Handler\TestHandler; | ||
10 | use Monolog\Logger; | ||
11 | use Wallabag\CoreBundle\Helper\DownloadImages; | ||
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 | ||
19 | $mock = new Mock([ | 36 | $mock = new Mock([ |
20 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), | 37 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), |
21 | ]); | 38 | ]); |
22 | 39 | ||
23 | $client->getEmitter()->attach($mock); | 40 | $client->getEmitter()->attach($mock); |
24 | 41 | ||
25 | $logHandler = new TestHandler(); | 42 | $logHandler = new TestHandler(); |
26 | $logger = new Logger('test', array($logHandler)); | 43 | $logger = new Logger('test', [$logHandler]); |
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() |
@@ -43,9 +61,9 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
43 | $client->getEmitter()->attach($mock); | 61 | $client->getEmitter()->attach($mock); |
44 | 62 | ||
45 | $logHandler = new TestHandler(); | 63 | $logHandler = new TestHandler(); |
46 | $logger = new Logger('test', array($logHandler)); | 64 | $logger = new Logger('test', [$logHandler]); |
47 | 65 | ||
48 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | 66 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
49 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); | 67 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); |
50 | 68 | ||
51 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); | 69 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); |
@@ -69,18 +87,18 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
69 | $client = new Client(); | 87 | $client = new Client(); |
70 | 88 | ||
71 | $mock = new Mock([ | 89 | $mock = new Mock([ |
72 | new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), | 90 | new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), |
73 | ]); | 91 | ]); |
74 | 92 | ||
75 | $client->getEmitter()->attach($mock); | 93 | $client->getEmitter()->attach($mock); |
76 | 94 | ||
77 | $logHandler = new TestHandler(); | 95 | $logHandler = new TestHandler(); |
78 | $logger = new Logger('test', array($logHandler)); | 96 | $logger = new Logger('test', [$logHandler]); |
79 | 97 | ||
80 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | 98 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
81 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 99 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
82 | 100 | ||
83 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res); | 101 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); |
84 | } | 102 | } |
85 | 103 | ||
86 | public function testProcessSingleImageWithBadUrl() | 104 | public function testProcessSingleImageWithBadUrl() |
@@ -94,9 +112,9 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
94 | $client->getEmitter()->attach($mock); | 112 | $client->getEmitter()->attach($mock); |
95 | 113 | ||
96 | $logHandler = new TestHandler(); | 114 | $logHandler = new TestHandler(); |
97 | $logger = new Logger('test', array($logHandler)); | 115 | $logger = new Logger('test', [$logHandler]); |
98 | 116 | ||
99 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | 117 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
100 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 118 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
101 | 119 | ||
102 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); | 120 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); |
@@ -113,9 +131,9 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
113 | $client->getEmitter()->attach($mock); | 131 | $client->getEmitter()->attach($mock); |
114 | 132 | ||
115 | $logHandler = new TestHandler(); | 133 | $logHandler = new TestHandler(); |
116 | $logger = new Logger('test', array($logHandler)); | 134 | $logger = new Logger('test', [$logHandler]); |
117 | 135 | ||
118 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | 136 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
119 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 137 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
120 | 138 | ||
121 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); | 139 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); |
@@ -126,17 +144,42 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
126 | $client = new Client(); | 144 | $client = new Client(); |
127 | 145 | ||
128 | $mock = new Mock([ | 146 | $mock = new Mock([ |
129 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), | 147 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), |
130 | ]); | 148 | ]); |
131 | 149 | ||
132 | $client->getEmitter()->attach($mock); | 150 | $client->getEmitter()->attach($mock); |
133 | 151 | ||
134 | $logHandler = new TestHandler(); | 152 | $logHandler = new TestHandler(); |
135 | $logger = new Logger('test', array($logHandler)); | 153 | $logger = new Logger('test', [$logHandler]); |
136 | 154 | ||
137 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | 155 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
138 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); | 156 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); |
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', [$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..7fd2ea2b 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |||
@@ -2,11 +2,11 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
6 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
5 | use Wallabag\CoreBundle\Entity\Config; | 7 | use Wallabag\CoreBundle\Entity\Config; |
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Helper\Redirect; | 8 | use Wallabag\CoreBundle\Helper\Redirect; |
8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | 9 | use Wallabag\UserBundle\Entity\User; |
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
10 | 10 | ||
11 | class RedirectTest extends \PHPUnit_Framework_TestCase | 11 | class RedirectTest extends \PHPUnit_Framework_TestCase |
12 | { | 12 | { |
@@ -56,21 +56,21 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
56 | { | 56 | { |
57 | $redirectUrl = $this->redirect->to(null, 'fallback'); | 57 | $redirectUrl = $this->redirect->to(null, 'fallback'); |
58 | 58 | ||
59 | $this->assertEquals('fallback', $redirectUrl); | 59 | $this->assertSame('fallback', $redirectUrl); |
60 | } | 60 | } |
61 | 61 | ||
62 | public function testRedirectToNullWithoutFallback() | 62 | public function testRedirectToNullWithoutFallback() |
63 | { | 63 | { |
64 | $redirectUrl = $this->redirect->to(null); | 64 | $redirectUrl = $this->redirect->to(null); |
65 | 65 | ||
66 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | 66 | $this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); |
67 | } | 67 | } |
68 | 68 | ||
69 | public function testRedirectToValidUrl() | 69 | public function testRedirectToValidUrl() |
70 | { | 70 | { |
71 | $redirectUrl = $this->redirect->to('/unread/list'); | 71 | $redirectUrl = $this->redirect->to('/unread/list'); |
72 | 72 | ||
73 | $this->assertEquals('/unread/list', $redirectUrl); | 73 | $this->assertSame('/unread/list', $redirectUrl); |
74 | } | 74 | } |
75 | 75 | ||
76 | public function testWithNotLoggedUser() | 76 | public function testWithNotLoggedUser() |
@@ -78,7 +78,7 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
78 | $redirect = new Redirect($this->routerMock, new TokenStorage()); | 78 | $redirect = new Redirect($this->routerMock, new TokenStorage()); |
79 | $redirectUrl = $redirect->to('/unread/list'); | 79 | $redirectUrl = $redirect->to('/unread/list'); |
80 | 80 | ||
81 | $this->assertEquals('/unread/list', $redirectUrl); | 81 | $this->assertSame('/unread/list', $redirectUrl); |
82 | } | 82 | } |
83 | 83 | ||
84 | public function testUserForRedirectToHomepage() | 84 | public function testUserForRedirectToHomepage() |
@@ -87,6 +87,24 @@ class RedirectTest extends \PHPUnit_Framework_TestCase | |||
87 | 87 | ||
88 | $redirectUrl = $this->redirect->to('/unread/list'); | 88 | $redirectUrl = $this->redirect->to('/unread/list'); |
89 | 89 | ||
90 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | 90 | $this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); |
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->assertSame('/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->assertSame('fallback', $redirectUrl); | ||
91 | } | 109 | } |
92 | } | 110 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php index 17b08c2a..c31af680 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() |
@@ -162,7 +182,7 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | |||
162 | $tags = $entry->getTags(); | 182 | $tags = $entry->getTags(); |
163 | 183 | ||
164 | $this->assertCount(1, $tags); | 184 | $this->assertCount(1, $tags); |
165 | $this->assertEquals('hey', $tags[0]->getLabel()); | 185 | $this->assertSame('hey', $tags[0]->getLabel()); |
166 | } | 186 | } |
167 | } | 187 | } |
168 | 188 | ||
@@ -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..475cd349 --- /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\CoreBundle\Repository\TagRepository; | ||
9 | use Wallabag\UserBundle\Entity\User; | ||
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->assertSame('tag1', $entry->getTags()[0]->getLabel()); | ||
24 | $this->assertSame('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->assertSame('tag1', $entry->getTags()[0]->getLabel()); | ||
38 | $this->assertSame('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->assertSame('tag1', $entry->getTags()[0]->getLabel()); | ||
80 | $this->assertSame('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->assertSame('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..74c645ef 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() |
@@ -212,6 +212,6 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase | |||
212 | 212 | ||
213 | $converter->apply($request, $params); | 213 | $converter->apply($request, $params); |
214 | 214 | ||
215 | $this->assertEquals($user, $request->attributes->get('user')); | 215 | $this->assertSame($user, $request->attributes->get('user')); |
216 | } | 216 | } |
217 | } | 217 | } |
diff --git a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php index 435c25ca..4521e485 100644 --- a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php +++ b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php | |||
@@ -18,7 +18,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase | |||
18 | public function examples() | 18 | public function examples() |
19 | { | 19 | { |
20 | $examples = []; | 20 | $examples = []; |
21 | $finder = (new Finder())->in(__DIR__.'/samples'); | 21 | $finder = (new Finder())->in(__DIR__ . '/samples'); |
22 | foreach ($finder->getIterator() as $file) { | 22 | foreach ($finder->getIterator() as $file) { |
23 | $examples[] = [$file->getContents(), 1]; | 23 | $examples[] = [$file->getContents(), 1]; |
24 | } | 24 | } |
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index b1c8c946..ceec4b37 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | |||
@@ -26,8 +26,8 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase | |||
26 | 26 | ||
27 | $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); | 27 | $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); |
28 | 28 | ||
29 | $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); | 29 | $this->assertSame('lemonde.fr', $extension->removeWww('www.lemonde.fr')); |
30 | $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); | 30 | $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); |
31 | $this->assertEquals('gist.github.com', $extension->removeWww('gist.github.com')); | 31 | $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); |
32 | } | 32 | } |
33 | } | 33 | } |
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 7bf4b43c..1eda5199 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | |||
@@ -2,25 +2,72 @@ | |||
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 | ||
21 | public function setUp() | ||
22 | { | ||
23 | parent::setUp(); | ||
24 | |||
25 | $this->client = static::createClient(); | ||
26 | } | ||
27 | |||
12 | public function getClient() | 28 | public function getClient() |
13 | { | 29 | { |
14 | return $this->client; | 30 | return $this->client; |
15 | } | 31 | } |
16 | 32 | ||
17 | public function setUp() | 33 | public function resetDatabase(Client $client) |
18 | { | 34 | { |
19 | parent::setUp(); | 35 | $application = new Application($client->getKernel()); |
20 | 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 | */ | ||
21 | $this->client = static::createClient(); | 63 | $this->client = static::createClient(); |
22 | } | 64 | } |
23 | 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. |
@@ -36,10 +83,10 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
36 | $loginManager = $container->get('fos_user.security.login_manager'); | 83 | $loginManager = $container->get('fos_user.security.login_manager'); |
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(['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(); |
44 | 91 | ||
45 | $cookie = new Cookie($session->getName(), $session->getId()); | 92 | $cookie = new Cookie($session->getName(), $session->getId()); |
@@ -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 | |||