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 testImportReadabilityWithFile()
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();
62 $file = new UploadedFile(__DIR__
.'/../fixtures/readability.json', 'readability.json');
65 'upload_import_file[file]' => $file,
68 $client->submit($form, $data);
70 $this->assertEquals(302, $client->getResponse()->getStatusCode());
72 $crawler = $client->followRedirect();
74 $content = $client->getContainer()
75 ->get('doctrine.orm.entity_manager')
76 ->getRepository('WallabagCoreBundle:Entry')
78 'https://venngage.com/blog/hashtags-are-worthless/',
79 $this->getLoggedInUserId()
82 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
83 $this->assertContains('flashes.import.notice.summary', $body[0]);
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'));
93 public function testImportReadabilityWithFileAndMarkAllAsRead()
95 $this->logInAs('admin');
96 $client = $this->getClient();
98 $crawler = $client->request('GET', '/import/readability');
99 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
101 $file = new UploadedFile(__DIR__
.'/../fixtures/readability-read.json', 'readability-read.json');
104 'upload_import_file[file]' => $file,
105 'upload_import_file[mark_as_read]' => 1,
108 $client->submit($form, $data);
110 $this->assertEquals(302, $client->getResponse()->getStatusCode());
112 $crawler = $client->followRedirect();
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()
122 $this->assertTrue($content1->isArchived());
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()
132 $this->assertTrue($content2->isArchived());
134 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
135 $this->assertContains('flashes.import.notice.summary', $body[0]);
138 public function testImportReadabilityWithEmptyFile()
140 $this->logInAs('admin');
141 $client = $this->getClient();
143 $crawler = $client->request('GET', '/import/readability');
144 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
146 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
149 'upload_import_file[file]' => $file,
152 $client->submit($form, $data);
154 $this->assertEquals(302, $client->getResponse()->getStatusCode());
156 $crawler = $client->followRedirect();
158 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
159 $this->assertContains('flashes.import.notice.failed', $body[0]);