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('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('rabbitmq', 0);
38 public function testImportReadabilityWithFile()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $crawler = $client->request('GET', '/import/readability');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
46 $file = new UploadedFile(__DIR__
.'/../fixtures/readability.json', 'readability.json');
49 'upload_import_file[file]' => $file,
52 $client->submit($form, $data);
54 $this->assertEquals(302, $client->getResponse()->getStatusCode());
56 $crawler = $client->followRedirect();
58 $content = $client->getContainer()
59 ->get('doctrine.orm.entity_manager')
60 ->getRepository('WallabagCoreBundle:Entry')
62 'https://venngage.com/blog/hashtags-are-worthless/',
63 $this->getLoggedInUserId()
66 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
67 $this->assertContains('flashes.import.notice.summary', $body[0]);
69 $this->assertNotEmpty($content->getMimetype());
70 $this->assertNotEmpty($content->getPreviewPicture());
71 $this->assertNotEmpty($content->getLanguage());
72 $this->assertEquals(0, count($content->getTags()));
73 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
74 $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d'));
77 public function testImportReadabilityWithFileAndMarkAllAsRead()
79 $this->logInAs('admin');
80 $client = $this->getClient();
82 $crawler = $client->request('GET', '/import/readability');
83 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
85 $file = new UploadedFile(__DIR__
.'/../fixtures/readability-read.json', 'readability-read.json');
88 'upload_import_file[file]' => $file,
89 'upload_import_file[mark_as_read]' => 1,
92 $client->submit($form, $data);
94 $this->assertEquals(302, $client->getResponse()->getStatusCode());
96 $crawler = $client->followRedirect();
98 $content1 = $client->getContainer()
99 ->get('doctrine.orm.entity_manager')
100 ->getRepository('WallabagCoreBundle:Entry')
101 ->findByUrlAndUserId(
102 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/',
103 $this->getLoggedInUserId()
106 $this->assertTrue($content1->isArchived());
108 $content2 = $client->getContainer()
109 ->get('doctrine.orm.entity_manager')
110 ->getRepository('WallabagCoreBundle:Entry')
111 ->findByUrlAndUserId(
112 'https://facebook.github.io/graphql/',
113 $this->getLoggedInUserId()
116 $this->assertTrue($content2->isArchived());
118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
119 $this->assertContains('flashes.import.notice.summary', $body[0]);
122 public function testImportReadabilityWithEmptyFile()
124 $this->logInAs('admin');
125 $client = $this->getClient();
127 $crawler = $client->request('GET', '/import/readability');
128 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
130 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
133 'upload_import_file[file]' => $file,
136 $client->submit($form, $data);
138 $this->assertEquals(302, $client->getResponse()->getStatusCode());
140 $crawler = $client->followRedirect();
142 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
143 $this->assertContains('flashes.import.notice.failed', $body[0]);