3 namespace Tests\Wallabag\ImportBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Symfony\Component\HttpFoundation\File\UploadedFile
;
8 class WallabagV1ControllerTest
extends WallabagCoreTestCase
10 public function testImportWallabag()
12 $this->logInAs('admin');
13 $client = $this->getClient();
15 $crawler = $client->request('GET', '/import/wallabag-v1');
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());
22 public function testImportWallabagWithRabbitEnabled()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
29 $crawler = $client->request('GET', '/import/wallabag-v1');
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());
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
38 public function testImportWallabagWithRedisEnabled()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
45 $crawler = $client->request('GET', '/import/wallabag-v1');
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());
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
54 public function testImportWallabagBadFile()
56 $this->logInAs('admin');
57 $client = $this->getClient();
59 $crawler = $client->request('GET', '/import/wallabag-v1');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
63 'upload_import_file[file]' => '',
66 $client->submit($form, $data);
68 $this->assertEquals(200, $client->getResponse()->getStatusCode());
71 public function testImportWallabagWithFile()
73 $this->logInAs('admin');
74 $client = $this->getClient();
76 $crawler = $client->request('GET', '/import/wallabag-v1');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
79 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
82 'upload_import_file[file]' => $file,
85 $client->submit($form, $data);
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
89 $crawler = $client->followRedirect();
91 $content = $client->getContainer()
92 ->get('doctrine.orm.entity_manager')
93 ->getRepository('WallabagCoreBundle:Entry')
95 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
96 $this->getLoggedInUserId()
99 $tag = $client->getContainer()
100 ->get('doctrine.orm.entity_manager')
101 ->getRepository('WallabagCoreBundle:Tag')
102 ->findOneByLabel('Framabag');
104 $this->assertTrue($content->getTags()->contains($tag));
106 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
107 $this->assertContains('flashes.import.notice.summary', $body[0]);
109 $this->assertEmpty($content->getMimetype());
110 $this->assertEmpty($content->getPreviewPicture());
111 $this->assertEmpty($content->getLanguage());
112 $this->assertEquals(1, count($content->getTags()));
113 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
116 public function testImportWallabagWithFileAndMarkAllAsRead()
118 $this->logInAs('admin');
119 $client = $this->getClient();
121 $crawler = $client->request('GET', '/import/wallabag-v1');
122 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
124 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
127 'upload_import_file[file]' => $file,
128 'upload_import_file[mark_as_read]' => 1,
131 $client->submit($form, $data);
133 $this->assertEquals(302, $client->getResponse()->getStatusCode());
135 $crawler = $client->followRedirect();
137 $content1 = $client->getContainer()
138 ->get('doctrine.orm.entity_manager')
139 ->getRepository('WallabagCoreBundle:Entry')
140 ->findByUrlAndUserId(
141 'http://gilbert.pellegrom.me/recreating-the-square-slider',
142 $this->getLoggedInUserId()
145 $this->assertTrue($content1->isArchived());
147 $content2 = $client->getContainer()
148 ->get('doctrine.orm.entity_manager')
149 ->getRepository('WallabagCoreBundle:Entry')
150 ->findByUrlAndUserId(
151 'https://www.wallabag.org/features/',
152 $this->getLoggedInUserId()
155 $this->assertTrue($content2->isArchived());
157 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
158 $this->assertContains('flashes.import.notice.summary', $body[0]);
161 public function testImportWallabagWithEmptyFile()
163 $this->logInAs('admin');
164 $client = $this->getClient();
166 $crawler = $client->request('GET', '/import/wallabag-v1');
167 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
169 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
172 'upload_import_file[file]' => $file,
175 $client->submit($form, $data);
177 $this->assertEquals(302, $client->getResponse()->getStatusCode());
179 $crawler = $client->followRedirect();
181 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
182 $this->assertContains('flashes.import.notice.failed', $body[0]);