]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\ImportBundle\Tests\Controller; | |
4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | |
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | |
7 | ||
8 | class WallabagV1ControllerTest extends WallabagCoreTestCase | |
9 | { | |
10 | public function testImportWallabag() | |
11 | { | |
12 | $this->logInAs('admin'); | |
13 | $client = $this->getClient(); | |
14 | ||
15 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
16 | ||
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()); | |
20 | } | |
21 | ||
22 | public function testImportWallabagWithFile() | |
23 | { | |
24 | $this->logInAs('admin'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
28 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
29 | ||
30 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json'); | |
31 | ||
32 | $data = array( | |
33 | 'upload_import_file[file]' => $file, | |
34 | ); | |
35 | ||
36 | $client->submit($form, $data); | |
37 | ||
38 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
39 | ||
40 | $crawler = $client->followRedirect(); | |
41 | ||
42 | $content = $client->getContainer() | |
43 | ->get('doctrine.orm.entity_manager') | |
44 | ->getRepository('WallabagCoreBundle:Entry') | |
45 | ->findByUrlAndUserId( | |
46 | 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur', | |
47 | $this->getLoggedInUserId() | |
48 | ); | |
49 | ||
50 | $tag = $client->getContainer() | |
51 | ->get('doctrine.orm.entity_manager') | |
52 | ->getRepository('WallabagCoreBundle:Tag') | |
53 | ->findOneByLabel('Framabag'); | |
54 | ||
55 | $this->assertTrue($content->getTags()->contains($tag)); | |
56 | ||
57 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); | |
58 | $this->assertContains('Import summary', $alert[0]); | |
59 | } | |
60 | ||
61 | public function testImportWallabagWithFileAndMarkAllAsRead() | |
62 | { | |
63 | $this->logInAs('admin'); | |
64 | $client = $this->getClient(); | |
65 | ||
66 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
67 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
68 | ||
69 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1-read.json', 'wallabag-v1-read.json'); | |
70 | ||
71 | $data = array( | |
72 | 'upload_import_file[file]' => $file, | |
73 | 'upload_import_file[mark_as_read]' => 1, | |
74 | ); | |
75 | ||
76 | $client->submit($form, $data); | |
77 | ||
78 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
79 | ||
80 | $crawler = $client->followRedirect(); | |
81 | ||
82 | $content1 = $client->getContainer() | |
83 | ->get('doctrine.orm.entity_manager') | |
84 | ->getRepository('WallabagCoreBundle:Entry') | |
85 | ->findByUrlAndUserId( | |
86 | 'http://gilbert.pellegrom.me/recreating-the-square-slider', | |
87 | $this->getLoggedInUserId() | |
88 | ); | |
89 | ||
90 | $this->assertTrue($content1->isArchived()); | |
91 | ||
92 | $content2 = $client->getContainer() | |
93 | ->get('doctrine.orm.entity_manager') | |
94 | ->getRepository('WallabagCoreBundle:Entry') | |
95 | ->findByUrlAndUserId( | |
96 | 'https://www.wallabag.org/features/', | |
97 | $this->getLoggedInUserId() | |
98 | ); | |
99 | ||
100 | $this->assertTrue($content2->isArchived()); | |
101 | ||
102 | $this->assertContains('Import summary', $client->getResponse()->getContent()); | |
103 | } | |
104 | ||
105 | public function testImportWallabagWithEmptyFile() | |
106 | { | |
107 | $this->logInAs('admin'); | |
108 | $client = $this->getClient(); | |
109 | ||
110 | $crawler = $client->request('GET', '/import/wallabag-v1'); | |
111 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
112 | ||
113 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | |
114 | ||
115 | $data = array( | |
116 | 'upload_import_file[file]' => $file, | |
117 | ); | |
118 | ||
119 | $client->submit($form, $data); | |
120 | ||
121 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
122 | ||
123 | $crawler = $client->followRedirect(); | |
124 | ||
125 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); | |
126 | $this->assertContains('Import failed, please try again', $alert[0]); | |
127 | } | |
128 | } |