aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-06-09 13:51:26 +0200
committerGitHub <noreply@github.com>2017-06-09 13:51:26 +0200
commita8993999893fb665b5e96597f9b649a2a8b940a2 (patch)
tree0c99b2f80a1279b17f44f2b9927f09e40a2001a2 /tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
parent5c762616c378d20b96eda0f0727eb4c760d4119d (diff)
parent1f7018e1fe369b326150c388b56b8b8c26017234 (diff)
downloadwallabag-a8993999893fb665b5e96597f9b649a2a8b940a2.tar.gz
wallabag-a8993999893fb665b5e96597f9b649a2a8b940a2.tar.zst
wallabag-a8993999893fb665b5e96597f9b649a2a8b940a2.zip
Merge pull request #3192 from wallabag/validate-content-fields
Validate language & preview picture fields
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php95
1 files changed, 81 insertions, 14 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index cc7b3672..3babbaca 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -158,6 +158,7 @@ class EntryControllerTest extends WallabagCoreTestCase
158 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); 158 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
159 $this->assertEquals($this->url, $content->getUrl()); 159 $this->assertEquals($this->url, $content->getUrl());
160 $this->assertContains('Google', $content->getTitle()); 160 $this->assertContains('Google', $content->getTitle());
161 $this->assertEquals('fr', $content->getLanguage());
161 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); 162 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
162 $this->assertEquals('Morgane Tual', $author[0]); 163 $this->assertEquals('Morgane Tual', $author[0]);
163 $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); 164 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
@@ -190,6 +191,7 @@ class EntryControllerTest extends WallabagCoreTestCase
190 191
191 $authors = $content->getPublishedBy(); 192 $authors = $content->getPublishedBy();
192 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); 193 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
194 $this->assertEquals('fr', $content->getLanguage());
193 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); 195 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
194 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); 196 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
195 } 197 }
@@ -254,15 +256,6 @@ class EntryControllerTest extends WallabagCoreTestCase
254 256
255 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 257 $this->assertEquals(302, $client->getResponse()->getStatusCode());
256 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 258 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
257
258 $em = $client->getContainer()
259 ->get('doctrine.orm.entity_manager');
260 $entry = $em
261 ->getRepository('WallabagCoreBundle:Entry')
262 ->findOneByUrl(urldecode($url));
263
264 $em->remove($entry);
265 $em->flush();
266 } 259 }
267 260
268 /** 261 /**
@@ -297,6 +290,7 @@ class EntryControllerTest extends WallabagCoreTestCase
297 290
298 $this->assertCount(2, $tags); 291 $this->assertCount(2, $tags);
299 $this->assertContains('wallabag', $tags); 292 $this->assertContains('wallabag', $tags);
293 $this->assertEquals('en', $entry->getLanguage());
300 294
301 $em->remove($entry); 295 $em->remove($entry);
302 $em->flush(); 296 $em->flush();
@@ -392,8 +386,6 @@ class EntryControllerTest extends WallabagCoreTestCase
392 } 386 }
393 387
394 /** 388 /**
395 * @depends testPostNewOk
396 *
397 * This test will require an internet connection. 389 * This test will require an internet connection.
398 */ 390 */
399 public function testReload() 391 public function testReload()
@@ -420,9 +412,6 @@ class EntryControllerTest extends WallabagCoreTestCase
420 $this->assertNotEmpty($entry->getContent()); 412 $this->assertNotEmpty($entry->getContent());
421 } 413 }
422 414
423 /**
424 * @depends testPostNewOk
425 */
426 public function testReloadWithFetchingFailed() 415 public function testReloadWithFetchingFailed()
427 { 416 {
428 $this->logInAs('admin'); 417 $this->logInAs('admin');
@@ -1254,4 +1243,82 @@ class EntryControllerTest extends WallabagCoreTestCase
1254 1243
1255 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1244 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1256 } 1245 }
1246
1247 public function dataForLanguage()
1248 {
1249 return [
1250 'ru' => [
1251 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1252 'ru',
1253 ],
1254 'fr-FR' => [
1255 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1256 'fr_FR',
1257 ],
1258 'de' => [
1259 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1260 'de',
1261 ],
1262 'it' => [
1263 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1264 'it',
1265 ],
1266 'zh_CN' => [
1267 'http://www.hao123.com/shequ?__noscript__-=1',
1268 'zh_CN',
1269 ],
1270 'de_AT' => [
1271 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1272 'de_AT',
1273 ],
1274 'ru_RU' => [
1275 'http://netler.ru/ikt/windows-error-reporting.htm',
1276 'ru_RU',
1277 ],
1278 'pt_BR' => [
1279 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1280 'pt_BR',
1281 ],
1282 'fucked_list_of_languages' => [
1283 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1284 '',
1285 ],
1286 'es-ES' => [
1287 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google',
1288 'es_ES',
1289 ],
1290 ];
1291 }
1292
1293 /**
1294 * @dataProvider dataForLanguage
1295 */
1296 public function testLanguageValidation($url, $expectedLanguage)
1297 {
1298 $this->logInAs('admin');
1299 $client = $this->getClient();
1300
1301 $crawler = $client->request('GET', '/new');
1302
1303 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1304
1305 $form = $crawler->filter('form[name=entry]')->form();
1306
1307 $data = [
1308 'entry[url]' => $url,
1309 ];
1310
1311 $client->submit($form, $data);
1312
1313 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1314
1315 $content = $client->getContainer()
1316 ->get('doctrine.orm.entity_manager')
1317 ->getRepository('WallabagCoreBundle:Entry')
1318 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1319
1320 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1321 $this->assertEquals($url, $content->getUrl());
1322 $this->assertEquals($expectedLanguage, $content->getLanguage());
1323 }
1257} 1324}