3 namespace Tests\Wallabag\ImportBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Symfony\Component\HttpFoundation\File\UploadedFile
;
8 class WallabagV1ControllerTest
extends WallabagCoreTestCase
10 public function testImportWallabag()
12 $this->logInAs('admin');
13 $client = $this->getClient();
15 $crawler = $client->request('GET', '/import/wallabag-v1');
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-v1');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
30 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
33 'upload_import_file[file]' => $file,
36 $client->submit($form, $data);
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
40 $crawler = $client->followRedirect();
42 $content = $client->getContainer()
43 ->get('doctrine.orm.entity_manager')
44 ->getRepository('WallabagCoreBundle:Entry')
46 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
47 $this->getLoggedInUserId()
50 $tag = $client->getContainer()
51 ->get('doctrine.orm.entity_manager')
52 ->getRepository('WallabagCoreBundle:Tag')
53 ->findOneByLabel('Framabag');
55 $this->assertTrue($content->getTags()->contains($tag));
57 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
58 $this->assertContains('flashes.import.notice.summary', $body[0]);
61 public function testImportWallabagWithFileAndMarkAllAsRead()
63 $this->logInAs('admin');
64 $client = $this->getClient();
66 $crawler = $client->request('GET', '/import/wallabag-v1');
67 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
69 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
72 'upload_import_file[file]' => $file,
73 'upload_import_file[mark_as_read]' => 1,
76 $client->submit($form, $data);
78 $this->assertEquals(302, $client->getResponse()->getStatusCode());
80 $crawler = $client->followRedirect();
82 $content1 = $client->getContainer()
83 ->get('doctrine.orm.entity_manager')
84 ->getRepository('WallabagCoreBundle:Entry')
86 'http://gilbert.pellegrom.me/recreating-the-square-slider',
87 $this->getLoggedInUserId()
90 $this->assertTrue($content1->isArchived());
92 $content2 = $client->getContainer()
93 ->get('doctrine.orm.entity_manager')
94 ->getRepository('WallabagCoreBundle:Entry')
96 'https://www.wallabag.org/features/',
97 $this->getLoggedInUserId()
100 $this->assertTrue($content2->isArchived());
102 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
103 $this->assertContains('flashes.import.notice.summary', $body[0]);
106 public function testImportWallabagWithEmptyFile()
108 $this->logInAs('admin');
109 $client = $this->getClient();
111 $crawler = $client->request('GET', '/import/wallabag-v1');
112 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
114 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
117 'upload_import_file[file]' => $file,
120 $client->submit($form, $data);
122 $this->assertEquals(302, $client->getResponse()->getStatusCode());
124 $crawler = $client->followRedirect();
126 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
127 $this->assertContains('flashes.import.notice.failed', $body[0]);