]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
Re-facto EntryConsumer
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / ReadabilityControllerTest.php
CommitLineData
a1a10770
JB
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class ReadabilityControllerTest extends WallabagCoreTestCase
9{
10 public function testImportReadability()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/readability');
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 testImportReadabilityWithRabbitEnabled()
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/readability');
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 testImportReadabilityWithRedisEnabled()
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/readability');
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
a1a10770
JB
54 public function testImportReadabilityWithFile()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/readability');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json');
63
64 $data = [
65 'upload_import_file[file]' => $file,
66 ];
67
68 $client->submit($form, $data);
69
70 $this->assertEquals(302, $client->getResponse()->getStatusCode());
71
72 $crawler = $client->followRedirect();
73
74 $content = $client->getContainer()
75 ->get('doctrine.orm.entity_manager')
76 ->getRepository('WallabagCoreBundle:Entry')
77 ->findByUrlAndUserId(
78 'https://venngage.com/blog/hashtags-are-worthless/',
79 $this->getLoggedInUserId()
80 );
81
82 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
83 $this->assertContains('flashes.import.notice.summary', $body[0]);
6d65c0a8
JB
84
85 $this->assertNotEmpty($content->getMimetype());
86 $this->assertNotEmpty($content->getPreviewPicture());
87 $this->assertNotEmpty($content->getLanguage());
88 $this->assertEquals(0, count($content->getTags()));
89 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
90 $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d'));
a1a10770
JB
91 }
92
93 public function testImportReadabilityWithFileAndMarkAllAsRead()
94 {
95 $this->logInAs('admin');
96 $client = $this->getClient();
97
98 $crawler = $client->request('GET', '/import/readability');
99 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
100
101 $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json');
102
103 $data = [
104 'upload_import_file[file]' => $file,
105 'upload_import_file[mark_as_read]' => 1,
106 ];
107
108 $client->submit($form, $data);
109
110 $this->assertEquals(302, $client->getResponse()->getStatusCode());
111
112 $crawler = $client->followRedirect();
113
114 $content1 = $client->getContainer()
115 ->get('doctrine.orm.entity_manager')
116 ->getRepository('WallabagCoreBundle:Entry')
117 ->findByUrlAndUserId(
118 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/',
119 $this->getLoggedInUserId()
120 );
121
122 $this->assertTrue($content1->isArchived());
123
124 $content2 = $client->getContainer()
125 ->get('doctrine.orm.entity_manager')
126 ->getRepository('WallabagCoreBundle:Entry')
127 ->findByUrlAndUserId(
128 'https://facebook.github.io/graphql/',
129 $this->getLoggedInUserId()
130 );
131
132 $this->assertTrue($content2->isArchived());
133
134 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
135 $this->assertContains('flashes.import.notice.summary', $body[0]);
136 }
137
138 public function testImportReadabilityWithEmptyFile()
139 {
140 $this->logInAs('admin');
141 $client = $this->getClient();
142
143 $crawler = $client->request('GET', '/import/readability');
144 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
145
146 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
147
148 $data = [
149 'upload_import_file[file]' => $file,
150 ];
151
152 $client->submit($form, $data);
153
154 $this->assertEquals(302, $client->getResponse()->getStatusCode());
155
156 $crawler = $client->followRedirect();
157
158 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
159 $this->assertContains('flashes.import.notice.failed', $body[0]);
160 }
161}