+
+ public function dataForLanguage()
+ {
+ return [
+ 'ru' => [
+ 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
+ 'ru',
+ ],
+ 'fr-FR' => [
+ 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
+ 'fr_FR',
+ ],
+ 'de' => [
+ 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
+ 'de',
+ ],
+ 'it' => [
+ 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
+ 'it',
+ ],
+ 'zh_CN' => [
+ 'http://www.hao123.com/shequ?__noscript__-=1',
+ 'zh_CN',
+ ],
+ 'de_AT' => [
+ 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
+ 'de_AT',
+ ],
+ 'ru_RU' => [
+ 'http://netler.ru/ikt/windows-error-reporting.htm',
+ 'ru_RU',
+ ],
+ 'pt_BR' => [
+ 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
+ 'pt_BR',
+ ],
+ 'fucked_list_of_languages' => [
+ 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
+ '',
+ ],
+ 'es-ES' => [
+ 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google',
+ 'es_ES',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataForLanguage
+ */
+ public function testLanguageValidation($url, $expectedLanguage)
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $crawler = $client->request('GET', '/new');
+
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+ $form = $crawler->filter('form[name=entry]')->form();
+
+ $data = [
+ 'entry[url]' => $url,
+ ];
+
+ $client->submit($form, $data);
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ $content = $client->getContainer()
+ ->get('doctrine.orm.entity_manager')
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+ $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
+ $this->assertEquals($url, $content->getUrl());
+ $this->assertEquals($expectedLanguage, $content->getLanguage());
+ }
+
+ /**
+ * This test will require an internet connection.
+ */
+ public function testRestrictedArticle()
+ {
+ $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475';
+ $this->logInAs('admin');
+ $client = $this->getClient();
+ $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+
+ // enable restricted access
+ $client->getContainer()->get('craue_config')->set('restricted_access', 1);
+
+ // create a new site_credential
+ $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
+ $credential = new SiteCredential($user);
+ $credential->setHost('monde-diplomatique.fr');
+ $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
+ $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
+
+ $em->persist($credential);
+ $em->flush();
+
+ $crawler = $client->request('GET', '/new');
+
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+ $form = $crawler->filter('form[name=entry]')->form();
+
+ $data = [
+ 'entry[url]' => $url,
+ ];
+
+ $client->submit($form, $data);
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ $crawler = $client->followRedirect();
+
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+ $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
+
+ $content = $em
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+ $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
+ $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
+
+ $client->getContainer()->get('craue_config')->set('restricted_access', 0);
+ }