Last active
August 29, 2015 14:01
-
-
Save garak/0c2dbebd3892b295feae to your computer and use it in GitHub Desktop.
Testing facebook login with FOSFacebookBundle (functional test)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
fos_facebook: | |
class: | |
api: Acme\DemoBundle\Test\FacebookSessionPersistenceStub | |
security: | |
firewalls: | |
frontend: | |
fos_facebook: | |
require_previous_session: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\Tests\Controller; | |
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
class DefaultControllerTest extends WebTestCase | |
{ | |
public function testLoginOK() | |
{ | |
$client = static::createClient(); | |
$crawler = $client->request('GET', '/'); | |
$this->assertTrue($client->getResponse()->isSuccessful()); | |
$crawler = $client->request('POST', '/loginfb_check'); | |
$crawler = $client->followRedirect(); | |
$this->assertTrue($client->getResponse()->isSuccessful()); | |
$this->assertCount(1, $crawler->filter('strong:contains("Mallo")')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\Test; | |
use Symfony\Component\HttpFoundation\Session\Session; | |
/** | |
* Stub of FOS\FacebookBundle\Facebook\FacebookSessionPersistence | |
* | |
* @codeCoverageIgnore | |
* @SuppressWarnings('unused') | |
*/ | |
class FacebookSessionPersistenceStub extends \BaseFacebook | |
{ | |
public function __construct($config, Session $session, $prefix = '') | |
{ | |
} | |
public function getLoginUrl($params = array()) | |
{ | |
return ''; | |
} | |
public function api() | |
{ | |
return array( | |
'id' => 123456, | |
'first_name' => 'Mallo', | |
'last_name' => 'Di Noce', | |
'email' => '[email protected]', | |
); | |
} | |
protected function clearAllPersistentData() | |
{ | |
} | |
protected function clearPersistentData($key) | |
{ | |
} | |
protected function setPersistentData($key, $value) | |
{ | |
} | |
protected function getPersistentData($key, $default = false) | |
{ | |
if ($key == 'user_id') { | |
return 123456; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment