]>
Commit | Line | Data |
---|---|---|
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 WallabagV1ControllerTest extends WallabagCoreTestCase | |
9 | { | |
10 | public function testImportWallabag() | |
11 | { | |
12 | $this->logInAs('admin'); | |
13 | $client = $this->getClient(); | |
14 | ||
15 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
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 testImportWallabagWithRabbitEnabled() | |
23 | { | |
24 | $this->logInAs('admin'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); | |
28 | ||
29 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
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('import_with_rabbitmq', 0); | |
36 | } | |
37 | ||
38 | public function testImportWallabagWithRedisEnabled() | |
39 | { | |
40 | $this->logInAs('admin'); | |
41 | $client = $this->getClient(); | |
42 | ||
43 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | |
44 | ||
45 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
46 | ||
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()); | |
50 | ||
51 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); | |
52 | } | |
53 | ||
54 | public function testImportWallabagWithFile() | |
55 | { | |
56 | $this->logInAs('admin'); | |
57 | $client = $this->getClient(); | |
58 | ||
59 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
60 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
61 | ||
62 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json'); | |
63 | ||
64 | $data = [ | |
65 | 'upload_import_file[file]' => $file, | |
66 | ]; | |
67 | ||
68 | $client->submit($form, $data); | |
69 | ||
70 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
71 | ||
72 | $crawler = $client->followRedirect(); | |
73 | ||
74 | $content = $client->getContainer() | |
75 | ->get('doctrine.orm.entity_manager') | |
76 | ->getRepository('WallabagCoreBundle:Entry') | |
77 | ->findByUrlAndUserId( | |
78 | 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur', | |
79 | $this->getLoggedInUserId() | |
80 | ); | |
81 | ||
82 | $tag = $client->getContainer() | |
83 | ->get('doctrine.orm.entity_manager') | |
84 | ->getRepository('WallabagCoreBundle:Tag') | |
85 | ->findOneByLabel('Framabag'); | |
86 | ||
87 | $this->assertTrue($content->getTags()->contains($tag)); | |
88 | ||
89 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
90 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
91 | ||
92 | $this->assertEmpty($content->getMimetype()); | |
93 | $this->assertEmpty($content->getPreviewPicture()); | |
94 | $this->assertEmpty($content->getLanguage()); | |
95 | $this->assertEquals(1, count($content->getTags())); | |
96 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | |
97 | } | |
98 | ||
99 | public function testImportWallabagWithFileAndMarkAllAsRead() | |
100 | { | |
101 | $this->logInAs('admin'); | |
102 | $client = $this->getClient(); | |
103 | ||
104 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
105 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
106 | ||
107 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json'); | |
108 | ||
109 | $data = [ | |
110 | 'upload_import_file[file]' => $file, | |
111 | 'upload_import_file[mark_as_read]' => 1, | |
112 | ]; | |
113 | ||
114 | $client->submit($form, $data); | |
115 | ||
116 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
117 | ||
118 | $crawler = $client->followRedirect(); | |
119 | ||
120 | $content1 = $client->getContainer() | |
121 | ->get('doctrine.orm.entity_manager') | |
122 | ->getRepository('WallabagCoreBundle:Entry') | |
123 | ->findByUrlAndUserId( | |
124 | 'http://gilbert.pellegrom.me/recreating-the-square-slider', | |
125 | $this->getLoggedInUserId() | |
126 | ); | |
127 | ||
128 | $this->assertTrue($content1->isArchived()); | |
129 | ||
130 | $content2 = $client->getContainer() | |
131 | ->get('doctrine.orm.entity_manager') | |
132 | ->getRepository('WallabagCoreBundle:Entry') | |
133 | ->findByUrlAndUserId( | |
134 | 'https://www.wallabag.org/features/', | |
135 | $this->getLoggedInUserId() | |
136 | ); | |
137 | ||
138 | $this->assertTrue($content2->isArchived()); | |
139 | ||
140 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
141 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
142 | } | |
143 | ||
144 | public function testImportWallabagWithEmptyFile() | |
145 | { | |
146 | $this->logInAs('admin'); | |
147 | $client = $this->getClient(); | |
148 | ||
149 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
150 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
151 | ||
152 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | |
153 | ||
154 | $data = [ | |
155 | 'upload_import_file[file]' => $file, | |
156 | ]; | |
157 | ||
158 | $client->submit($form, $data); | |
159 | ||
160 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
161 | ||
162 | $crawler = $client->followRedirect(); | |
163 | ||
164 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
165 | $this->assertContains('flashes.import.notice.failed', $body[0]); | |
166 | } | |
167 | } |