]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
Re-facto EntryConsumer
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV1ControllerTest.php
CommitLineData
7019c7cf
JB
1<?php
2
23634d5d 3namespace Tests\Wallabag\ImportBundle\Controller;
7019c7cf 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
7019c7cf
JB
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class WallabagV1ControllerTest extends WallabagCoreTestCase
9{
10 public function testImportWallabag()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/wallabag-v1');
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-v1');
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-v1');
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
7019c7cf
JB
54 public function testImportWallabagWithFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/wallabag-v1');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
63
4094ea47 64 $data = [
7019c7cf 65 'upload_import_file[file]' => $file,
4094ea47 66 ];
7019c7cf
JB
67
68 $client->submit($form, $data);
69
70 $this->assertEquals(302, $client->getResponse()->getStatusCode());
71
72 $crawler = $client->followRedirect();
73
fca2b052
TC
74 $content = $client->getContainer()
75 ->get('doctrine.orm.entity_manager')
76 ->getRepository('WallabagCoreBundle:Entry')
77 ->findByUrlAndUserId(
78 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
79 $this->getLoggedInUserId()
80 );
81
82 $tag = $client->getContainer()
83 ->get('doctrine.orm.entity_manager')
84 ->getRepository('WallabagCoreBundle:Tag')
85 ->findOneByLabel('Framabag');
86
87 $this->assertTrue($content->getTags()->contains($tag));
88
4094ea47 89 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 90 $this->assertContains('flashes.import.notice.summary', $body[0]);
6d65c0a8
JB
91
92 $this->assertEmpty($content->getMimetype());
93 $this->assertEmpty($content->getPreviewPicture());
94 $this->assertEmpty($content->getLanguage());
95 $this->assertEquals(1, count($content->getTags()));
96 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
7019c7cf
JB
97 }
98
c32ae320
TC
99 public function testImportWallabagWithFileAndMarkAllAsRead()
100 {
101 $this->logInAs('admin');
102 $client = $this->getClient();
103
104 $crawler = $client->request('GET', '/import/wallabag-v1');
105 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
106
107 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
108
4094ea47 109 $data = [
c32ae320
TC
110 'upload_import_file[file]' => $file,
111 'upload_import_file[mark_as_read]' => 1,
4094ea47 112 ];
c32ae320
TC
113
114 $client->submit($form, $data);
115
116 $this->assertEquals(302, $client->getResponse()->getStatusCode());
117
118 $crawler = $client->followRedirect();
119
120 $content1 = $client->getContainer()
121 ->get('doctrine.orm.entity_manager')
122 ->getRepository('WallabagCoreBundle:Entry')
123 ->findByUrlAndUserId(
124 'http://gilbert.pellegrom.me/recreating-the-square-slider',
125 $this->getLoggedInUserId()
126 );
127
128 $this->assertTrue($content1->isArchived());
129
130 $content2 = $client->getContainer()
131 ->get('doctrine.orm.entity_manager')
132 ->getRepository('WallabagCoreBundle:Entry')
133 ->findByUrlAndUserId(
134 'https://www.wallabag.org/features/',
135 $this->getLoggedInUserId()
136 );
137
138 $this->assertTrue($content2->isArchived());
139
4094ea47 140 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 141 $this->assertContains('flashes.import.notice.summary', $body[0]);
c32ae320
TC
142 }
143
7019c7cf
JB
144 public function testImportWallabagWithEmptyFile()
145 {
146 $this->logInAs('admin');
147 $client = $this->getClient();
148
149 $crawler = $client->request('GET', '/import/wallabag-v1');
150 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
151
152 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
153
4094ea47 154 $data = [
7019c7cf 155 'upload_import_file[file]' => $file,
4094ea47 156 ];
7019c7cf
JB
157
158 $client->submit($form, $data);
159
160 $this->assertEquals(302, $client->getResponse()->getStatusCode());
161
162 $crawler = $client->followRedirect();
163
4094ea47 164 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 165 $this->assertContains('flashes.import.notice.failed', $body[0]);
7019c7cf
JB
166 }
167}