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('import_with_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('import_with_rabbitmq', 0);
38 public function testImportWallabagWithRedisEnabled()
40 $this->logInAs('admin');
41 $client = $this->getClient();
43 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
45 $crawler = $client->request('GET', '/import/wallabag-v1');
47 $this->assertEquals(200, $client->getResponse()->getStatusCode());
48 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
49 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
51 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
54 public function testImportWallabagWithFile()
56 $this->logInAs('admin');
57 $client = $this->getClient();
59 $crawler = $client->request('GET', '/import/wallabag-v1');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
62 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json');
65 'upload_import_file[file]' => $file,
68 $client->submit($form, $data);
70 $this->assertEquals(302, $client->getResponse()->getStatusCode());
72 $crawler = $client->followRedirect();
74 $content = $client->getContainer()
75 ->get('doctrine.orm.entity_manager')
76 ->getRepository('WallabagCoreBundle:Entry')
78 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur',
79 $this->getLoggedInUserId()
82 $tag = $client->getContainer()
83 ->get('doctrine.orm.entity_manager')
84 ->getRepository('WallabagCoreBundle:Tag')
85 ->findOneByLabel('Framabag');
87 $this->assertTrue($content->getTags()->contains($tag));
89 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
90 $this->assertContains('flashes.import.notice.summary', $body[0]);
92 $this->assertEmpty($content->getMimetype());
93 $this->assertEmpty($content->getPreviewPicture());
94 $this->assertEmpty($content->getLanguage());
95 $this->assertEquals(1, count($content->getTags()));
96 $this->assertInstanceOf(\DateTime
::class, $content->getCreatedAt());
99 public function testImportWallabagWithFileAndMarkAllAsRead()
101 $this->logInAs('admin');
102 $client = $this->getClient();
104 $crawler = $client->request('GET', '/import/wallabag-v1');
105 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
107 $file = new UploadedFile(__DIR__
.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json');
110 'upload_import_file[file]' => $file,
111 'upload_import_file[mark_as_read]' => 1,
114 $client->submit($form, $data);
116 $this->assertEquals(302, $client->getResponse()->getStatusCode());
118 $crawler = $client->followRedirect();
120 $content1 = $client->getContainer()
121 ->get('doctrine.orm.entity_manager')
122 ->getRepository('WallabagCoreBundle:Entry')
123 ->findByUrlAndUserId(
124 'http://gilbert.pellegrom.me/recreating-the-square-slider',
125 $this->getLoggedInUserId()
128 $this->assertTrue($content1->isArchived());
130 $content2 = $client->getContainer()
131 ->get('doctrine.orm.entity_manager')
132 ->getRepository('WallabagCoreBundle:Entry')
133 ->findByUrlAndUserId(
134 'https://www.wallabag.org/features/',
135 $this->getLoggedInUserId()
138 $this->assertTrue($content2->isArchived());
140 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
141 $this->assertContains('flashes.import.notice.summary', $body[0]);
144 public function testImportWallabagWithEmptyFile()
146 $this->logInAs('admin');
147 $client = $this->getClient();
149 $crawler = $client->request('GET', '/import/wallabag-v1');
150 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
152 $file = new UploadedFile(__DIR__
.'/../fixtures/test.txt', 'test.txt');
155 'upload_import_file[file]' => $file,
158 $client->submit($form, $data);
160 $this->assertEquals(302, $client->getResponse()->getStatusCode());
162 $crawler = $client->followRedirect();
164 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
165 $this->assertContains('flashes.import.notice.failed', $body[0]);