]>
Commit | Line | Data |
---|---|---|
a1a10770 JB |
1 | <?php |
2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | |
7 | ||
8 | class 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 | ||
27 | $client->getContainer()->get('craue_config')->set('rabbitmq', 1); | |
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 | ||
35 | $client->getContainer()->get('craue_config')->set('rabbitmq', 0); | |
36 | } | |
37 | ||
a1a10770 JB |
38 | public function testImportReadabilityWithFile() |
39 | { | |
40 | $this->logInAs('admin'); | |
41 | $client = $this->getClient(); | |
42 | ||
43 | $crawler = $client->request('GET', '/import/readability'); | |
44 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
45 | ||
46 | $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); | |
47 | ||
48 | $data = [ | |
49 | 'upload_import_file[file]' => $file, | |
50 | ]; | |
51 | ||
52 | $client->submit($form, $data); | |
53 | ||
54 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
55 | ||
56 | $crawler = $client->followRedirect(); | |
57 | ||
58 | $content = $client->getContainer() | |
59 | ->get('doctrine.orm.entity_manager') | |
60 | ->getRepository('WallabagCoreBundle:Entry') | |
61 | ->findByUrlAndUserId( | |
62 | 'https://venngage.com/blog/hashtags-are-worthless/', | |
63 | $this->getLoggedInUserId() | |
64 | ); | |
65 | ||
66 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
67 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
6d65c0a8 JB |
68 | |
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')); | |
a1a10770 JB |
75 | } |
76 | ||
77 | public function testImportReadabilityWithFileAndMarkAllAsRead() | |
78 | { | |
79 | $this->logInAs('admin'); | |
80 | $client = $this->getClient(); | |
81 | ||
82 | $crawler = $client->request('GET', '/import/readability'); | |
83 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
84 | ||
85 | $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json'); | |
86 | ||
87 | $data = [ | |
88 | 'upload_import_file[file]' => $file, | |
89 | 'upload_import_file[mark_as_read]' => 1, | |
90 | ]; | |
91 | ||
92 | $client->submit($form, $data); | |
93 | ||
94 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
95 | ||
96 | $crawler = $client->followRedirect(); | |
97 | ||
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() | |
104 | ); | |
105 | ||
106 | $this->assertTrue($content1->isArchived()); | |
107 | ||
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() | |
114 | ); | |
115 | ||
116 | $this->assertTrue($content2->isArchived()); | |
117 | ||
118 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
119 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
120 | } | |
121 | ||
122 | public function testImportReadabilityWithEmptyFile() | |
123 | { | |
124 | $this->logInAs('admin'); | |
125 | $client = $this->getClient(); | |
126 | ||
127 | $crawler = $client->request('GET', '/import/readability'); | |
128 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
129 | ||
130 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | |
131 | ||
132 | $data = [ | |
133 | 'upload_import_file[file]' => $file, | |
134 | ]; | |
135 | ||
136 | $client->submit($form, $data); | |
137 | ||
138 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
139 | ||
140 | $crawler = $client->followRedirect(); | |
141 | ||
142 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
143 | $this->assertContains('flashes.import.notice.failed', $body[0]); | |
144 | } | |
145 | } |