]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Prepare 2.3.4 release
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / EntryControllerTest.php
index 12a74f4976a435a7a71796479c3aaf25912ce1dc..479e07000e642d1de582d3c67a51d666274bb718 100644 (file)
@@ -6,12 +6,14 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 use Wallabag\CoreBundle\Entity\Config;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\SiteCredential;
+use Wallabag\CoreBundle\Entity\Tag;
+use Wallabag\CoreBundle\Helper\ContentProxy;
 
 class EntryControllerTest extends WallabagCoreTestCase
 {
+    const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
     public $downloadImagesEnabled = false;
-    public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html';
-    const An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'http://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
+    public $url = 'https://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html';
 
     /**
      * @after
@@ -137,6 +139,8 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->logInAs('admin');
         $client = $this->getClient();
 
+        $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
+
         $crawler = $client->request('GET', '/new');
 
         $this->assertSame(200, $client->getResponse()->getStatusCode());
@@ -162,14 +166,14 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertSame($this->url, $content->getUrl());
         $this->assertContains('Google', $content->getTitle());
         $this->assertSame('fr', $content->getLanguage());
-        $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
-        $this->assertSame('Morgane Tual', $author[0]);
-        $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
+        $this->assertSame('2016-04-07 19:01:35', $content->getPublishedAt()->format('Y-m-d H:i:s'));
+        $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
+        $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
     }
 
     public function testPostWithMultipleAuthors()
     {
-        $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
+        $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
         $this->logInAs('admin');
         $client = $this->getClient();
 
@@ -192,6 +196,7 @@ class EntryControllerTest extends WallabagCoreTestCase
             ->getRepository('WallabagCoreBundle:Entry')
             ->findByUrlAndUserId($url, $this->getLoggedInUserId());
 
+        $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
         $authors = $content->getPublishedBy();
         $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
         $this->assertSame('fr', $content->getLanguage());
@@ -471,10 +476,11 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $this->assertSame(200, $client->getResponse()->getStatusCode());
 
-        $form = $crawler->filter('button[type=submit]')->form();
+        $form = $crawler->filter('button[id=entry_save]')->form();
 
         $data = [
             'entry[title]' => 'My updated title hehe :)',
+            'entry[origin_url]' => 'https://example.io',
         ];
 
         $client->submit($form, $data);
@@ -483,8 +489,43 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
-        $this->assertContains('My updated title hehe :)', $alert[0]);
+        $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
+        $this->assertContains('My updated title hehe :)', $title[0]);
+        $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
+        $this->assertContains('example.io', trim($stats[1]));
+    }
+
+    public function testEditRemoveOriginUrl()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $entry = new Entry($this->getLoggedInUser());
+        $entry->setUrl($this->url);
+        $this->getEntityManager()->persist($entry);
+        $this->getEntityManager()->flush();
+
+        $crawler = $client->request('GET', '/edit/' . $entry->getId());
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('button[id=entry_save]')->form();
+
+        $data = [
+            'entry[title]' => 'My updated title hehe :)',
+            'entry[origin_url]' => '',
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
+        $this->assertContains('My updated title hehe :)', $title[0]);
+        $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
+        $this->assertNotContains('example.io', trim($stats[0]));
     }
 
     public function testToggleArchive()
@@ -978,7 +1019,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->logInAs('admin');
         $client = $this->getClient();
 
-        $url = self::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
+        $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
         $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
 
         $crawler = $client->request('GET', '/new');
@@ -1020,7 +1061,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->logInAs('admin');
         $client = $this->getClient();
 
-        $url = self::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
+        $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
         $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
 
         $crawler = $client->request('GET', '/new');
@@ -1102,7 +1143,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $client = $this->getClient();
 
         $entry = new Entry($this->getLoggedInUser());
-        $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
+        $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
         $entry->setHttpStatus(404);
         $this->getEntityManager()->persist($entry);
 
@@ -1268,12 +1309,12 @@ class EntryControllerTest extends WallabagCoreTestCase
                 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
                 'ru',
             ],
-            'fr-FR' => [
-                'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
-                'fr_FR',
+            'fr' => [
+                'https://fr.wikipedia.org/wiki/Wallabag',
+                'fr',
             ],
             'de' => [
-                'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
+                'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
                 'de',
             ],
             'it' => [
@@ -1284,16 +1325,12 @@ class EntryControllerTest extends WallabagCoreTestCase
                 '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',
+            'ru' => [
+                'https://www.kp.ru/daily/26879.7/3921982/',
+                'ru',
             ],
             'pt_BR' => [
-                'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
+                'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
                 'pt_BR',
             ],
             'fucked_list_of_languages' => [
@@ -1301,8 +1338,8 @@ class EntryControllerTest extends WallabagCoreTestCase
                 null,
             ],
             'es-ES' => [
-                'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
-                'es_ES',
+                'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
+                'es',
             ],
         ];
     }
@@ -1390,4 +1427,71 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $client->getContainer()->get('craue_config')->set('restricted_access', 0);
     }
+
+    public function testPostEntryWhenFetchFails()
+    {
+        $url = 'http://example.com/papers/email_tracking.pdf';
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $container = $client->getContainer();
+        $contentProxy = $this->getMockBuilder(ContentProxy::class)
+            ->disableOriginalConstructor()
+            ->setMethods(['updateEntry'])
+            ->getMock();
+        $contentProxy->expects($this->any())
+            ->method('updateEntry')
+            ->willThrowException(new \Exception('Test Fetch content fails'));
+
+        $crawler = $client->request('GET', '/new');
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('form[name=entry]')->form();
+
+        $data = [
+            'entry[url]' => $url,
+        ];
+
+        /**
+         * We generate a new client to be able to use Mock ContentProxy
+         * Also we reinject the cookie from the previous client to keep the
+         * session.
+         */
+        $cookie = $client->getCookieJar()->all();
+        $client = $this->getNewClient();
+        $client->getCookieJar()->set($cookie[0]);
+        $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
+        $client->submit($form, $data);
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $content = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+        $authors = $content->getPublishedBy();
+        $this->assertSame('email_tracking.pdf', $content->getTitle());
+        $this->assertSame('example.com', $content->getDomainName());
+    }
+
+    public function testEntryDeleteTagLink()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $em = $client->getContainer()->get('doctrine.orm.entity_manager');
+        $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
+        $tag = $entry->getTags()[0];
+
+        $crawler = $client->request('GET', '/view/' . $entry->getId());
+
+        // As long as the deletion link of a tag is following
+        // a link to the tag view, we take the second one to retrieve
+        // the deletion link of the first tag
+        $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
+
+        $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
+    }
 }