X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FTests%2FController%2FEntryControllerTest.php;h=5ac39d1212276a210ba3b6471d6ee815aa41ff26;hb=0d6a7929e17c84052cbb3e494d5e5c195c24ca04;hp=99a3a94520e82f73868325cc586de9c4b52379ed;hpb=1d14779154481b320e1c44fccf2558d8c9fa43a1;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 99a3a945..5ac39d12 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -2,11 +2,12 @@ namespace Wallabag\CoreBundle\Tests\Controller; -use Wallabag\CoreBundle\Tests\WallabagTestCase; -use Doctrine\ORM\AbstractQuery; +use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -class EntryControllerTest extends WallabagTestCase +class EntryControllerTest extends WallabagCoreTestCase { + 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'; + public function testLogin() { $client = $this->getClient(); @@ -30,6 +31,31 @@ class EntryControllerTest extends WallabagTestCase $this->assertCount(1, $crawler->filter('button[type=submit]')); } + public function testPostNewViaBookmarklet() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/'); + + $this->assertCount(4, $crawler->filter('div[class=entry]')); + + // Good URL + $crawler = $client->request('GET', '/bookmarklet', array('url' => $this->url)); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $crawler = $client->followRedirect(); + $crawler = $client->request('GET', '/'); + $this->assertCount(5, $crawler->filter('div[class=entry]')); + + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($this->url); + $em->remove($entry); + $em->flush(); + } + public function testPostNewEmpty() { $this->logInAs('admin'); @@ -60,7 +86,7 @@ class EntryControllerTest extends WallabagTestCase $form = $crawler->filter('button[type=submit]')->form(); $data = array( - 'entry[url]' => 'https://www.mailjet.com/blog/mailjet-zapier-integrations-made-easy/', + 'entry[url]' => $this->url, ); $client->submit($form, $data); @@ -70,7 +96,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); - $this->assertContains('Mailjet', $alert[0]); + $this->assertContains('Google', $alert[0]); } public function testArchive() @@ -78,7 +104,7 @@ class EntryControllerTest extends WallabagTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->request('GET', '/archive'); + $client->request('GET', '/archive/list'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); } @@ -88,7 +114,7 @@ class EntryControllerTest extends WallabagTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->request('GET', '/starred'); + $client->request('GET', '/starred/list'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); } @@ -101,7 +127,7 @@ class EntryControllerTest extends WallabagTestCase $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); + ->findOneByUrl($this->url); $client->request('GET', '/view/'.$content->getId()); @@ -109,6 +135,54 @@ class EntryControllerTest extends WallabagTestCase $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); } + public function testEdit() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($this->url); + + $crawler = $client->request('GET', '/edit/'.$content->getId()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $this->assertCount(1, $crawler->filter('input[id=entry_title]')); + $this->assertCount(1, $crawler->filter('button[id=entry_save]')); + } + + public function testEditUpdate() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($this->url); + + $crawler = $client->request('GET', '/edit/'.$content->getId()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = array( + 'entry[title]' => 'My updated title hehe :)', + ); + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); + $this->assertContains('My updated title hehe :)', $alert[0]); + } + public function testToggleArchive() { $this->logInAs('admin'); @@ -117,7 +191,7 @@ class EntryControllerTest extends WallabagTestCase $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsArchived(false); + ->findOneByUrl($this->url); $client->request('GET', '/archive/'.$content->getId()); @@ -126,7 +200,7 @@ class EntryControllerTest extends WallabagTestCase $res = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneById($content->getId()); + ->find($content->getId()); $this->assertEquals($res->isArchived(), true); } @@ -139,7 +213,7 @@ class EntryControllerTest extends WallabagTestCase $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByIsStarred(false); + ->findOneByUrl($this->url); $client->request('GET', '/star/'.$content->getId()); @@ -161,7 +235,7 @@ class EntryControllerTest extends WallabagTestCase $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneById(1); + ->findOneByUrl($this->url); $client->request('GET', '/delete/'.$content->getId()); @@ -174,22 +248,181 @@ class EntryControllerTest extends WallabagTestCase public function testViewOtherUserEntry() { - $this->logInAs('bob'); + $this->logInAs('admin'); $client = $this->getClient(); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->createQueryBuilder('e') - ->select('e.id') - ->leftJoin('e.user', 'u') - ->where('u.username != :username')->setParameter('username', 'bob') - ->setMaxResults(1) - ->getQuery() - ->getSingleResult(AbstractQuery::HYDRATE_ARRAY); + ->findOneByUsernameAndNotArchived('bob'); - $client->request('GET', '/view/'.$content['id']); + $client->request('GET', '/view/'.$content->getId()); $this->assertEquals(403, $client->getResponse()->getStatusCode()); } + + public function testFilterOnReadingTime() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = array( + 'entry_filter[readingTime][right_number]' => 11, + 'entry_filter[readingTime][left_number]' => 11, + ); + + $crawler = $client->submit($form, $data); + + $this->assertCount(1, $crawler->filter('div[class=entry]')); + } + + public function testFilterOnCreationDate() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = array( + 'entry_filter[createdAt][left_date]' => date('d/m/Y'), + 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), + ); + + $crawler = $client->submit($form, $data); + + $this->assertCount(5, $crawler->filter('div[class=entry]')); + + $data = array( + 'entry_filter[createdAt][left_date]' => date('d/m/Y'), + 'entry_filter[createdAt][right_date]' => date('d/m/Y'), + ); + + $crawler = $client->submit($form, $data); + + $this->assertCount(5, $crawler->filter('div[class=entry]')); + + $data = array( + 'entry_filter[createdAt][left_date]' => '01/01/1970', + 'entry_filter[createdAt][right_date]' => '01/01/1970', + ); + + $crawler = $client->submit($form, $data); + + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } + + public function testPaginationWithFilter() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $crawler = $client->request('GET', '/config'); + + $form = $crawler->filter('button[id=config_save]')->form(); + + $data = array( + 'config[items_per_page]' => '1', + ); + + $client->submit($form, $data); + + $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; + + $crawler = $client->request('GET', 'unread/list'.$parameters); + + $this->assertContains($parameters, $client->getResponse()->getContent()); + + // reset pagination + $crawler = $client->request('GET', '/config'); + $form = $crawler->filter('button[id=config_save]')->form(); + $data = array( + 'config[items_per_page]' => '12', + ); + $client->submit($form, $data); + } + + public function testFilterOnDomainName() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $data = array( + 'entry_filter[domainName]' => 'domain', + ); + + $crawler = $client->submit($form, $data); + $this->assertCount(5, $crawler->filter('div[class=entry]')); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + $data = array( + 'entry_filter[domainName]' => 'wallabag', + ); + + $crawler = $client->submit($form, $data); + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } + + public function testFilterOnStatus() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $form['entry_filter[isArchived]']->tick(); + $form['entry_filter[isStarred]']->untick(); + + $crawler = $client->submit($form); + $this->assertCount(1, $crawler->filter('div[class=entry]')); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + $form['entry_filter[isArchived]']->untick(); + $form['entry_filter[isStarred]']->tick(); + + $crawler = $client->submit($form); + $this->assertCount(1, $crawler->filter('div[class=entry]')); + } + + public function testPreviewPictureFilter() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $form['entry_filter[previewPicture]']->tick(); + + $crawler = $client->submit($form); + $this->assertCount(1, $crawler->filter('div[class=entry]')); + } + + public function testFilterOnLanguage() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $data = array( + 'entry_filter[language]' => 'fr', + ); + + $crawler = $client->submit($form, $data); + $this->assertCount(2, $crawler->filter('div[class=entry]')); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + $data = array( + 'entry_filter[language]' => 'en', + ); + + $crawler = $client->submit($form, $data); + $this->assertCount(2, $crawler->filter('div[class=entry]')); + } }