Improve account test

This commit is contained in:
Dennis Eichhorn 2019-04-19 19:01:59 +02:00
parent 492430ea8a
commit 99f429f7ed

View File

@ -18,45 +18,96 @@ use phpOMS\Account\AccountManager;
require_once __DIR__ . '/../Autoloader.php'; require_once __DIR__ . '/../Autoloader.php';
/**
* @testdox phpOMS\tests\Account\AccountManager: Account/user manager to handle/access loaded accounts
*/
class AccountManagerTest extends \PHPUnit\Framework\TestCase 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 public function testAttributes() : void
{ {
$manager = new AccountManager($GLOBALS['httpSession']); self::assertInstanceOf('\phpOMS\Account\AccountManager', $this->manager);
self::assertInstanceOf('\phpOMS\Account\AccountManager', $manager);
/* Testing members */ /* 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 public function testDefault() : void
{ {
$manager = new AccountManager($GLOBALS['httpSession']); self::assertEquals(0, $this->manager->count());
self::assertInstanceOf('\phpOMS\Account\Account', $this->manager->get(0));
self::assertEquals(0, $manager->count()); self::assertInstanceOf('\phpOMS\Account\NullAccount', $this->manager->get(-1));
self::assertInstanceOf('\phpOMS\Account\Account', $manager->get(0));
self::assertInstanceOf('\phpOMS\Account\NullAccount', $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']); $added = $this->manager->add($this->account);
$account = new Account(3);
$account->generatePassword('abcd');
$added = $manager->add($account);
self::assertTrue($added); self::assertTrue($added);
self::assertEquals($account, $manager->get($account->getId())); self::assertEquals(1, $this->manager->count());
self::assertEquals(1, $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::assertFalse($added);
self::assertTrue($manager->remove($account->getId())); self::assertTrue($this->manager->remove($this->account->getId()));
self::assertFalse($manager->remove(-1)); self::assertFalse($this->manager->remove(-1));
self::assertEquals(0, $manager->count()); 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());
} }
} }