aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2017-11-27 22:56:46 +0100
committerKevin Decherf <kevin@kdecherf.com>2017-12-13 22:44:31 +0100
commit300f293cb1b7c2e2a94e3d716c75faf4b2a9b823 (patch)
tree177786412f334effb74135f715273eba77928ab6
parentaf29e1bf07aabaa6a4e4653c1a3b5c10ce831bb6 (diff)
downloadwallabag-300f293cb1b7c2e2a94e3d716c75faf4b2a9b823.tar.gz
wallabag-300f293cb1b7c2e2a94e3d716c75faf4b2a9b823.tar.zst
wallabag-300f293cb1b7c2e2a94e3d716c75faf4b2a9b823.zip
Add test on EntryControllerTest for #3442
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php49
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php5
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 4ac4548b..a02f9699 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -6,6 +6,7 @@ use 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; 8use Wallabag\CoreBundle\Entity\SiteCredential;
9use Wallabag\CoreBundle\Helper\ContentProxy;
9 10
10class EntryControllerTest extends WallabagCoreTestCase 11class EntryControllerTest extends WallabagCoreTestCase
11{ 12{
@@ -1429,4 +1430,52 @@ class EntryControllerTest extends WallabagCoreTestCase
1429 1430
1430 $client->getContainer()->get('craue_config')->set('restricted_access', 0); 1431 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1431 } 1432 }
1433
1434 public function testPostEntryWhenFetchFails()
1435 {
1436 $url = 'http://example.com/papers/email_tracking.pdf';
1437 $this->logInAs('admin');
1438 $client = $this->getClient();
1439
1440 $container = $client->getContainer();
1441 $contentProxy = $this->getMockBuilder(ContentProxy::class)
1442 ->disableOriginalConstructor()
1443 ->setMethods(['updateEntry'])
1444 ->getMock();
1445 $contentProxy->expects($this->any())
1446 ->method('updateEntry')
1447 ->willThrowException(new \Exception('Test Fetch content fails'));
1448
1449 $crawler = $client->request('GET', '/new');
1450
1451 $this->assertSame(200, $client->getResponse()->getStatusCode());
1452
1453 $form = $crawler->filter('form[name=entry]')->form();
1454
1455 $data = [
1456 'entry[url]' => $url,
1457 ];
1458
1459 /**
1460 * We generate a new client to be able to use Mock ContentProxy
1461 * Also we reinject the cookie from the previous client to keep the
1462 * session.
1463 */
1464 $cookie = $client->getCookieJar()->all();
1465 $client = $this->getNewClient();
1466 $client->getCookieJar()->set($cookie[0]);
1467 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1468 $client->submit($form, $data);
1469
1470 $this->assertSame(302, $client->getResponse()->getStatusCode());
1471
1472 $content = $client->getContainer()
1473 ->get('doctrine.orm.entity_manager')
1474 ->getRepository('WallabagCoreBundle:Entry')
1475 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1476
1477 $authors = $content->getPublishedBy();
1478 $this->assertSame('email_tracking.pdf', $content->getTitle());
1479 $this->assertSame('example.com', $content->getDomainName());
1480 }
1432} 1481}
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index 1eda5199..6e1163c5 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -25,6 +25,11 @@ abstract class WallabagCoreTestCase extends WebTestCase
25 $this->client = static::createClient(); 25 $this->client = static::createClient();
26 } 26 }
27 27
28 public function getNewClient()
29 {
30 return $this->client = static::createClient();
31 }
32
28 public function getClient() 33 public function getClient()
29 { 34 {
30 return $this->client; 35 return $this->client;