X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FTests%2FController%2FEntryControllerTest.php;h=3a77518245e068bbb985ff6cba5adbb20a2a2107;hb=1930c19d8214c05ceefac5ac011a6b6e7e4a983d;hp=e9c85a17225fffedadc3bab17e79c562ba347c17;hpb=02d17813a11d27e0232c38d1adf037cefdb176c1;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index e9c85a17..3a775182 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -3,7 +3,7 @@ namespace Wallabag\CoreBundle\Tests\Controller; use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; -use Doctrine\ORM\AbstractQuery; +use Wallabag\CoreBundle\Entity\Entry; class EntryControllerTest extends WallabagCoreTestCase { @@ -19,6 +19,36 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('login', $client->getResponse()->headers->get('location')); } + public function testQuickstart() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $client->request('GET', '/unread/list'); + $client->followRedirect(); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains('We\'ll accompany you to visit wallabag', $client->getResponse()->getContent()); + + // Test if quickstart is disabled when user has 1 entry + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = array( + 'entry[url]' => 'https://www.wallabag.org/blog/2016/01/08/wallabag-alpha1-v2', + ); + + $client->submit($form, $data); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $client->followRedirect(); + + $client->request('GET', '/unread/list'); + $this->assertContains('There is one entry.', $client->getResponse()->getContent()); + } + public function testGetNew() { $this->logInAs('admin'); @@ -32,6 +62,31 @@ class EntryControllerTest extends WallabagCoreTestCase $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 + $client->request('GET', '/bookmarklet', array('url' => $this->url)); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $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'); @@ -50,6 +105,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals('This value should not be blank.', $alert[0]); } + /** + * This test will require an internet connection. + */ public function testPostNewOk() { $this->logInAs('admin'); @@ -75,6 +133,44 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('Google', $alert[0]); } + /** + * This test will require an internet connection. + */ + public function testPostNewThatWillBeTaggued() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = array( + 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', + ); + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $client->followRedirect(); + + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($url); + $tags = $entry->getTags(); + + $this->assertCount(1, $tags); + $this->assertEquals('wallabag', $tags[0]->getLabel()); + + $em->remove($entry); + $em->flush(); + } + public function testArchive() { $this->logInAs('admin'); @@ -95,6 +191,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); } + /** + * @depends testPostNewOk + */ public function testView() { $this->logInAs('admin'); @@ -111,6 +210,38 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); } + /** + * @depends testPostNewOk + * + * This test will require an internet connection. + */ + public function testReload() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($this->url); + + // empty content + $content->setContent(''); + $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); + $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); + + $client->request('GET', '/reload/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl($this->url); + + $this->assertNotEmpty($content->getContent()); + } + public function testEdit() { $this->logInAs('admin'); @@ -222,6 +353,51 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } + /** + * It will create a new entry. + * Browse to it. + * Then remove it. + * + * And it'll check that user won't be redirected to the view page of the content when it had been removed + */ + public function testViewAndDelete() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // add a new content to be removed later + $user = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagUserBundle:User') + ->findOneByUserName('admin'); + + $content = new Entry($user); + $content->setUrl('http://1.1.1.1/entry'); + $content->setReadingTime(12); + $content->setDomainName('domain.io'); + $content->setMimetype('text/html'); + $content->setTitle('test title entry'); + $content->setContent('This is my content /o/'); + $content->setArchived(true); + $content->setLanguage('fr'); + + $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->persist($content); + $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->flush(); + + $client->request('GET', '/view/'.$content->getId()); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $client->request('GET', '/delete/'.$content->getId()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $client->followRedirect(); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testViewOtherUserEntry() { $this->logInAs('admin'); @@ -309,7 +485,7 @@ class EntryControllerTest extends WallabagCoreTestCase $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; - $crawler = $client->request('GET', 'unread/list'.$parameters); + $client->request('GET', 'unread/list'.$parameters); $this->assertContains($parameters, $client->getResponse()->getContent());