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 testImportWallabagWithRabbitEnabled()
24 $this->logInAs('admin');
25 $client = $this->getClient();
27 $client->getContainer()->get('craue_config')->set('rabbitmq', 1);
29 $crawler = $client->request('GET', '/import/wallabag-v1');
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
35 $client->getContainer()->get('craue_config')->set('rabbitmq', 0);
38 public function testImportWallabagWithFile()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $crawler = $client->request('GET', '/import/wallabag-v1');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
46 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
49 'upload_import_file[file]' => $file,
52 $client->submit($form, $data);
54 $this->assertEquals(302, $client->getResponse()->getStatusCode());
56 $crawler = $client->followRedirect();
58 $content = $client->getContainer()
59 ->get('doctrine.orm.entity_manager')
60 ->getRepository('WallabagCoreBundle:Entry')
62 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
63 $this->getLoggedInUserId()
66 $tag = $client->getContainer()
67 ->get('doctrine.orm.entity_manager')
68 ->getRepository('WallabagCoreBundle:Tag')
69 ->findOneByLabel('Framabag');
71 $this->assertTrue($content->getTags()->contains($tag));
73 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
74 $this->assertContains('flashes.import.notice.summary', $body[0]);
76 $this->assertEmpty($content->getMimetype());
77 $this->assertEmpty($content->getPreviewPicture());
78 $this->assertEmpty($content->getLanguage());
79 $this->assertEquals(1, count($content->getTags()));
80 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
83 public function testImportWallabagWithFileAndMarkAllAsRead()
85 $this->logInAs('admin');
86 $client = $this->getClient();
88 $crawler = $client->request('GET', '/import/wallabag-v1');
89 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
91 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
94 'upload_import_file[file]' => $file,
95 'upload_import_file[mark_as_read]' => 1,
98 $client->submit($form, $data);
100 $this->assertEquals(302, $client->getResponse()->getStatusCode());
102 $crawler = $client->followRedirect();
104 $content1 = $client->getContainer()
105 ->get('doctrine.orm.entity_manager')
106 ->getRepository('WallabagCoreBundle:Entry')
107 ->findByUrlAndUserId(
108 'http://gilbert.pellegrom.me/recreating-the-square-slider',
109 $this->getLoggedInUserId()
112 $this->assertTrue($content1->isArchived());
114 $content2 = $client->getContainer()
115 ->get('doctrine.orm.entity_manager')
116 ->getRepository('WallabagCoreBundle:Entry')
117 ->findByUrlAndUserId(
118 'https://www.wallabag.org/features/',
119 $this->getLoggedInUserId()
122 $this->assertTrue($content2->isArchived());
124 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
125 $this->assertContains('flashes.import.notice.summary', $body[0]);
128 public function testImportWallabagWithEmptyFile()
130 $this->logInAs('admin');
131 $client = $this->getClient();
133 $crawler = $client->request('GET', '/import/wallabag-v1');
134 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
136 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
139 'upload_import_file[file]' => $file,
142 $client->submit($form, $data);
144 $this->assertEquals(302, $client->getResponse()->getStatusCode());
146 $crawler = $client->followRedirect();
148 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
149 $this->assertContains('flashes.import.notice.failed', $body[0]);