]>
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 | ||
22 | public function testImportReadabilityWithFile() | |
23 | { | |
24 | $this->logInAs('admin'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $crawler = $client->request('GET', '/import/readability'); | |
28 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
29 | ||
30 | $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); | |
31 | ||
32 | $data = [ | |
33 | 'upload_import_file[file]' => $file, | |
34 | ]; | |
35 | ||
36 | $client->submit($form, $data); | |
37 | ||
38 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
39 | ||
40 | $crawler = $client->followRedirect(); | |
41 | ||
42 | $content = $client->getContainer() | |
43 | ->get('doctrine.orm.entity_manager') | |
44 | ->getRepository('WallabagCoreBundle:Entry') | |
45 | ->findByUrlAndUserId( | |
46 | 'https://venngage.com/blog/hashtags-are-worthless/', | |
47 | $this->getLoggedInUserId() | |
48 | ); | |
49 | ||
50 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
51 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
6d65c0a8 JB |
52 | |
53 | $this->assertNotEmpty($content->getMimetype()); | |
54 | $this->assertNotEmpty($content->getPreviewPicture()); | |
55 | $this->assertNotEmpty($content->getLanguage()); | |
56 | $this->assertEquals(0, count($content->getTags())); | |
57 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | |
58 | $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d')); | |
a1a10770 JB |
59 | } |
60 | ||
61 | public function testImportReadabilityWithFileAndMarkAllAsRead() | |
62 | { | |
63 | $this->logInAs('admin'); | |
64 | $client = $this->getClient(); | |
65 | ||
66 | $crawler = $client->request('GET', '/import/readability'); | |
67 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
68 | ||
69 | $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json'); | |
70 | ||
71 | $data = [ | |
72 | 'upload_import_file[file]' => $file, | |
73 | 'upload_import_file[mark_as_read]' => 1, | |
74 | ]; | |
75 | ||
76 | $client->submit($form, $data); | |
77 | ||
78 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
79 | ||
80 | $crawler = $client->followRedirect(); | |
81 | ||
82 | $content1 = $client->getContainer() | |
83 | ->get('doctrine.orm.entity_manager') | |
84 | ->getRepository('WallabagCoreBundle:Entry') | |
85 | ->findByUrlAndUserId( | |
86 | 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/', | |
87 | $this->getLoggedInUserId() | |
88 | ); | |
89 | ||
90 | $this->assertTrue($content1->isArchived()); | |
91 | ||
92 | $content2 = $client->getContainer() | |
93 | ->get('doctrine.orm.entity_manager') | |
94 | ->getRepository('WallabagCoreBundle:Entry') | |
95 | ->findByUrlAndUserId( | |
96 | 'https://facebook.github.io/graphql/', | |
97 | $this->getLoggedInUserId() | |
98 | ); | |
99 | ||
100 | $this->assertTrue($content2->isArchived()); | |
101 | ||
102 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
103 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
104 | } | |
105 | ||
106 | public function testImportReadabilityWithEmptyFile() | |
107 | { | |
108 | $this->logInAs('admin'); | |
109 | $client = $this->getClient(); | |
110 | ||
111 | $crawler = $client->request('GET', '/import/readability'); | |
112 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
113 | ||
114 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | |
115 | ||
116 | $data = [ | |
117 | 'upload_import_file[file]' => $file, | |
118 | ]; | |
119 | ||
120 | $client->submit($form, $data); | |
121 | ||
122 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
123 | ||
124 | $crawler = $client->followRedirect(); | |
125 | ||
126 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
127 | $this->assertContains('flashes.import.notice.failed', $body[0]); | |
128 | } | |
129 | } |