3 namespace Wallabag\ImportBundle\Tests\Controller
;
5 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase
;
6 use Symfony\Component\HttpFoundation\File\UploadedFile
;
8 class WallabagV2ControllerTest
extends WallabagCoreTestCase
10 public function testImportWallabag()
12 $this->logInAs('admin');
13 $client = $this->getClient();
15 $crawler = $client->request('GET', '/import/wallabag-v2');
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());
22 public function testImportWallabagWithFile()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $crawler = $client->request('GET', '/import/wallabag-v2');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
30 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json');
33 'upload_import_file[file]' => $file,
36 $client->submit($form, $data);
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
40 $crawler = $client->followRedirect();
42 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
43 $this->assertContains('Import summary', $alert[0]);
46 public function testImportWallabagWithEmptyFile()
48 $this->logInAs('admin');
49 $client = $this->getClient();
51 $crawler = $client->request('GET', '/import/wallabag-v2');
52 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
54 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
57 'upload_import_file[file]' => $file,
60 $client->submit($form, $data);
62 $this->assertEquals(302, $client->getResponse()->getStatusCode());
64 $crawler = $client->followRedirect();
66 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
67 $this->assertContains('Import failed, please try again', $alert[0]);