]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
Add test for RabbitMQ
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV1ControllerTest.php
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('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
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
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 '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
73 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
74 $this->assertContains('flashes.import.notice.summary', $body[0]);
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());
81 }
82
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
93 $data = [
94 'upload_import_file[file]' => $file,
95 'upload_import_file[mark_as_read]' => 1,
96 ];
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
124 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
125 $this->assertContains('flashes.import.notice.summary', $body[0]);
126 }
127
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
138 $data = [
139 'upload_import_file[file]' => $file,
140 ];
141
142 $client->submit($form, $data);
143
144 $this->assertEquals(302, $client->getResponse()->getStatusCode());
145
146 $crawler = $client->followRedirect();
147
148 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
149 $this->assertContains('flashes.import.notice.failed', $body[0]);
150 }
151 }