]>
Commit | Line | Data |
---|---|---|
7019c7cf JB |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\ImportBundle\Controller; |
7019c7cf | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
7019c7cf JB |
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 | ||
13470c35 JB |
22 | public function testImportWallabagWithRabbitEnabled() |
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/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('rabbitmq', 0); | |
36 | } | |
37 | ||
7019c7cf JB |
38 | public function testImportWallabagWithFile() |
39 | { | |
40 | $this->logInAs('admin'); | |
41 | $client = $this->getClient(); | |
42 | ||
43 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
44 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
45 | ||
46 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json'); | |
47 | ||
4094ea47 | 48 | $data = [ |
7019c7cf | 49 | 'upload_import_file[file]' => $file, |
4094ea47 | 50 | ]; |
7019c7cf JB |
51 | |
52 | $client->submit($form, $data); | |
53 | ||
54 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
55 | ||
56 | $crawler = $client->followRedirect(); | |
57 | ||
fca2b052 TC |
58 | $content = $client->getContainer() |
59 | ->get('doctrine.orm.entity_manager') | |
60 | ->getRepository('WallabagCoreBundle:Entry') | |
61 | ->findByUrlAndUserId( | |
62 | 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur', | |
63 | $this->getLoggedInUserId() | |
64 | ); | |
65 | ||
66 | $tag = $client->getContainer() | |
67 | ->get('doctrine.orm.entity_manager') | |
68 | ->getRepository('WallabagCoreBundle:Tag') | |
69 | ->findOneByLabel('Framabag'); | |
70 | ||
71 | $this->assertTrue($content->getTags()->contains($tag)); | |
72 | ||
4094ea47 | 73 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 74 | $this->assertContains('flashes.import.notice.summary', $body[0]); |
6d65c0a8 JB |
75 | |
76 | $this->assertEmpty($content->getMimetype()); | |
77 | $this->assertEmpty($content->getPreviewPicture()); | |
78 | $this->assertEmpty($content->getLanguage()); | |
79 | $this->assertEquals(1, count($content->getTags())); | |
80 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | |
7019c7cf JB |
81 | } |
82 | ||
c32ae320 TC |
83 | public function testImportWallabagWithFileAndMarkAllAsRead() |
84 | { | |
85 | $this->logInAs('admin'); | |
86 | $client = $this->getClient(); | |
87 | ||
88 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
89 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
90 | ||
91 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json'); | |
92 | ||
4094ea47 | 93 | $data = [ |
c32ae320 TC |
94 | 'upload_import_file[file]' => $file, |
95 | 'upload_import_file[mark_as_read]' => 1, | |
4094ea47 | 96 | ]; |
c32ae320 TC |
97 | |
98 | $client->submit($form, $data); | |
99 | ||
100 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
101 | ||
102 | $crawler = $client->followRedirect(); | |
103 | ||
104 | $content1 = $client->getContainer() | |
105 | ->get('doctrine.orm.entity_manager') | |
106 | ->getRepository('WallabagCoreBundle:Entry') | |
107 | ->findByUrlAndUserId( | |
108 | 'http://gilbert.pellegrom.me/recreating-the-square-slider', | |
109 | $this->getLoggedInUserId() | |
110 | ); | |
111 | ||
112 | $this->assertTrue($content1->isArchived()); | |
113 | ||
114 | $content2 = $client->getContainer() | |
115 | ->get('doctrine.orm.entity_manager') | |
116 | ->getRepository('WallabagCoreBundle:Entry') | |
117 | ->findByUrlAndUserId( | |
118 | 'https://www.wallabag.org/features/', | |
119 | $this->getLoggedInUserId() | |
120 | ); | |
121 | ||
122 | $this->assertTrue($content2->isArchived()); | |
123 | ||
4094ea47 | 124 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 125 | $this->assertContains('flashes.import.notice.summary', $body[0]); |
c32ae320 TC |
126 | } |
127 | ||
7019c7cf JB |
128 | public function testImportWallabagWithEmptyFile() |
129 | { | |
130 | $this->logInAs('admin'); | |
131 | $client = $this->getClient(); | |
132 | ||
133 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
134 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
135 | ||
136 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | |
137 | ||
4094ea47 | 138 | $data = [ |
7019c7cf | 139 | 'upload_import_file[file]' => $file, |
4094ea47 | 140 | ]; |
7019c7cf JB |
141 | |
142 | $client->submit($form, $data); | |
143 | ||
144 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
145 | ||
146 | $crawler = $client->followRedirect(); | |
147 | ||
4094ea47 | 148 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 149 | $this->assertContains('flashes.import.notice.failed', $body[0]); |
7019c7cf JB |
150 | } |
151 | } |