+
+ // test url search on list of all articles
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://domain/qux');
+ $entry->setTitle('Le manège');
+ $entry->setArchived(true);
+ $this->getEntityManager()->persist($entry);
+ $this->getEntityManager()->flush();
+
+ $crawler = $client->request('GET', '/all/list');
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+
+ // same as previous test but for case-sensitivity
+ $crawler = $client->request('GET', '/all/list');
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+ }
+
+ 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());