aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php49
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php5
3 files changed, 56 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index b0d4c4e1..5c7b988c 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -501,6 +501,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
501 $content = json_decode($this->client->getResponse()->getContent(), true); 501 $content = json_decode($this->client->getResponse()->getContent(), true);
502 $this->assertGreaterThan(0, $content['id']); 502 $this->assertGreaterThan(0, $content['id']);
503 $this->assertSame('http://www.example.com/', $content['url']); 503 $this->assertSame('http://www.example.com/', $content['url']);
504 $this->assertSame('www.example.com', $content['domain_name']);
505 $this->assertSame('www.example.com', $content['title']);
504 } finally { 506 } finally {
505 // Remove the created entry to avoid side effects on other tests 507 // Remove the created entry to avoid side effects on other tests
506 if (isset($content['id'])) { 508 if (isset($content['id'])) {
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;