]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
Change flash message for queued articles
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV2ControllerTest.php
CommitLineData
6785f4aa
NL
1<?php
2
23634d5d 3namespace Tests\Wallabag\ImportBundle\Controller;
6785f4aa 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6785f4aa
NL
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class WallabagV2ControllerTest extends WallabagCoreTestCase
9{
10 public function testImportWallabag()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/wallabag-v2');
16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 }
21
13470c35
JB
22 public function testImportWallabagWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
b3437d58 27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
13470c35
JB
28
29 $crawler = $client->request('GET', '/import/wallabag-v2');
30
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
34
b3437d58
JB
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
38 public function testImportWallabagWithRedisEnabled()
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
43 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
44
45 $crawler = $client->request('GET', '/import/wallabag-v2');
46
47 $this->assertEquals(200, $client->getResponse()->getStatusCode());
48 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
49 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
50
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
13470c35
JB
52 }
53
015c7a83
JB
54 public function testImportWallabagBadFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/wallabag-v2');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $data = [
63 'upload_import_file[file]' => '',
64 ];
65
66 $client->submit($form, $data);
67
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
69 }
70
6785f4aa
NL
71 public function testImportWallabagWithFile()
72 {
73 $this->logInAs('admin');
74 $client = $this->getClient();
75
76 $crawler = $client->request('GET', '/import/wallabag-v2');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
78
79 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
80
4094ea47 81 $data = [
6785f4aa 82 'upload_import_file[file]' => $file,
4094ea47 83 ];
6785f4aa
NL
84
85 $client->submit($form, $data);
86
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
88
89 $crawler = $client->followRedirect();
90
4094ea47 91 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 92 $this->assertContains('flashes.import.notice.summary', $body[0]);
f21a5388
NL
93
94 $content = $client->getContainer()
95 ->get('doctrine.orm.entity_manager')
96 ->getRepository('WallabagCoreBundle:Entry')
97 ->findByUrlAndUserId(
98 'http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867',
99 $this->getLoggedInUserId()
100 );
101
886d4797
JB
102 $this->assertNotEmpty($content->getMimetype());
103 $this->assertNotEmpty($content->getPreviewPicture());
104 $this->assertNotEmpty($content->getLanguage());
8f336fda 105 $this->assertEquals(0, count($content->getTags()));
4c46e260
NL
106
107 $content = $client->getContainer()
108 ->get('doctrine.orm.entity_manager')
109 ->getRepository('WallabagCoreBundle:Entry')
110 ->findByUrlAndUserId(
111 'https://www.mediapart.fr/',
112 $this->getLoggedInUserId()
113 );
114
115 $this->assertNotEmpty($content->getMimetype());
116 $this->assertNotEmpty($content->getPreviewPicture());
117 $this->assertNotEmpty($content->getLanguage());
8f336fda 118 $this->assertEquals(2, count($content->getTags()));
6d65c0a8
JB
119 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
120 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
6785f4aa
NL
121 }
122
123 public function testImportWallabagWithEmptyFile()
124 {
125 $this->logInAs('admin');
126 $client = $this->getClient();
127
128 $crawler = $client->request('GET', '/import/wallabag-v2');
129 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
130
131 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
132
4094ea47 133 $data = [
6785f4aa 134 'upload_import_file[file]' => $file,
4094ea47 135 ];
6785f4aa
NL
136
137 $client->submit($form, $data);
138
139 $this->assertEquals(302, $client->getResponse()->getStatusCode());
140
141 $crawler = $client->followRedirect();
142
4094ea47 143 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 144 $this->assertContains('flashes.import.notice.failed', $body[0]);
6785f4aa
NL
145 }
146}