public function onBootstrap(MvcEvent $e) { if (\Zend\Console\Console::isConsole()) { return; } $eventManager = $e->getApplication()->getEventManager(); $services = $e->getApplication()->getServiceManager(); $eventManager->attach(MvcEvent::EVENT_ROUTE, function (MvcEvent $e) use($services) { /* @var $checkPermissionsListener \Acl\Listener\CheckPermissionsListener */ $checkPermissionsListener = $services->get('Auth/CheckPermissionsListener'); $checkPermissionsListener->onRoute($e); }, -10); $eventManager->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) use($services) { /** @var CheckPermissionsListener $checkPermissionsListener */ $checkPermissionsListener = $services->get('Auth/CheckPermissionsListener'); $checkPermissionsListener->onDispatch($e); }, 10); $unauthorizedAccessListener = $services->get('UnauthorizedAccessListener'); $unauthorizedAccessListener->attach($eventManager); $deactivatedUserListener = $services->get('DeactivatedUserListener'); $deactivatedUserListener->attach($eventManager); $sharedManager = $eventManager->getSharedManager(); $defaultlistener = $services->get('Auth/Listener/AuthAggregateListener'); $defaultlistener->attachShared($sharedManager); $socialProfilesUnconfiguredErrorListener = new SocialProfilesUnconfiguredErrorListener(); $socialProfilesUnconfiguredErrorListener->attach($eventManager); }
/** * @dataProvider provideTestData * * @param $useValidException * @param $useValidModel * @param $useValidError * @param $shouldModelChange */ public function testSetsViewModelTemplateIfPrerequisitesAreMet($useValidException, $useValidModel, $useValidError, $shouldModelChange) { $target = new SocialProfilesUnconfiguredErrorListener(); $exception = new \Exception($useValidException ? 'Your application id and secret' : 'This exception must not match'); $event = $this->getMockBuilder('\\Zend\\Mvc\\MvcEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('getParam')->with('exception')->willReturn($exception); if ($useValidModel) { $model = $this->getMockBuilder('\\Zend\\View\\Model\\ViewModel')->disableOriginalConstructor()->getMock(); if ($shouldModelChange) { $model->expects($this->once())->method('setTemplate')->with('auth/error/social-profiles-unconfigured'); } else { $model->expects($this->never())->method('setTemplate'); } $event->expects($this->once())->method('getError')->willReturn($useValidError ? Application::ERROR_EXCEPTION : 'NotMatchError'); } else { $model = 'not a view model instance'; $event->expects($this->never())->method('getError'); } $event->expects($this->once())->method('getResult')->willReturn($model); $target->onDispatchError($event); }