1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-07-17 17:08:37 +00:00

Change the way to login user in tests

Instead of using a HTTP request we just login user like FOSUser does.
It allows us to mock service in container for functional tests.

Also, fix a bad config name in fos_user for firewall

And finally, add functional test to PocketImport
This commit is contained in:
Jeremy Benoist 2016-06-24 11:55:45 +02:00
parent 2bc9cad78e
commit fdc90ceb17
6 changed files with 90 additions and 9 deletions

View file

@ -22,15 +22,13 @@ class PocketControllerTest extends WallabagCoreTestCase
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/import/pocket/auth');
$client->request('GET', '/import/pocket/auth');
$this->assertEquals(302, $client->getResponse()->getStatusCode());
}
public function testImportPocketAuth()
{
$this->markTestSkipped('PocketImport: Find a way to properly mock a service.');
$this->logInAs('admin');
$client = $this->getClient();
@ -43,9 +41,9 @@ class PocketControllerTest extends WallabagCoreTestCase
->method('getRequestToken')
->willReturn('token');
$client->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
$crawler = $client->request('GET', '/import/pocket/auth');
$client->request('GET', '/import/pocket/auth');
$this->assertEquals(301, $client->getResponse()->getStatusCode());
$this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location'));
@ -56,10 +54,55 @@ class PocketControllerTest extends WallabagCoreTestCase
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/import/pocket/callback');
$pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport')
->disableOriginalConstructor()
->getMock();
$pocketImport
->expects($this->once())
->method('authorize')
->willReturn(false);
static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
$client->request('GET', '/import/pocket/callback');
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertContains('import/pocket', $client->getResponse()->headers->get('location'));
$this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
$this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
}
public function testImportPocketCallback()
{
$this->logInAs('admin');
$client = $this->getClient();
$pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport')
->disableOriginalConstructor()
->getMock();
$pocketImport
->expects($this->once())
->method('authorize')
->willReturn(true);
$pocketImport
->expects($this->once())
->method('setMarkAsRead')
->with(false)
->willReturn($pocketImport);
$pocketImport
->expects($this->once())
->method('import')
->willReturn(true);
static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
$client->request('GET', '/import/pocket/callback');
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
$this->assertEquals('flashes.import.notice.summary', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
}
}