aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-05-05 17:42:18 +0200
committerGitHub <noreply@github.com>2017-05-05 17:42:18 +0200
commitab742ee9c69f8cf6e6295d6044e05accffc5551d (patch)
tree503f54518cd9df45434903714eff2a5ab71c8a7c /tests
parent69803049688179e1b03ef424dec91f1b9a4f9e91 (diff)
parent4eeb29ff784934fa879dd87999e07c4c7626af8c (diff)
downloadwallabag-ab742ee9c69f8cf6e6295d6044e05accffc5551d.tar.gz
wallabag-ab742ee9c69f8cf6e6295d6044e05accffc5551d.tar.zst
wallabag-ab742ee9c69f8cf6e6295d6044e05accffc5551d.zip
Merge pull request #2920 from wallabag/cleanduplicatescommand
Clean Duplicates Command
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php108
-rw-r--r--tests/Wallabag/CoreBundle/Command/ExportCommandTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php2
3 files changed, 110 insertions, 2 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php
new file mode 100644
index 00000000..e6e57f30
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php
@@ -0,0 +1,108 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\CoreBundle\Command\CleanDuplicatesCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9use Wallabag\CoreBundle\Entity\Entry;
10
11class 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..b21f3318 100644
--- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
@@ -70,7 +70,7 @@ class ExportCommandTest extends WallabagCoreTestCase
70 $tester->execute([ 70 $tester->execute([
71 'command' => $command->getName(), 71 'command' => $command->getName(),
72 'username' => 'admin', 72 'username' => 'admin',
73 'filepath' => 'specialexport.json' 73 'filepath' => 'specialexport.json',
74 ]); 74 ]);
75 75
76 $this->assertFileExists('specialexport.json'); 76 $this->assertFileExists('specialexport.json');
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 5956b502..8abb1bbb 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -111,7 +111,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
111 111
112 $this->assertEquals('http://domain.io', $entry->getUrl()); 112 $this->assertEquals('http://domain.io', $entry->getUrl());
113 $this->assertEquals('my title', $entry->getTitle()); 113 $this->assertEquals('my title', $entry->getTitle());
114 $this->assertEquals($this->fetchingErrorMessage . '<p><i>But we found a short description: </i></p>desc', $entry->getContent()); 114 $this->assertEquals($this->fetchingErrorMessage.'<p><i>But we found a short description: </i></p>desc', $entry->getContent());
115 $this->assertEmpty($entry->getPreviewPicture()); 115 $this->assertEmpty($entry->getPreviewPicture());
116 $this->assertEmpty($entry->getLanguage()); 116 $this->assertEmpty($entry->getLanguage());
117 $this->assertEmpty($entry->getHttpStatus()); 117 $this->assertEmpty($entry->getHttpStatus());