X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FCoreBundle%2FController%2FEntryControllerTest.php;h=104f60f175efb58db53e1f5a5bc287c1b15cf26f;hb=9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b;hp=8f5c372d83bc92356b2ab8e9daec60fb371a3640;hpb=fd7fde95159828960784a438c4b4da147e20ab18;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 8f5c372d..104f60f1 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\SiteCredential; class EntryControllerTest extends WallabagCoreTestCase { @@ -1321,4 +1322,56 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals($url, $content->getUrl()); $this->assertEquals($expectedLanguage, $content->getLanguage()); } + + /** + * This test will require an internet connection. + */ + public function testRestrictedArticle() + { + $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475'; + $this->logInAs('admin'); + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + + // enable restricted access + $client->getContainer()->get('craue_config')->set('restricted_access', 1); + + // create a new site_credential + $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); + $credential = new SiteCredential($user); + $credential->setHost('monde-diplomatique.fr'); + $credential->setUsername('foo'); + $credential->setPassword('bar'); + + $em->persist($credential); + $em->flush(); + + $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()); + + $crawler = $client->followRedirect(); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); + + $content = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getLoggedInUserId()); + + $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); + $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); + + $client->getContainer()->get('craue_config')->set('restricted_access', 0); + } }