diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index a1d5b3aa9b..6f07434142 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -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; diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php index aed0c4a505..cd22311cc3 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php @@ -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';