aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-03 10:23:49 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-20 16:03:20 +0200
commit9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b (patch)
tree6db9842b413ba4cec80b1d36c54cf77bf1a4c2c0
parentfd7fde95159828960784a438c4b4da147e20ab18 (diff)
downloadwallabag-9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b.tar.gz
wallabag-9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b.tar.zst
wallabag-9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b.zip
Add a live test for restricted article
It is not aimed to test if we can get the full article (since we aren't using real login/password) but mostly to test the full work (with authentication, etc.) Do not clean fixtured to avoid SQLite to re-use id for entry tag relation 😓
-rw-r--r--src/Wallabag/CoreBundle/Controller/SiteCredentialController.php4
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php5
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php53
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php44
-rw-r--r--tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php6
5 files changed, 81 insertions, 31 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
index 429f529a..dc8e723d 100644
--- a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -24,9 +24,7 @@ class SiteCredentialController extends Controller
24 */ 24 */
25 public function indexAction() 25 public function indexAction()
26 { 26 {
27 $em = $this->getDoctrine()->getManager(); 27 $credentials = $this->get('wallabag_core.site_credential_repository')->findByUser($this->getUser());
28
29 $credentials = $em->getRepository('WallabagCoreBundle:SiteCredential')->findByUser($this->getUser());
30 28
31 return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', array( 29 return $this->render('WallabagCoreBundle:SiteCredential:index.html.twig', array(
32 'credentials' => $credentials, 30 'credentials' => $credentials,
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index ae69492d..62a3bc13 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -31,14 +31,13 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
31 */ 31 */
32 private $currentUser; 32 private $currentUser;
33 33
34
35 /** 34 /**
36 * GrabySiteConfigBuilder constructor. 35 * GrabySiteConfigBuilder constructor.
37 * 36 *
38 * @param ConfigBuilder $grabyConfigBuilder 37 * @param ConfigBuilder $grabyConfigBuilder
39 * @param TokenStorage $token 38 * @param TokenStorage $token
40 * @param SiteCredentialRepository $credentialRepository 39 * @param SiteCredentialRepository $credentialRepository
41 * @param LoggerInterface $logger 40 * @param LoggerInterface $logger
42 */ 41 */
43 public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger) 42 public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
44 { 43 {
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;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config; 6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\SiteCredential;
8 9
9class EntryControllerTest extends WallabagCoreTestCase 10class EntryControllerTest extends WallabagCoreTestCase
10{ 11{
@@ -1321,4 +1322,56 @@ class EntryControllerTest extends WallabagCoreTestCase
1321 $this->assertEquals($url, $content->getUrl()); 1322 $this->assertEquals($url, $content->getUrl());
1322 $this->assertEquals($expectedLanguage, $content->getLanguage()); 1323 $this->assertEquals($expectedLanguage, $content->getLanguage());
1323 } 1324 }
1325
1326 /**
1327 * This test will require an internet connection.
1328 */
1329 public function testRestrictedArticle()
1330 {
1331 $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1332 $this->logInAs('admin');
1333 $client = $this->getClient();
1334 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1335
1336 // enable restricted access
1337 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1338
1339 // create a new site_credential
1340 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1341 $credential = new SiteCredential($user);
1342 $credential->setHost('monde-diplomatique.fr');
1343 $credential->setUsername('foo');
1344 $credential->setPassword('bar');
1345
1346 $em->persist($credential);
1347 $em->flush();
1348
1349 $crawler = $client->request('GET', '/new');
1350
1351 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1352
1353 $form = $crawler->filter('form[name=entry]')->form();
1354
1355 $data = [
1356 'entry[url]' => $url,
1357 ];
1358
1359 $client->submit($form, $data);
1360
1361 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1362
1363 $crawler = $client->followRedirect();
1364
1365 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1366 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1367
1368 $content = $em
1369 ->getRepository('WallabagCoreBundle:Entry')
1370 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1371
1372 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1373 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1374
1375 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1376 }
1324} 1377}
diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php
index 47bf0907..7e6dafee 100644
--- a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php
@@ -2,7 +2,9 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Client;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 6use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
7use Wallabag\CoreBundle\Entity\SiteCredential;
6 8
7class SiteCredentialControllerTest extends WallabagCoreTestCase 9class SiteCredentialControllerTest extends WallabagCoreTestCase
8{ 10{
@@ -52,18 +54,12 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase
52 $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); 54 $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]);
53 } 55 }
54 56
55 /**
56 * @depends testNewSiteCredential
57 */
58 public function testEditSiteCredential() 57 public function testEditSiteCredential()
59 { 58 {
60 $this->logInAs('admin'); 59 $this->logInAs('admin');
61 $client = $this->getClient(); 60 $client = $this->getClient();
62 61
63 $credential = $client->getContainer() 62 $credential = $this->createSiteCredential($client);
64 ->get('doctrine.orm.entity_manager')
65 ->getRepository('WallabagCoreBundle:SiteCredential')
66 ->findOneByHost('google.io');
67 63
68 $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); 64 $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit');
69 65
@@ -92,36 +88,26 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase
92 $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value')); 88 $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value'));
93 } 89 }
94 90
95 /**
96 * @depends testNewSiteCredential
97 */
98 public function testEditFromADifferentUserSiteCredential() 91 public function testEditFromADifferentUserSiteCredential()
99 { 92 {
100 $this->logInAs('bob'); 93 $this->logInAs('admin');
101 $client = $this->getClient(); 94 $client = $this->getClient();
102 95
103 $credential = $client->getContainer() 96 $credential = $this->createSiteCredential($client);
104 ->get('doctrine.orm.entity_manager') 97
105 ->getRepository('WallabagCoreBundle:SiteCredential') 98 $this->logInAs('bob');
106 ->findOneByHost('google.io');
107 99
108 $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); 100 $client->request('GET', '/site-credentials/'.$credential->getId().'/edit');
109 101
110 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 102 $this->assertEquals(403, $client->getResponse()->getStatusCode());
111 } 103 }
112 104
113 /**
114 * @depends testNewSiteCredential
115 */
116 public function testDeleteSiteCredential() 105 public function testDeleteSiteCredential()
117 { 106 {
118 $this->logInAs('admin'); 107 $this->logInAs('admin');
119 $client = $this->getClient(); 108 $client = $this->getClient();
120 109
121 $credential = $client->getContainer() 110 $credential = $this->createSiteCredential($client);
122 ->get('doctrine.orm.entity_manager')
123 ->getRepository('WallabagCoreBundle:SiteCredential')
124 ->findOneByHost('google.io');
125 111
126 $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); 112 $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit');
127 113
@@ -137,4 +123,18 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase
137 123
138 $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); 124 $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]);
139 } 125 }
126
127 private function createSiteCredential(Client $client)
128 {
129 $credential = new SiteCredential($this->getLoggedInUser());
130 $credential->setHost('google.io');
131 $credential->setUsername('sergei');
132 $credential->setPassword('microsoft');
133
134 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
135 $em->persist($credential);
136 $em->flush();
137
138 return $credential;
139 }
140} 140}
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
index 980f7579..1e1e8989 100644
--- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
+++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
@@ -25,7 +25,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
25 25
26 $grabySiteConfig = new GrabySiteConfig(); 26 $grabySiteConfig = new GrabySiteConfig();
27 $grabySiteConfig->requires_login = true; 27 $grabySiteConfig->requires_login = true;
28 $grabySiteConfig->login_uri = 'http://example.com/login'; 28 $grabySiteConfig->login_uri = 'http://www.example.com/login';
29 $grabySiteConfig->login_username_field = 'login'; 29 $grabySiteConfig->login_username_field = 'login';
30 $grabySiteConfig->login_password_field = 'password'; 30 $grabySiteConfig->login_password_field = 'password';
31 $grabySiteConfig->login_extra_fields = ['field=value']; 31 $grabySiteConfig->login_extra_fields = ['field=value'];
@@ -67,13 +67,13 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
67 $logger 67 $logger
68 ); 68 );
69 69
70 $config = $this->builder->buildForHost('example.com'); 70 $config = $this->builder->buildForHost('www.example.com');
71 71
72 $this->assertEquals( 72 $this->assertEquals(
73 new SiteConfig([ 73 new SiteConfig([
74 'host' => 'example.com', 74 'host' => 'example.com',
75 'requiresLogin' => true, 75 'requiresLogin' => true,
76 'loginUri' => 'http://example.com/login', 76 'loginUri' => 'http://www.example.com/login',
77 'usernameField' => 'login', 77 'usernameField' => 'login',
78 'passwordField' => 'password', 78 'passwordField' => 'password',
79 'extraFields' => ['field' => 'value'], 79 'extraFields' => ['field' => 'value'],