Add API auth events

This commit is contained in:
Romain Neutron
2013-05-07 17:16:14 +02:00
parent c0fcd10964
commit e42363acb0
2 changed files with 35 additions and 0 deletions

View File

@@ -12,6 +12,8 @@
namespace Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Authentication\Context;
use Alchemy\Phrasea\Core\Event\PreAuthenticate;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Controller\Api\Oauth2;
use Alchemy\Phrasea\Controller\Api\V1;

View File

@@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Border\Manager;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response;
@@ -112,6 +113,38 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
parent::tearDownAfterClass();
}
/**
* @dataProvider provideEventNames
*/
public function testThatEventsAreDispatched($eventName, $className, $route)
{
$preEvent = 0;
$phpunit = $this;
self::$DI['app']['dispatcher']->addListener($eventName, function ($event) use ($phpunit, &$preEvent, $className) {
$preEvent++;
$phpunit->assertInstanceOf($className, $event);
});
$this->setToken(self::$token);
self::$DI['client']->request('GET', '/databoxes/list/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
$this->assertEquals(1, $preEvent);
}
public function provideEventNames()
{
return array(
array(PhraseaEvents::PRE_AUTHENTICATE, 'Alchemy\Phrasea\Core\Event\PreAuthenticate', '/databoxes/list/'),
array(PhraseaEvents::API_OAUTH2_START, 'Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent', '/databoxes/list/'),
array(PhraseaEvents::API_OAUTH2_END, 'Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent', '/databoxes/list/'),
array(PhraseaEvents::API_RESULT, 'Alchemy\Phrasea\Core\Event\ApiResultEvent', '/databoxes/list/'),
array(PhraseaEvents::PRE_AUTHENTICATE, 'Alchemy\Phrasea\Core\Event\PreAuthenticate', '/no-route'),
array(PhraseaEvents::API_OAUTH2_START, 'Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent', '/no-route'),
array(PhraseaEvents::API_OAUTH2_END, 'Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent', '/no-route'),
array(PhraseaEvents::API_RESULT, 'Alchemy\Phrasea\Core\Event\ApiResultEvent', '/no-route'),
);
}
public function testRouteNotFound()
{
$route = '/api/v1/nothinghere';