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, $body = $crawler->filter('body')->extract(array('_text')));
43 $this->assertContains('flashes.import.notice.summary', $body[0]);
45 $content = $client->getContainer()
46 ->get('doctrine.orm.entity_manager')
47 ->getRepository('WallabagCoreBundle:Entry')
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()
53 $this->assertEmpty($content->getMimetype());
54 $this->assertEmpty($content->getPreviewPicture());
55 $this->assertEmpty($content->getLanguage());
56 $this->assertEquals(0, count($content->getTags()));
58 $content = $client->getContainer()
59 ->get('doctrine.orm.entity_manager')
60 ->getRepository('WallabagCoreBundle:Entry')
62 'https://www.mediapart.fr/',
63 $this->getLoggedInUserId()
66 $this->assertNotEmpty($content->getMimetype());
67 $this->assertNotEmpty($content->getPreviewPicture());
68 $this->assertNotEmpty($content->getLanguage());
69 $this->assertEquals(2, count($content->getTags()));
72 public function testImportWallabagWithEmptyFile()
74 $this->logInAs('admin');
75 $client = $this->getClient();
77 $crawler = $client->request('GET', '/import/wallabag-v2');
78 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
80 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
83 'upload_import_file[file]' => $file,
86 $client->submit($form, $data);
88 $this->assertEquals(302, $client->getResponse()->getStatusCode());
90 $crawler = $client->followRedirect();
92 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text')));
93 $this->assertContains('flashes.import.notice.failed', $body[0]);