From dd2050ba0df2fd9525017895b11f544d3b9d6790 Mon Sep 17 00:00:00 2001 From: Nathan Salter Date: Mon, 25 Jan 2016 11:35:16 +0000 Subject: [PATCH] Completed base testing --- src/Item/Type/PermissionItem.php | 2 +- src/Item/Type/UserItem.php | 29 +++++++++ test/Item/ItemFactoryEventTest.php | 26 ++++++++ test/Item/Type/PermissionItemTest.php | 67 ++++++++++++++++++++ test/Item/Type/UserGroupItemTest.php | 49 ++++++++++++++ test/Item/Type/UserItemTest.php | 67 ++++++++++++++++++++ test/Timetable/TimetableManagerEventTest.php | 25 ++++++++ test/Value/AbstractEnumValueTest.php | 38 +++++++++++ test/Value/DateValueTest.php | 23 +++++++ 9 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 test/Item/ItemFactoryEventTest.php create mode 100644 test/Item/Type/PermissionItemTest.php create mode 100644 test/Item/Type/UserGroupItemTest.php create mode 100644 test/Item/Type/UserItemTest.php create mode 100644 test/Timetable/TimetableManagerEventTest.php create mode 100644 test/Value/AbstractEnumValueTest.php create mode 100644 test/Value/DateValueTest.php diff --git a/src/Item/Type/PermissionItem.php b/src/Item/Type/PermissionItem.php index 887f443..937a83b 100644 --- a/src/Item/Type/PermissionItem.php +++ b/src/Item/Type/PermissionItem.php @@ -110,7 +110,7 @@ public function setItem(ItemInterface $item) : PermissionItem */ public function isAllowed() : bool { - return $this->allowed; + return $this->allowed ? true : false; } /** diff --git a/src/Item/Type/UserItem.php b/src/Item/Type/UserItem.php index 26eabbf..3ef6f62 100644 --- a/src/Item/Type/UserItem.php +++ b/src/Item/Type/UserItem.php @@ -33,6 +33,9 @@ class UserItem extends AbstractItem implements SimpleTypeInterface */ private $userGroupId; + /** + * UserItem constructor. + */ public function __construct() { $this->assignId(self::ID_PREFIX); @@ -59,6 +62,9 @@ public function setFirstName(string $firstName) return $this; } + /** + * @return bool + */ public function hasFirstName() : bool { return $this->firstName !== null; @@ -85,6 +91,9 @@ public function setSurname(string $surname) : UserItem return $this; } + /** + * @return bool + */ public function hasSurname() : bool { return $this->surname !== null; @@ -111,11 +120,27 @@ public function setUserGroupId(string $userGroupId) : UserItem return $this; } + /** + * @param UserGroupItem $userGroup + * @return UserItem + */ + public function setUserGroup(UserGroupItem $userGroup) : UserItem + { + $this->setUserGroupId($userGroup->getId()); + return $this; + } + + /** + * @return bool + */ public function hasUserGroupId() : bool { return $this->userGroupId !== null; } + /** + * @return array + */ public function toArray() : array { return array_merge([ @@ -125,6 +150,10 @@ public function toArray() : array ], parent::toArray()); } + /** + * @param array $data + * @return ItemInterface + */ public function fromArray(array $data) : ItemInterface { parent::fromArray($data); diff --git a/test/Item/ItemFactoryEventTest.php b/test/Item/ItemFactoryEventTest.php new file mode 100644 index 0000000..b677121 --- /dev/null +++ b/test/Item/ItemFactoryEventTest.php @@ -0,0 +1,26 @@ +getMock(ItemInterface::class); + $this->assertFalse($event->hasItem()); + $this->assertInstanceOf(ItemFactoryEvent::class, $event->setItem($expectedItem)); + $this->assertTrue($event->hasItem()); + $this->assertEquals($expectedItem, $event->getItem()); + + } +} diff --git a/test/Item/Type/PermissionItemTest.php b/test/Item/Type/PermissionItemTest.php new file mode 100644 index 0000000..5bf73c4 --- /dev/null +++ b/test/Item/Type/PermissionItemTest.php @@ -0,0 +1,67 @@ +assertFalse($permission->hasItemId()); + $this->assertInstanceOf(PermissionItem::class, $permission->setItem($expectedItem)); + $this->assertEquals($expectedItem->getId(), $permission->getItemId()); + $this->assertTrue($permission->hasItemId()); + $this->assertInstanceOf(PermissionItem::class, $permission->setItemId($expectedItem->getId())); + $this->assertEquals($expectedItem->getId(), $permission->getItemId()); + + $expectedUserGroup = new UserGroupItem(); + $this->assertFalse($permission->hasUserGroupId()); + $this->assertInstanceOf(PermissionItem::class, $permission->setUserGroup($expectedUserGroup)); + $this->assertEquals($expectedUserGroup->getId(), $permission->getUserGroupId()); + $this->assertTrue($permission->hasUserGroupId()); + $this->assertInstanceOf(PermissionItem::class, $permission->setUserGroupId($expectedUserGroup->getId())); + $this->assertEquals($expectedUserGroup->getId(), $permission->getUserGroupId()); + + $expectedAllowed = true; + $this->assertFalse($permission->isAllowed()); + $this->assertInstanceOf(PermissionItem::class, $permission->setAllowed($expectedAllowed)); + $this->assertEquals($expectedAllowed, $permission->isAllowed()); + + return $permission; + + } + + /** + * @param PermissionItem $item + * @depends testGettersAndSetters + */ + public function testExchangeable(PermissionItem $item) + { + + $conf = $item->toArray(); + + $newItem = new PermissionItem(); + $newItem->fromArray($conf); + + $this->assertEquals($item, $newItem); + + $newConf = $newItem->toArray(); + + $this->assertEquals($conf, $newConf); + + } +} diff --git a/test/Item/Type/UserGroupItemTest.php b/test/Item/Type/UserGroupItemTest.php new file mode 100644 index 0000000..3e5474f --- /dev/null +++ b/test/Item/Type/UserGroupItemTest.php @@ -0,0 +1,49 @@ +assertInstanceOf(UserGroupItem::class, $userGroup->setName($expectedName)); + $this->assertEquals($expectedName, $userGroup->getName()); + + return $userGroup; + + } + + + /** + * @param UserGroupItem $userGroup + * @depends testGettersAndSetters + */ + public function testExchangeable(UserGroupItem $userGroup) + { + + $conf = $userGroup->toArray(); + + $newUserGroup = new UserGroupItem(); + $newUserGroup->fromArray($conf); + + $this->assertEquals($userGroup, $newUserGroup); + + $newConf = $newUserGroup->toArray(); + + $this->assertEquals($conf, $newConf); + + } +} diff --git a/test/Item/Type/UserItemTest.php b/test/Item/Type/UserItemTest.php new file mode 100644 index 0000000..745daf4 --- /dev/null +++ b/test/Item/Type/UserItemTest.php @@ -0,0 +1,67 @@ +assertFalse($user->hasUserGroupId()); + $this->assertInstanceOf(UserItem::class, $user->setUserGroup($expectedUserGroup)); + $this->assertTrue($user->hasUserGroupId()); + $this->assertEquals($expectedUserGroup->getId(), $user->getUserGroupId()); + $this->assertInstanceOf(UserItem::class, $user->setUserGroupId($expectedUserGroup->getId())); + $this->assertEquals($expectedUserGroup->getId(), $user->getUserGroupId()); + + $expectedName = 'Great'; + $this->assertFalse($user->hasFirstName()); + $this->assertInstanceOf(UserItem::class, $user->setFirstName($expectedName)); + $this->assertTrue($user->hasFirstName()); + $this->assertEquals($expectedName, $user->getFirstName()); + + $expectedSurname = 'Scott!'; + $this->assertFalse($user->hasSurname()); + $this->assertInstanceOf(UserItem::class, $user->setSurname($expectedSurname)); + $this->assertTrue($user->hasSurname()); + $this->assertEquals($expectedSurname, $user->getSurname()); + + return $user; + + } + + /** + * @param UserItem $user + * @depends testGettersAndSetters + */ + public function testExchangeable(UserItem $user) + { + + $conf = $user->toArray(); + + $newUser = new UserItem(); + $newUser->fromArray($conf); + + $this->assertEquals($user, $newUser); + + $newConf = $newUser->toArray(); + + $this->assertEquals($conf, $newConf); + + } + + +} diff --git a/test/Timetable/TimetableManagerEventTest.php b/test/Timetable/TimetableManagerEventTest.php new file mode 100644 index 0000000..2709316 --- /dev/null +++ b/test/Timetable/TimetableManagerEventTest.php @@ -0,0 +1,25 @@ +assertFalse($event->hasPointInTime()); + $this->assertInstanceOf(TimetableManagerEvent::class, $event->setPointInTime($expectedPointInTime)); + $this->assertTrue($event->hasPointInTime()); + $this->assertEquals($expectedPointInTime, $event->getPointInTime()); + + } +} diff --git a/test/Value/AbstractEnumValueTest.php b/test/Value/AbstractEnumValueTest.php new file mode 100644 index 0000000..c20f6da --- /dev/null +++ b/test/Value/AbstractEnumValueTest.php @@ -0,0 +1,38 @@ +assertEquals($expectedB, $class->get()); + + try { + $class->set('FAIL'); + $this->fail('Should not have reached this expression'); + } catch (Exception $e) {} + + $this->assertEquals([$expectedA, $expectedB], $class->getOptions()); + + $class->set($expectedA); + $this->assertEquals($expectedA, $class->get()); + + } +} diff --git a/test/Value/DateValueTest.php b/test/Value/DateValueTest.php new file mode 100644 index 0000000..6f83478 --- /dev/null +++ b/test/Value/DateValueTest.php @@ -0,0 +1,23 @@ +assertEquals($exampleOne, $exampleTwo); + + } +}