1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00
Arsse/tests/User/TestUser.php
J. King 7785eb072b Complete rewrite of User class and other changes
- User-related database methods will now throw User\Exception upon errors
- Internal userAdd method can now generate random passwords
- Pursuant to above, dependency on password genrator has been added, and password-related methods now return strings instead of booleans
- User class methods now all explicitly follow different branches for internal/external/missing implementations
- various User class methods now perform auto-provisioning of the internal database when external implementations report success on users not in the database
- Tests have been adjusted to account for the above changes
- Lots is probably still broken
2017-02-20 17:04:13 -05:00

72 lines
2 KiB
PHP

<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync;
class TestUser extends \PHPUnit\Framework\TestCase {
use Test\Tools;
const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com";
protected $data;
function setUp() {
$drv = Test\User\DriverInternalMock::class;
$conf = new Conf();
$conf->userDriver = $drv;
$conf->userAuthPreferHTTP = true;
$this->data = new Test\RuntimeData($conf);
$this->data->user = new User($this->data);
$_SERVER['PHP_AUTH_USER'] = self::USER1;
$_SERVER['PHP_AUTH_PW'] = "secret";
}
function testListUsers() {
$this->assertCount(0,$this->data->user->list());
}
function testCheckIfAUserDoesNotExist() {
$this->assertFalse($this->data->user->exists(self::USER1));
}
function testAddAUser() {
$this->data->user->add(self::USER1, "secret");
$this->assertCount(1,$this->data->user->list());
}
function testCheckIfAUserDoesExist() {
$this->data->user->add(self::USER1, "secret");
$this->assertTrue($this->data->user->exists(self::USER1));
}
function testAddADuplicateUser() {
$this->data->user->add(self::USER1, "secret");
$this->assertException("alreadyExists", "User");
$this->data->user->add(self::USER1, "secret");
}
function testAddMultipleUsers() {
$this->data->user->add(self::USER1, "secret");
$this->data->user->add(self::USER2, "secret");
$this->assertCount(2,$this->data->user->list());
}
function testRemoveAUser() {
$this->data->user->add(self::USER1, "secret");
$this->assertCount(1,$this->data->user->list());
$this->data->user->remove(self::USER1);
$this->assertCount(0,$this->data->user->list());
}
function testRemoveAMissingUser() {
$this->assertException("doesNotExist", "User");
$this->data->user->remove(self::USER1);
}
function testAuthenticateAUser() {
$this->data->user->add(self::USER1, "secret");
$this->assertTrue($this->data->user->auth(self::USER1, "secret"));
$this->assertFalse($this->data->user->auth(self::USER1, "superman"));
}
}