diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-01 21:27:35 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-22 17:59:35 +0200 |
commit | 23634d5d842dabcf5d7475e2becb7e127824239e (patch) | |
tree | b91688722a996c46f27e8fe0542c356424483da3 /tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | |
parent | 891a026e31ad54ca90b70f6026f23260cfadb7fd (diff) | |
download | wallabag-23634d5d842dabcf5d7475e2becb7e127824239e.tar.gz wallabag-23634d5d842dabcf5d7475e2becb7e127824239e.tar.zst wallabag-23634d5d842dabcf5d7475e2becb7e127824239e.zip |
Jump to Symfony 3.1
Diffstat (limited to 'tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php new file mode 100644 index 00000000..d8d2c8bf --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | |||
@@ -0,0 +1,95 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
7 | |||
8 | class 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 = [ | ||
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, $body = $crawler->filter('body')->extract(['_text'])); | ||
43 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
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->assertEmpty($content->getMimetype()); | ||
54 | $this->assertEmpty($content->getPreviewPicture()); | ||
55 | $this->assertEmpty($content->getLanguage()); | ||
56 | $this->assertEquals(0, count($content->getTags())); | ||
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()); | ||
69 | $this->assertEquals(2, count($content->getTags())); | ||
70 | } | ||
71 | |||
72 | public function testImportWallabagWithEmptyFile() | ||
73 | { | ||
74 | $this->logInAs('admin'); | ||
75 | $client = $this->getClient(); | ||
76 | |||
77 | $crawler = $client->request('GET', '/import/wallabag-v2'); | ||
78 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
79 | |||
80 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | ||
81 | |||
82 | $data = [ | ||
83 | 'upload_import_file[file]' => $file, | ||
84 | ]; | ||
85 | |||
86 | $client->submit($form, $data); | ||
87 | |||
88 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
89 | |||
90 | $crawler = $client->followRedirect(); | ||
91 | |||
92 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
93 | $this->assertContains('flashes.import.notice.failed', $body[0]); | ||
94 | } | ||
95 | } | ||