/** * @param array $server * @param string $expectedLogin * @param string $expectedPass * @dataProvider getCredentialsDataProvider */ public function testGetCredentials($server, $expectedLogin, $expectedPass) { $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', [], [], '', false); $request->expects($this->once())->method('getServerValue')->will($this->returnValue($server)); $response = $this->getMock('\\Magento\\Framework\\App\\Response\\Http', [], [], '', false); $authentication = new \Magento\Framework\HTTP\Authentication($request, $response); $this->assertSame([$expectedLogin, $expectedPass], $authentication->getCredentials()); }
public function testSetAuthenticationFailed() { $request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', array(), array(), '', false); $cookieMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie', array(), array(), '', false); $contextMock = $this->getMock('Magento\\Framework\\App\\Http\\Context', array(), array(), '', false); $response = new \Magento\Framework\App\Response\Http($cookieMock, $contextMock); $authentication = new \Magento\Framework\HTTP\Authentication($request, $response); $realm = uniqid(); $response->headersSentThrowsException = false; $authentication->setAuthenticationFailed($realm); $headers = $response->getHeaders(); $this->assertArrayHasKey(0, $headers); $this->assertEquals('401 Unauthorized', $headers[0]['value']); $this->assertArrayHasKey(1, $headers); $this->assertContains('realm="' . $realm . '"', $headers[1]['value']); $this->assertContains('401', $response->getBody()); }