diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r-- | tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | 95 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | 25 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg | bin | 0 -> 354067 bytes |
3 files changed, 120 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php new file mode 100644 index 00000000..3b928d1e --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | |||
@@ -0,0 +1,95 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; | ||
8 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
9 | use Wallabag\CoreBundle\Command\ShowUserCommand; | ||
10 | use Wallabag\CoreBundle\Entity\Entry; | ||
11 | use Wallabag\UserBundle\Entity\User; | ||
12 | |||
13 | class ShowUserCommandTest extends WallabagCoreTestCase | ||
14 | { | ||
15 | /** | ||
16 | * @expectedException \Symfony\Component\Console\Exception\RuntimeException | ||
17 | * @expectedExceptionMessage Not enough arguments | ||
18 | */ | ||
19 | public function testRunShowUserCommandWithoutUsername() | ||
20 | { | ||
21 | $application = new Application($this->getClient()->getKernel()); | ||
22 | $application->add(new ShowUserCommand()); | ||
23 | |||
24 | $command = $application->find('wallabag:user:show'); | ||
25 | |||
26 | $tester = new CommandTester($command); | ||
27 | $tester->execute([ | ||
28 | 'command' => $command->getName(), | ||
29 | ]); | ||
30 | } | ||
31 | |||
32 | public function testRunShowUserCommandWithBadUsername() | ||
33 | { | ||
34 | $application = new Application($this->getClient()->getKernel()); | ||
35 | $application->add(new ShowUserCommand()); | ||
36 | |||
37 | $command = $application->find('wallabag:user:show'); | ||
38 | |||
39 | $tester = new CommandTester($command); | ||
40 | $tester->execute([ | ||
41 | 'command' => $command->getName(), | ||
42 | 'username' => 'unknown', | ||
43 | ]); | ||
44 | |||
45 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
46 | } | ||
47 | |||
48 | public function testRunShowUserCommandForUser() | ||
49 | { | ||
50 | $application = new Application($this->getClient()->getKernel()); | ||
51 | $application->add(new ShowUserCommand()); | ||
52 | |||
53 | $command = $application->find('wallabag:user:show'); | ||
54 | |||
55 | $tester = new CommandTester($command); | ||
56 | $tester->execute([ | ||
57 | 'command' => $command->getName(), | ||
58 | 'username' => 'admin', | ||
59 | ]); | ||
60 | |||
61 | $this->assertContains('Username : admin', $tester->getDisplay()); | ||
62 | $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); | ||
63 | $this->assertContains('Display name : Big boss', $tester->getDisplay()); | ||
64 | $this->assertContains('2FA activated: no', $tester->getDisplay()); | ||
65 | } | ||
66 | |||
67 | public function testShowUser() | ||
68 | { | ||
69 | $client = $this->getClient(); | ||
70 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
71 | |||
72 | $this->logInAs('admin'); | ||
73 | |||
74 | /** @var User $user */ | ||
75 | $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); | ||
76 | |||
77 | $user->setName('Bug boss'); | ||
78 | $em->persist($user); | ||
79 | |||
80 | $em->flush(); | ||
81 | |||
82 | $application = new Application($this->getClient()->getKernel()); | ||
83 | $application->add(new ShowUserCommand()); | ||
84 | |||
85 | $command = $application->find('wallabag:user:show'); | ||
86 | |||
87 | $tester = new CommandTester($command); | ||
88 | $tester->execute([ | ||
89 | 'command' => $command->getName(), | ||
90 | 'username' => 'admin', | ||
91 | ]); | ||
92 | |||
93 | $this->assertContains('Display name : Bug boss', $tester->getDisplay()); | ||
94 | } | ||
95 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 9125f8dc..c02f9658 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -157,4 +157,29 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
157 | 157 | ||
158 | $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'); |
159 | } | 159 | } |
160 | |||
161 | public function testProcessRealImage() | ||
162 | { | ||
163 | $client = new Client(); | ||
164 | |||
165 | $mock = new Mock([ | ||
166 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__.'/../fixtures/image-no-content-type.jpg'))), | ||
167 | ]); | ||
168 | |||
169 | $client->getEmitter()->attach($mock); | ||
170 | |||
171 | $logHandler = new TestHandler(); | ||
172 | $logger = new Logger('test', array($logHandler)); | ||
173 | |||
174 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); | ||
175 | |||
176 | $res = $download->processSingleImage( | ||
177 | 123, | ||
178 | 'https://cdn.theconversation.com/files/157200/article/width926/gsj2rjp2-1487348607.jpg', | ||
179 | 'https://theconversation.com/conversation-avec-gerald-bronner-ce-nest-pas-la-post-verite-qui-nous-menace-mais-lextension-de-notre-credulite-73089' | ||
180 | ); | ||
181 | |||
182 | $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/', $res, 'Content-Type was empty but data is ok for an image'); | ||
183 | $this->assertContains('DownloadImages: Checking extension (alternative)', $logHandler->getRecords()[3]['message']); | ||
184 | } | ||
160 | } | 185 | } |
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 | |||