]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
Retrieve created date from Pocket
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / WallabagV2ControllerTest.php
CommitLineData
6785f4aa
NL
1<?php
2
23634d5d 3namespace Tests\Wallabag\ImportBundle\Controller;
6785f4aa 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6785f4aa
NL
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class WallabagV2ControllerTest extends WallabagCoreTestCase
9{
10 public function testImportWallabag()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/wallabag-v2');
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-v2');
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
6785f4aa
NL
38 public function testImportWallabagWithFile()
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
43 $crawler = $client->request('GET', '/import/wallabag-v2');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
45
46 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
47
4094ea47 48 $data = [
6785f4aa 49 'upload_import_file[file]' => $file,
4094ea47 50 ];
6785f4aa
NL
51
52 $client->submit($form, $data);
53
54 $this->assertEquals(302, $client->getResponse()->getStatusCode());
55
56 $crawler = $client->followRedirect();
57
4094ea47 58 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 59 $this->assertContains('flashes.import.notice.summary', $body[0]);
f21a5388
NL
60
61 $content = $client->getContainer()
62 ->get('doctrine.orm.entity_manager')
63 ->getRepository('WallabagCoreBundle:Entry')
64 ->findByUrlAndUserId(
65 'http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867',
66 $this->getLoggedInUserId()
67 );
68
4c46e260
NL
69 $this->assertEmpty($content->getMimetype());
70 $this->assertEmpty($content->getPreviewPicture());
71 $this->assertEmpty($content->getLanguage());
8f336fda 72 $this->assertEquals(0, count($content->getTags()));
4c46e260
NL
73
74 $content = $client->getContainer()
75 ->get('doctrine.orm.entity_manager')
76 ->getRepository('WallabagCoreBundle:Entry')
77 ->findByUrlAndUserId(
78 'https://www.mediapart.fr/',
79 $this->getLoggedInUserId()
80 );
81
82 $this->assertNotEmpty($content->getMimetype());
83 $this->assertNotEmpty($content->getPreviewPicture());
84 $this->assertNotEmpty($content->getLanguage());
8f336fda 85 $this->assertEquals(2, count($content->getTags()));
6d65c0a8
JB
86 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
87 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
6785f4aa
NL
88 }
89
90 public function testImportWallabagWithEmptyFile()
91 {
92 $this->logInAs('admin');
93 $client = $this->getClient();
94
95 $crawler = $client->request('GET', '/import/wallabag-v2');
96 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
97
98 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
99
4094ea47 100 $data = [
6785f4aa 101 'upload_import_file[file]' => $file,
4094ea47 102 ];
6785f4aa
NL
103
104 $client->submit($form, $data);
105
106 $this->assertEquals(302, $client->getResponse()->getStatusCode());
107
108 $crawler = $client->followRedirect();
109
4094ea47 110 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 111 $this->assertContains('flashes.import.notice.failed', $body[0]);
6785f4aa
NL
112 }
113}