Skip to content

Commit

Permalink
Add test on EntryControllerTest for #3442
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
  • Loading branch information
Kdecherf committed Dec 1, 2017
1 parent f8c154b commit 2233c5d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Expand Up @@ -6,6 +6,7 @@
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\SiteCredential;
use Wallabag\CoreBundle\Helper\ContentProxy;

class EntryControllerTest extends WallabagCoreTestCase
{
Expand Down Expand Up @@ -1429,4 +1430,55 @@ public function testRestrictedArticle()

$client->getContainer()->get('craue_config')->set('restricted_access', 0);
}

/**
* This test will require an internet connection.
*/
public function testPostEntryWhenFetchFails()
{
$url = 'http://example.com/papers/email_tracking.pdf';
$this->logInAs('admin');
$client = $this->getClient();

$container = $client->getContainer();
$contentProxy = $this->getMockBuilder(ContentProxy::class)
->disableOriginalConstructor()
->setMethods(['updateEntry'])
->getMock();
$contentProxy->expects($this->any())
->method('updateEntry')
->willThrowException(new \Exception('Test Fetch content fails'));

$crawler = $client->request('GET', '/new');

$this->assertSame(200, $client->getResponse()->getStatusCode());

$form = $crawler->filter('form[name=entry]')->form();

$data = [
'entry[url]' => $url,
];

/**
* We generate a new client to be able to use Mock ContentProxy
* Also we reinject the cookie from the previous client to keep the
* session.
*/
$cookie = $client->getCookieJar()->all();
$client = $this->getNewClient();
$client->getCookieJar()->set($cookie[0]);
$client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
$client->submit($form, $data);

$this->assertSame(302, $client->getResponse()->getStatusCode());

$content = $client->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId($url, $this->getLoggedInUserId());

$authors = $content->getPublishedBy();
$this->assertSame('email_tracking.pdf', $content->getTitle());
$this->assertSame('example.com', $content->getDomainName());
}
}
5 changes: 5 additions & 0 deletions tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
Expand Up @@ -25,6 +25,11 @@ public function setUp()
$this->client = static::createClient();
}

public function getNewClient()
{
return $this->client = static::createClient();
}

public function getClient()
{
return $this->client;
Expand Down

0 comments on commit 2233c5d

Please sign in to comment.