/** * {@inheritDoc} */ public function setUp() { $this->setApplicationConfig(include __DIR__ . '/../../../../../../tests/config/application.config.php'); parent::setUp(); $this->controller = new IdeaController(); $this->request = new Request(); $this->response = null; $this->routeMatch = new RouteMatch(['controller' => 'project-idea']); $this->event = new MvcEvent(); $router = new SimpleRouteStack(); $router->addRoute('idea/idea', ['type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => ['route' => "project/idea.html"]]); $this->event->setRouter($router); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); //Get the serviceLocation and inject it into the controller $serviceLocator = $this->getApplicationServiceLocator(); $this->controller->setServiceLocator($serviceLocator); $formService = $serviceLocator->get(FormService::class); $this->controller->setFormService($formService); $ideaServiceMock = $this->getMockBuilder('Project\\Service\\IdeaService')->disableOriginalConstructor()->getMock(); $newEntityResult = new Idea(); $newEntityResult->setId(1); $ideaServiceMock->expects($this->any())->method('newEntity')->will($this->returnValue($newEntityResult)); $ideaServiceMock->expects($this->any())->method('findAll')->will($this->returnValue([])); $this->controller->setIdeaService($serviceLocator->get(IdeaService::class)); $serviceManager = $this->getApplicationServiceLocator(); $serviceManager->setAllowOverride(true); $serviceManager->setService(IdeaService::class, $ideaServiceMock); $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock(); $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $serviceManager = $this->getApplicationServiceLocator()->get('viewhelpermanager'); $serviceManager->setAllowOverride(true); $serviceManager->setService('isAllowed', $authorizeServiceMock); $this->controller->getPluginManager()->setFactory('zfcUserAuthentication', function ($sm) { $serviceLocator = $sm->getController()->getServiceLocator(); $authService = new AuthenticationService(); $nonPersistent = new NonPersistent(); /** * Store a reference if the contact in the session */ $entityManager = $serviceLocator->get('doctrine.entitymanager.orm_default'); $contact = $entityManager->getReference("Contact\\Entity\\Contact", 1); $nonPersistent->write($contact); $authService->setStorage($nonPersistent); $authAdapter = $serviceLocator->get('ZfcUser\\Authentication\\Adapter\\AdapterChain'); $controllerPlugin = new \ZfcUser\Controller\Plugin\ZfcUserAuthentication(); $controllerPlugin->setAuthService($authService); $controllerPlugin->setAuthAdapter($authAdapter); return $controllerPlugin; }); }
/** * {@inheritDoc} */ public function setUp() { $this->serviceManager = Bootstrap::getServiceManager(); $this->ideaImage = $this->serviceManager->get('viewhelpermanager')->get('ideaImage'); $idea = new Idea(); $idea->setId(1); $idea->setIdea('This is the idea'); $this->image = new Image(); $this->image->setId(1); $this->image->setIdea($idea); $contentType = new ContentType(); $contentType->setExtension('jpg'); $this->image->setContentType($contentType); }
/** * {@inheritDoc} */ public function setUp() { $this->serviceManager = Bootstrap::getServiceManager(); $idea = new Idea(); $idea->setId(1); $idea->setNumber(123123); $idea->setIdea('This is the idea'); $this->ideaService = $this->serviceManager->get(IdeaService::class); $this->ideaService->setIdea($idea); $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock(); $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $viewHelperManager = $this->serviceManager->get('viewhelpermanager'); $viewHelperManager->setService('isAllowed', $authorizeServiceMock); $urlViewHelperMock = $this->getMockBuilder(Url::class)->disableOriginalConstructor()->getMock(); $urlViewHelperMock->expects($this->any())->method('__invoke')->will($this->returnValue(true)); $viewHelperManager->setService('url', $urlViewHelperMock); $this->ideaLink = $this->serviceManager->get('viewhelpermanager')->get('idealink'); }