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 testImportReadabilityWithFile()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $crawler = $client->request('GET', '/import/readability');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
30 $file = new UploadedFile(__DIR__
.'/../fixtures/readability.json', 'readability.json');
33 'upload_import_file[file]' => $file,
36 $client->submit($form, $data);
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
40 $crawler = $client->followRedirect();
42 $content = $client->getContainer()
43 ->get('doctrine.orm.entity_manager')
44 ->getRepository('WallabagCoreBundle:Entry')
46 'https://venngage.com/blog/hashtags-are-worthless/',
47 $this->getLoggedInUserId()
50 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
51 $this->assertContains('flashes.import.notice.summary', $body[0]);
54 public function testImportReadabilityWithFileAndMarkAllAsRead()
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-read.json', 'readability-read.json');
65 'upload_import_file[file]' => $file,
66 'upload_import_file[mark_as_read]' => 1,
69 $client->submit($form, $data);
71 $this->assertEquals(302, $client->getResponse()->getStatusCode());
73 $crawler = $client->followRedirect();
75 $content1 = $client->getContainer()
76 ->get('doctrine.orm.entity_manager')
77 ->getRepository('WallabagCoreBundle:Entry')
79 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/',
80 $this->getLoggedInUserId()
83 $this->assertTrue($content1->isArchived());
85 $content2 = $client->getContainer()
86 ->get('doctrine.orm.entity_manager')
87 ->getRepository('WallabagCoreBundle:Entry')
89 'https://facebook.github.io/graphql/',
90 $this->getLoggedInUserId()
93 $this->assertTrue($content2->isArchived());
95 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
96 $this->assertContains('flashes.import.notice.summary', $body[0]);
99 public function testImportReadabilityWithEmptyFile()
101 $this->logInAs('admin');
102 $client = $this->getClient();
104 $crawler = $client->request('GET', '/import/readability');
105 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
107 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
110 'upload_import_file[file]' => $file,
113 $client->submit($form, $data);
115 $this->assertEquals(302, $client->getResponse()->getStatusCode());
117 $crawler = $client->followRedirect();
119 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
120 $this->assertContains('flashes.import.notice.failed', $body[0]);