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()); }