mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Improve account test
This commit is contained in:
parent
492430ea8a
commit
99f429f7ed
|
|
@ -18,45 +18,96 @@ use phpOMS\Account\AccountManager;
|
|||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Account\AccountManager: Account/user manager to handle/access loaded accounts
|
||||
*/
|
||||
class AccountManagerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $manager = null;
|
||||
protected $account = null;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->manager = new AccountManager($GLOBALS['httpSession']);
|
||||
|
||||
$this->account = new Account(3);
|
||||
$this->account->generatePassword('abcd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The manager has the expected member variables
|
||||
*/
|
||||
public function testAttributes() : void
|
||||
{
|
||||
$manager = new AccountManager($GLOBALS['httpSession']);
|
||||
self::assertInstanceOf('\phpOMS\Account\AccountManager', $manager);
|
||||
self::assertInstanceOf('\phpOMS\Account\AccountManager', $this->manager);
|
||||
|
||||
/* Testing members */
|
||||
self::assertObjectHasAttribute('accounts', $manager);
|
||||
self::assertObjectHasAttribute('accounts', $this->manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The manager has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$manager = new AccountManager($GLOBALS['httpSession']);
|
||||
|
||||
self::assertEquals(0, $manager->count());
|
||||
self::assertInstanceOf('\phpOMS\Account\Account', $manager->get(0));
|
||||
self::assertInstanceOf('\phpOMS\Account\NullAccount', $manager->get(-1));
|
||||
self::assertEquals(0, $this->manager->count());
|
||||
self::assertInstanceOf('\phpOMS\Account\Account', $this->manager->get(0));
|
||||
self::assertInstanceOf('\phpOMS\Account\NullAccount', $this->manager->get(-1));
|
||||
}
|
||||
|
||||
public function testSetGet() : void
|
||||
/**
|
||||
* @testdox An account can be added to the manager
|
||||
*/
|
||||
public function testAddAccount() : void
|
||||
{
|
||||
$manager = new AccountManager($GLOBALS['httpSession']);
|
||||
$account = new Account(3);
|
||||
|
||||
$account->generatePassword('abcd');
|
||||
|
||||
$added = $manager->add($account);
|
||||
$added = $this->manager->add($this->account);
|
||||
self::assertTrue($added);
|
||||
self::assertEquals($account, $manager->get($account->getId()));
|
||||
self::assertEquals(1, $manager->count());
|
||||
self::assertEquals(1, $this->manager->count());
|
||||
}
|
||||
|
||||
$added = $manager->add($account);
|
||||
/**
|
||||
* @testdox An account can be retrieved from the manager
|
||||
*/
|
||||
public function testRetrieveAccount() : void
|
||||
{
|
||||
$this->manager->add($this->account);
|
||||
self::assertEquals($this->account, $this->manager->get($this->account->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An account can only be added once to the account manager (no duplication)
|
||||
*/
|
||||
public function testNoAccountDuplication() : void
|
||||
{
|
||||
$this->manager->add($this->account);
|
||||
$added = $this->manager->add($this->account);
|
||||
self::assertFalse($added);
|
||||
|
||||
self::assertTrue($manager->remove($account->getId()));
|
||||
self::assertFalse($manager->remove(-1));
|
||||
self::assertEquals(0, $manager->count());
|
||||
self::assertTrue($this->manager->remove($this->account->getId()));
|
||||
self::assertFalse($this->manager->remove(-1));
|
||||
self::assertEquals(0, $this->manager->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An account can be removed from the account manager
|
||||
*/
|
||||
public function testRemoveAccount() : void
|
||||
{
|
||||
$this->manager->add($this->account);
|
||||
self::assertTrue($this->manager->remove($this->account->getId()));
|
||||
self::assertEquals(0, $this->manager->count());
|
||||
self::assertFalse($this->manager->remove(-1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Only a valid account can be removed from the manager
|
||||
*/
|
||||
public function testRemoveOnlyValidAccount() : void
|
||||
{
|
||||
$this->manager->add($this->account);
|
||||
self::assertFalse($this->manager->remove(-1));
|
||||
self::assertEquals(1, $this->manager->count());
|
||||
self::assertTrue($this->manager->remove($this->account->getId()));
|
||||
self::assertEquals(0, $this->manager->count());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user