X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FCoreBundle%2FController%2FEntryControllerTest.php;h=952e895741d84350e4cdcd8245169d396ba79683;hb=5ae8788583a63973c89a5a83f1a6880ce04b49d7;hp=4ab06dbfffb0700b3b17bccba0d2937952fb918f;hpb=e0597476d1d5f6a4a7d6ea9b76966465f3d22fb8;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 4ab06dbf..952e8957 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; class EntryControllerTest extends WallabagCoreTestCase @@ -896,4 +897,192 @@ class EntryControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } + + public function testRedirectToHomepage() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->find($this->getLoggedInUserId()); + + if (!$user) { + $this->markTestSkipped('No user found in db.'); + } + + // Redirect to homepage + $config = $user->getConfig(); + $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + $em->persist($config); + $em->flush(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/archive/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals('/', $client->getResponse()->headers->get('location')); + } + + public function testRedirectToCurrentPage() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->find($this->getLoggedInUserId()); + + if (!$user) { + $this->markTestSkipped('No user found in db.'); + } + + // Redirect to current page + $config = $user->getConfig(); + $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); + $em->persist($config); + $em->flush(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/archive/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); + } + + public function testFilterOnHttpStatus() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/new'); + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', + ]; + + $client->submit($form, $data); + + $crawler = $client->request('GET', '/all/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[httpStatus]' => 404, + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(1, $crawler->filter('div[class=entry]')); + + $crawler = $client->request('GET', '/new'); + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', + ]; + + $client->submit($form, $data); + + $crawler = $client->request('GET', '/all/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[httpStatus]' => 200, + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(1, $crawler->filter('div[class=entry]')); + + $crawler = $client->request('GET', '/all/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[httpStatus]' => 1024, + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(7, $crawler->filter('div[class=entry]')); + } + + public function testSearch() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // Search on unread list + $crawler = $client->request('GET', '/unread/list'); + + $form = $crawler->filter('form[name=search]')->form(); + $data = [ + 'search_entry[term]' => 'title', + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(5, $crawler->filter('div[class=entry]')); + + // Search on starred list + $crawler = $client->request('GET', '/starred/list'); + + $form = $crawler->filter('form[name=search]')->form(); + $data = [ + 'search_entry[term]' => 'title', + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(1, $crawler->filter('div[class=entry]')); + + // Added new article to test on archive list + $crawler = $client->request('GET', '/new'); + $form = $crawler->filter('form[name=entry]')->form(); + $data = [ + 'entry[url]' => $this->url, + ]; + $client->submit($form, $data); + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $client->request('GET', '/archive/'.$content->getId()); + + $crawler = $client->request('GET', '/archive/list'); + + $form = $crawler->filter('form[name=search]')->form(); + $data = [ + 'search_entry[term]' => 'manège', + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(1, $crawler->filter('div[class=entry]')); + $client->request('GET', '/delete/'.$content->getId()); + + // test on list of all articles + $crawler = $client->request('GET', '/all/list'); + + $form = $crawler->filter('form[name=search]')->form(); + $data = [ + 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } }