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