Page MenuHomePhabricator

AbstractBasicTest.php
No OneTemporary

AbstractBasicTest.php

<?php
namespace Sabre\DAV\Auth\Backend;
use Sabre\DAV;
use Sabre\HTTP;
require_once 'Sabre/HTTP/ResponseMock.php';
class AbstractBasicTest extends \PHPUnit_Framework_TestCase {
function testCheckNoHeaders() {
$request = new HTTP\Request();
$response = new HTTP\Response();
$backend = new AbstractBasicMock();
$this->assertFalse(
$backend->check($request, $response)[0]
);
}
function testCheckUnknownUser() {
$request = HTTP\Sapi::createFromServerArray(array(
'PHP_AUTH_USER' => 'username',
'PHP_AUTH_PW' => 'wrongpassword',
));
$response = new HTTP\Response();
$backend = new AbstractBasicMock();
$this->assertFalse(
$backend->check($request, $response)[0]
);
}
function testCheckSuccess() {
$request = HTTP\Sapi::createFromServerArray(array(
'PHP_AUTH_USER' => 'username',
'PHP_AUTH_PW' => 'password',
));
$response = new HTTP\Response();
$backend = new AbstractBasicMock();
$this->assertEquals(
[true, 'principals/username'],
$backend->check($request, $response)
);
}
function testRequireAuth() {
$request = new HTTP\Request();
$response = new HTTP\Response();
$backend = new AbstractBasicMock();
$backend->setRealm('writing unittests on a saturday night');
$backend->challenge($request, $response);
$this->assertEquals(
'Basic realm="writing unittests on a saturday night"',
$response->getHeader('WWW-Authenticate')
);
}
}
class AbstractBasicMock extends AbstractBasic {
/**
* Validates a username and password
*
* This method should return true or false depending on if login
* succeeded.
*
* @param string $username
* @param string $password
* @return bool
*/
function validateUserPass($username, $password) {
return ($username == 'username' && $password == 'password');
}
}

File Metadata

Mime Type
text/x-php
Expires
Dec 20 2024, 8:02 AM (4 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
914381
Default Alt Text
AbstractBasicTest.php (2 KB)

Event Timeline