3 namespace Tests\Wallabag\ImportBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Symfony\Component\HttpFoundation\File\UploadedFile
;
8 class BrowserControllerTest
extends WallabagCoreTestCase
10 public function testImportWallabag()
12 $this->logInAs('admin');
13 $client = $this->getClient();
15 $crawler = $client->request('GET', '/import/browser');
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 testImportWallabagWithFirefoxFile()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $crawler = $client->request('GET', '/import/browser');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
30 $file = new UploadedFile(__DIR__
.'/../fixtures/firefox-bookmarks.json', 'Bookmarks');
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(['_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://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html',
50 $this->getLoggedInUserId()
53 $this->assertNotEmpty($content->getMimetype());
54 $this->assertNotEmpty($content->getPreviewPicture());
55 $this->assertNotEmpty($content->getLanguage());
56 $this->assertEquals(0, count($content->getTags()));
58 $content = $client->getContainer()
59 ->get('doctrine.orm.entity_manager')
60 ->getRepository('WallabagCoreBundle:Entry')
62 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java',
63 $this->getLoggedInUserId()
66 $this->assertNotEmpty($content->getMimetype());
67 $this->assertNotEmpty($content->getPreviewPicture());
68 $this->assertEmpty($content->getLanguage());
71 public function testImportWallabagWithChromeFile()
73 $this->logInAs('admin');
74 $client = $this->getClient();
76 $crawler = $client->request('GET', '/import/browser');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
79 $file = new UploadedFile(__DIR__
.'/../fixtures/chrome-bookmarks', 'Bookmarks');
82 'upload_import_file[file]' => $file,
85 $client->submit($form, $data);
87 $this->assertEquals(302, $client->getResponse()->getStatusCode());
89 $crawler = $client->followRedirect();
91 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
92 $this->assertContains('flashes.import.notice.summary', $body[0]);
94 $content = $client->getContainer()
95 ->get('doctrine.orm.entity_manager')
96 ->getRepository('WallabagCoreBundle:Entry')
98 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730',
99 $this->getLoggedInUserId()
102 $this->assertNotEmpty($content->getMimetype());
103 $this->assertNotEmpty($content->getPreviewPicture());
104 $this->assertNotEmpty($content->getLanguage());
105 $this->assertEquals(0, count($content->getTags()));
108 public function testImportWallabagWithEmptyFile()
110 $this->logInAs('admin');
111 $client = $this->getClient();
113 $crawler = $client->request('GET', '/import/browser');
114 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
116 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
119 'upload_import_file[file]' => $file,
122 $client->submit($form, $data);
124 $this->assertEquals(302, $client->getResponse()->getStatusCode());
126 $crawler = $client->followRedirect();
128 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
129 $this->assertContains('flashes.import.notice.failed', $body[0]);