public function testClearHeaderAndHeaderNotExists() { $response = $this->response = $this->getMock('Magento\\Framework\\HTTP\\PhpEnvironment\\Response', ['getHeaders', 'send']); $this->headers->addHeaderLine('Header-name: header-value'); $header = \Zend\Http\Header\GenericHeader::fromString('Header-name: header-value'); $this->headers->expects($this->once())->method('has')->with('Header-name')->will($this->returnValue(false)); $this->headers->expects($this->never())->method('get')->with('Header-name')->will($this->returnValue($header)); $this->headers->expects($this->never())->method('removeHeader')->with($header); $response->expects($this->once())->method('getHeaders')->will($this->returnValue($this->headers)); $response->clearHeader('Header-name'); }
protected function setUp() { $this->markTestSkipped('Remove it when MAGETWO-33495 is done.'); $this->_response = $this->getMockBuilder('\\Magento\\Framework\\App\\Response\\Http')->setMethods(['sendHeaders'])->disableOriginalConstructor()->getMock(); $this->_request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getHeader'], [], '', false); $header = \Zend\Http\Header\GenericHeader::fromString('User-Agent: Mozilla/5.0 FirePHP/1.6'); $this->_request->expects($this->any())->method('getHeader')->with('User-Agent')->will($this->returnValue($header)); $this->_output = new \Magento\Framework\Profiler\Driver\Standard\Output\Firebug(); $this->_output->setResponse($this->_response); $this->_output->setRequest($this->_request); }
public function testSchemeFail() { $accept = new Accept(); $accept->addMediaType('application/json'); $this->getRequest()->setMethod(Request::METHOD_GET)->getHeaders()->addHeaders([$accept, GenericHeader::fromString('Authorization: Basic ' . base64_encode('toby:password1'))]); $this->dispatch('http://test.com/test'); $response = $this->getResponse(); $this->assertResponseStatusCode(403); $content = $response->getContent(); $this->assertEquals(0, strlen($content)); }
public function testSchemeFail() { $this->getRequest()->setMethod(Request::METHOD_GET)->getHeaders()->addHeader(GenericHeader::fromString('Authorization: Basic ' . base64_encode('toby:password'))); $this->dispatch('http://test.com/test'); $response = $this->getResponse(); $this->assertResponseStatusCode(403); $this->assertEquals('false', $response->getContent()); // $this->request->setUri('http://test.local'); // $this->request->getHeaders()->addHeader(GenericHeader::fromString('Authorization: Basic ' . base64_encode('toby:password'))); // // $this->assertFalse($this->authenticationService->hasIdentity()); }
/** * @dataProvider dataProvider */ public function testAroundDispatchProcessIfCacheMissed($state) { $header = \Zend\Http\Header\GenericHeader::fromString('Cache-Control: no-cache'); $this->configMock->expects($this->once())->method('getType')->will($this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)); $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $this->versionMock->expects($this->once())->method('process'); $this->kernelMock->expects($this->once())->method('load')->will($this->returnValue(false)); $this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state)); if ($state == \Magento\Framework\App\State::MODE_DEVELOPER) { $this->responseMock->expects($this->at(1))->method('setHeader')->with('X-Magento-Cache-Control'); $this->responseMock->expects($this->at(2))->method('setHeader')->with('X-Magento-Cache-Debug', 'MISS', true); } else { $this->responseMock->expects($this->never())->method('setHeader'); } $this->responseMock->expects($this->once())->method('getHeader')->with('Cache-Control')->will($this->returnValue($header)); $this->kernelMock->expects($this->once())->method('process')->with($this->responseMock); $this->assertSame($this->responseMock, $this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock)); }
public function testUpdateIdentityCredentialFail() { $this->setExpectedException('Sds\\IdentityModule\\Exception\\InvalidArgumentException'); $this->routeMatch->setParam('id', 'lucy'); $this->request->setMethod(Request::METHOD_PUT); $this->request->getHeaders()->addHeader(GenericHeader::fromString('Content-type: application/json')); $this->request->setContent('{ "credential":"password2" }'); $result = $this->getController()->dispatch($this->request, $this->response); $result->getVariables(); }
protected function getSubRequest($batchRequest, array $requestData) { $request = new Request(); $request->setMethod($requestData['method']); $request->setUri($requestData['uri']); $queryString = $request->getUri()->getQuery(); if ($queryString) { $query = []; parse_str($queryString, $query); $request->setQuery(new Parameters($query)); } $requestHeaders = [$batchRequest->getHeaders()->get('Accept'), $batchRequest->getHeaders()->get('Content-Type')]; if (isset($requestData['headers'])) { foreach ($requestData['headers'] as $name => $value) { $requestHeaders[] = GenericHeader::fromString($name . ': ' . $value); } } $request->getHeaders()->addHeaders($requestHeaders); if (isset($requestData['content'])) { $request->setContent(json_encode($requestData['content'])); } return $request; }