]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Merge pull request #3133 from wallabag/testing-travis-failure
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / EntryControllerTest.php
index 06ed2db60e4ec6041b21510d8d29cd2e09a601b6..116e5f323bbfa330154fc8b42efb8e1abe59f23f 100644 (file)
@@ -8,8 +8,24 @@ use Wallabag\CoreBundle\Entity\Entry;
 
 class EntryControllerTest extends WallabagCoreTestCase
 {
+    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';
 
+    /**
+     * @after
+     *
+     * Ensure download_images_enabled is disabled after each script
+     */
+    public function tearDownImagesEnabled()
+    {
+        if ($this->downloadImagesEnabled) {
+            $client = static::createClient();
+            $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
+
+            $this->downloadImagesEnabled = false;
+        }
+    }
+
     public function testLogin()
     {
         $client = $this->getClient();
@@ -135,9 +151,45 @@ class EntryControllerTest extends WallabagCoreTestCase
             ->getRepository('WallabagCoreBundle:Entry')
             ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
 
+        $author = $content->getPublishedBy();
+
         $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
         $this->assertEquals($this->url, $content->getUrl());
         $this->assertContains('Google', $content->getTitle());
+        $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
+        $this->assertEquals('Morgane Tual', $author[0]);
+        $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
+    }
+
+    public function testPostWithMultipleAuthors()
+    {
+        $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
+        $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());
+
+        $authors = $content->getPublishedBy();
+        $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
+        $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
+        $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
     }
 
     public function testPostNewOkUrlExist()
@@ -235,7 +287,7 @@ class EntryControllerTest extends WallabagCoreTestCase
             ->findOneByUrl($url);
         $tags = $entry->getTags();
 
-        $this->assertCount(1, $tags);
+        $this->assertCount(2, $tags);
         $this->assertEquals('wallabag', $tags[0]->getLabel());
 
         $em->remove($entry);
@@ -264,8 +316,8 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $tags = $entry->getTags();
 
-        $this->assertCount(1, $tags);
-        $this->assertEquals('wallabag', $tags[0]->getLabel());
+        $this->assertCount(2, $tags);
+        $this->assertEquals('wallabag', $tags[1]->getLabel());
 
         $em->remove($entry);
         $em->flush();
@@ -591,6 +643,26 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertCount(1, $crawler->filter('div[class=entry]'));
     }
 
+    public function testFilterOnReadingTimeWithNegativeValue()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/unread/list');
+
+        $form = $crawler->filter('button[id=submit-filter]')->form();
+
+        $data = [
+            'entry_filter[readingTime][right_number]' => -22,
+            'entry_filter[readingTime][left_number]' => -22,
+        ];
+
+        $crawler = $client->submit($form, $data);
+
+        // forcing negative value results in no entry displayed
+        $this->assertCount(0, $crawler->filter('div[class=entry]'));
+    }
+
     public function testFilterOnReadingTimeOnlyUpper()
     {
         $this->logInAs('admin');
@@ -606,7 +678,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->submit($form, $data);
 
-        $this->assertCount(2, $crawler->filter('div[class=entry]'));
+        $this->assertCount(3, $crawler->filter('div[class=entry]'));
     }
 
     public function testFilterOnReadingTimeOnlyLower()
@@ -642,7 +714,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->submit($form, $data);
 
-        $this->assertCount(4, $crawler->filter('div[class=entry]'));
+        $this->assertCount(5, $crawler->filter('div[class=entry]'));
     }
 
     public function testFilterOnCreationDate()
@@ -661,7 +733,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->submit($form, $data);
 
-        $this->assertCount(5, $crawler->filter('div[class=entry]'));
+        $this->assertCount(6, $crawler->filter('div[class=entry]'));
 
         $data = [
             'entry_filter[createdAt][left_date]' => date('d/m/Y'),
@@ -670,7 +742,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->submit($form, $data);
 
-        $this->assertCount(5, $crawler->filter('div[class=entry]'));
+        $this->assertCount(6, $crawler->filter('div[class=entry]'));
 
         $data = [
             'entry_filter[createdAt][left_date]' => '01/01/1970',
@@ -774,7 +846,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         $form['entry_filter[previewPicture]']->tick();
 
         $crawler = $client->submit($form);
-        $this->assertCount(1, $crawler->filter('div[class=entry]'));
+        $this->assertCount(2, $crawler->filter('div[class=entry]'));
     }
 
     public function testFilterOnLanguage()
@@ -789,7 +861,7 @@ class EntryControllerTest extends WallabagCoreTestCase
         ];
 
         $crawler = $client->submit($form, $data);
-        $this->assertCount(2, $crawler->filter('div[class=entry]'));
+        $this->assertCount(3, $crawler->filter('div[class=entry]'));
 
         $form = $crawler->filter('button[id=submit-filter]')->form();
         $data = [
@@ -849,6 +921,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
     public function testNewEntryWithDownloadImagesEnabled()
     {
+        $this->downloadImagesEnabled = true;
         $this->logInAs('admin');
         $client = $this->getClient();
 
@@ -879,7 +952,8 @@ class EntryControllerTest extends WallabagCoreTestCase
         $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
         $this->assertEquals($url, $entry->getUrl());
         $this->assertContains('Perpignan', $entry->getTitle());
-        $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
+        // instead of checking for the filename (which might change) check that the image is now local
+        $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent());
 
         $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
     }
@@ -889,6 +963,7 @@ class EntryControllerTest extends WallabagCoreTestCase
      */
     public function testRemoveEntryWithDownloadImagesEnabled()
     {
+        $this->downloadImagesEnabled = true;
         $this->logInAs('admin');
         $client = $this->getClient();
 
@@ -1014,7 +1089,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->submit($form, $data);
 
-        $this->assertCount(1, $crawler->filter('div[class=entry]'));
+        $this->assertCount(2, $crawler->filter('div[class=entry]'));
 
         $crawler = $client->request('GET', '/all/list');
         $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1025,7 +1100,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->submit($form, $data);
 
-        $this->assertCount(7, $crawler->filter('div[class=entry]'));
+        $this->assertCount(8, $crawler->filter('div[class=entry]'));
     }
 
     public function testSearch()
@@ -1093,5 +1168,29 @@ class EntryControllerTest extends WallabagCoreTestCase
         $crawler = $client->submit($form, $data);
 
         $this->assertCount(0, $crawler->filter('div[class=entry]'));
+
+        // test url search on list of all articles
+        $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]'));
     }
 }