3 namespace Tests\Wallabag\ImportBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Symfony\Component\HttpFoundation\File\UploadedFile
;
8 class ReadabilityControllerTest
extends WallabagCoreTestCase
10 public function testImportReadability()
12 $this->logInAs('admin');
13 $client = $this->getClient();
15 $crawler = $client->request('GET', '/import/readability');
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());
22 public function testImportReadabilityWithRabbitEnabled()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
29 $crawler = $client->request('GET', '/import/readability');
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());
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
38 public function testImportReadabilityWithRedisEnabled()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
45 $crawler = $client->request('GET', '/import/readability');
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());
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
54 public function testImportReadabilityBadFile()
56 $this->logInAs('admin');
57 $client = $this->getClient();
59 $crawler = $client->request('GET', '/import/readability');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
63 'upload_import_file[file]' => '',
66 $client->submit($form, $data);
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
71 public function testImportReadabilityWithFile()
73 $this->logInAs('admin');
74 $client = $this->getClient();
76 $crawler = $client->request('GET', '/import/readability');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
79 $file = new UploadedFile(__DIR__
.'/../fixtures/readability.json', 'readability.json');
82 'upload_import_file[file]' => $file,
85 $client->submit($form, $data);
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
89 $crawler = $client->followRedirect();
91 $content = $client->getContainer()
92 ->get('doctrine.orm.entity_manager')
93 ->getRepository('WallabagCoreBundle:Entry')
95 'https://venngage.com/blog/hashtags-are-worthless/',
96 $this->getLoggedInUserId()
99 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
100 $this->assertContains('flashes.import.notice.summary', $body[0]);
102 $this->assertNotEmpty($content->getMimetype());
103 $this->assertNotEmpty($content->getPreviewPicture());
104 $this->assertNotEmpty($content->getLanguage());
105 $this->assertEquals(0, count($content->getTags()));
106 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
107 $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d'));
110 public function testImportReadabilityWithFileAndMarkAllAsRead()
112 $this->logInAs('admin');
113 $client = $this->getClient();
115 $crawler = $client->request('GET', '/import/readability');
116 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
118 $file = new UploadedFile(__DIR__
.'/../fixtures/readability-read.json', 'readability-read.json');
121 'upload_import_file[file]' => $file,
122 'upload_import_file[mark_as_read]' => 1,
125 $client->submit($form, $data);
127 $this->assertEquals(302, $client->getResponse()->getStatusCode());
129 $crawler = $client->followRedirect();
131 $content1 = $client->getContainer()
132 ->get('doctrine.orm.entity_manager')
133 ->getRepository('WallabagCoreBundle:Entry')
134 ->findByUrlAndUserId(
135 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/',
136 $this->getLoggedInUserId()
139 $this->assertTrue($content1->isArchived());
141 $content2 = $client->getContainer()
142 ->get('doctrine.orm.entity_manager')
143 ->getRepository('WallabagCoreBundle:Entry')
144 ->findByUrlAndUserId(
145 'https://facebook.github.io/graphql/',
146 $this->getLoggedInUserId()
149 $this->assertTrue($content2->isArchived());
151 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
152 $this->assertContains('flashes.import.notice.summary', $body[0]);
155 public function testImportReadabilityWithEmptyFile()
157 $this->logInAs('admin');
158 $client = $this->getClient();
160 $crawler = $client->request('GET', '/import/readability');
161 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
163 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
166 'upload_import_file[file]' => $file,
169 $client->submit($form, $data);
171 $this->assertEquals(302, $client->getResponse()->getStatusCode());
173 $crawler = $client->followRedirect();
175 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
176 $this->assertContains('flashes.import.notice.failed', $body[0]);