public function testInvoke() { $url = 'someUrl'; $this->routeMatch->expects($this->once())->method('getMatchedRouteName')->will($this->returnValue('someRoute')); $headers = $this->getMock('Zend\\Http\\Headers'); $headers->expects($this->once())->method('addHeaderLine')->with('Location', $url); $this->router->expects($this->any())->method('assemble')->with(array(), array('name' => 'zfcuser'))->will($this->returnValue($url)); $this->response->expects($this->once())->method('getHeaders')->will($this->returnValue($headers)); $this->response->expects($this->once())->method('setStatusCode')->with(302); $result = $this->redirectCallback->__invoke(); $this->assertSame($this->response, $result); }
/** * @dataProvider providerTestAuthenticateAction * @depend testActionControllHasIdentity */ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareResult = false, $authValid = false) { $controller = $this->controller; $response = new Response(); $hasRedirect = !(is_null($query) && is_null($post)); $params = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Params'); $params->expects($this->any())->method('__invoke')->will($this->returnSelf()); $params->expects($this->once())->method('fromPost')->will($this->returnCallback(function ($key, $default) use($post) { return $post ?: $default; })); $params->expects($this->once())->method('fromQuery')->will($this->returnCallback(function ($key, $default) use($query) { return $query ?: $default; })); $this->pluginManagerPlugins['params'] = $params; $request = $this->getMock('Zend\\Http\\Request'); $this->helperMakePropertyAccessable($controller, 'request', $request); $adapter = $this->getMock('ZfcUser\\Authentication\\Adapter\\AdapterChain'); $adapter->expects($this->once())->method('prepareForAuthentication')->with($request)->will($this->returnValue($prepareResult)); $service = $this->getMock('Zend\\Authentication\\AuthenticationService'); $this->setUpZfcUserAuthenticationPlugin(array('hasIdentity' => false, 'getAuthAdapter' => $adapter, 'getAuthService' => $service)); if (is_bool($prepareResult)) { $authResult = $this->getMockBuilder('Zend\\Authentication\\Result')->disableOriginalConstructor()->getMock(); $authResult->expects($this->once())->method('isValid')->will($this->returnValue($authValid)); $service->expects($this->once())->method('authenticate')->with($adapter)->will($this->returnValue($authResult)); $redirect = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Redirect'); $this->pluginManagerPlugins['redirect'] = $redirect; if (!$authValid) { $flashMessenger = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\FlashMessenger'); $this->pluginManagerPlugins['flashMessenger'] = $flashMessenger; $flashMessenger->expects($this->once())->method('setNamespace')->with('zfcuser-login-form')->will($this->returnSelf()); $flashMessenger->expects($this->once())->method('addMessage'); $adapter->expects($this->once())->method('resetAdapters'); $redirectQuery = $post ?: $query ?: false; $redirectQuery = $redirectQuery ? '?redirect=' . rawurlencode($redirectQuery) : ''; $redirect->expects($this->once())->method('toUrl')->with('user/login' . $redirectQuery)->will($this->returnValue($response)); $url = $this->getMock('Zend\\Mvc\\Controller\\Plugin\\Url'); $url->expects($this->once())->method('fromRoute')->with($controller::ROUTE_LOGIN)->will($this->returnValue('user/login')); $this->pluginManagerPlugins['url'] = $url; } else { $this->redirectCallback->expects($this->once())->method('__invoke'); } $this->options->expects($this->any())->method('getUseRedirectParameterIfPresent')->will($this->returnValue((bool) $wantRedirect)); } $result = $controller->authenticateAction(); }