]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Tests/Controller/WallabagV2ControllerTest.php
add test to check empty fields
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Tests / Controller / WallabagV2ControllerTest.php
CommitLineData
6785f4aa
NL
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
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
32 $data = array(
33 'upload_import_file[file]' => $file,
34 );
35
36 $client->submit($form, $data);
37
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
39
40 $crawler = $client->followRedirect();
41
42 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
43 $this->assertContains('Import summary', $alert[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
53 $this->assertEquals('', $content->getMimetype());
54 $this->assertEquals('', $content->getPreviewPicture());
55 $this->assertEquals('', $content->getLanguage());
6785f4aa
NL
56 }
57
58 public function testImportWallabagWithEmptyFile()
59 {
60 $this->logInAs('admin');
61 $client = $this->getClient();
62
63 $crawler = $client->request('GET', '/import/wallabag-v2');
64 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
65
66 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
67
68 $data = array(
69 'upload_import_file[file]' => $file,
70 );
71
72 $client->submit($form, $data);
73
74 $this->assertEquals(302, $client->getResponse()->getStatusCode());
75
76 $crawler = $client->followRedirect();
77
78 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
79 $this->assertContains('Import failed, please try again', $alert[0]);
80 }
81}