]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
Add ability to define created_at for all import
[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
22 public function testImportWallabagWithFile()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $crawler = $client->request('GET', '/import/wallabag-v2');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
29
30 $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
31
4094ea47 32 $data = [
6785f4aa 33 'upload_import_file[file]' => $file,
4094ea47 34 ];
6785f4aa
NL
35
36 $client->submit($form, $data);
37
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
39
40 $crawler = $client->followRedirect();
41
4094ea47 42 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 43 $this->assertContains('flashes.import.notice.summary', $body[0]);
f21a5388
NL
44
45 $content = $client->getContainer()
46 ->get('doctrine.orm.entity_manager')
47 ->getRepository('WallabagCoreBundle:Entry')
48 ->findByUrlAndUserId(
49 'http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867',
50 $this->getLoggedInUserId()
51 );
52
4c46e260
NL
53 $this->assertEmpty($content->getMimetype());
54 $this->assertEmpty($content->getPreviewPicture());
55 $this->assertEmpty($content->getLanguage());
8f336fda 56 $this->assertEquals(0, count($content->getTags()));
4c46e260
NL
57
58 $content = $client->getContainer()
59 ->get('doctrine.orm.entity_manager')
60 ->getRepository('WallabagCoreBundle:Entry')
61 ->findByUrlAndUserId(
62 'https://www.mediapart.fr/',
63 $this->getLoggedInUserId()
64 );
65
66 $this->assertNotEmpty($content->getMimetype());
67 $this->assertNotEmpty($content->getPreviewPicture());
68 $this->assertNotEmpty($content->getLanguage());
8f336fda 69 $this->assertEquals(2, count($content->getTags()));
6d65c0a8
JB
70 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
71 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
6785f4aa
NL
72 }
73
74 public function testImportWallabagWithEmptyFile()
75 {
76 $this->logInAs('admin');
77 $client = $this->getClient();
78
79 $crawler = $client->request('GET', '/import/wallabag-v2');
80 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
81
82 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
83
4094ea47 84 $data = [
6785f4aa 85 'upload_import_file[file]' => $file,
4094ea47 86 ];
6785f4aa
NL
87
88 $client->submit($form, $data);
89
90 $this->assertEquals(302, $client->getResponse()->getStatusCode());
91
92 $crawler = $client->followRedirect();
93
4094ea47 94 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
4204a06b 95 $this->assertContains('flashes.import.notice.failed', $body[0]);
6785f4aa
NL
96 }
97}