From 0ca886d865dc8b763c9910dd6ce55efd9636b6f9 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Sat, 12 Oct 2013 08:34:53 -0230 Subject: [PATCH] Refactored entities. Refactored classes in `AbaLookup\Entity` namespace. The location specific classes are likely no longer needed as we are going to be using a 3rd-party maps/distance API. Added a UserType enumeration (kinda?) class that holds the types a user can be. Refactored unit tests to reflect updates to classes. Also, - Removed traces of moderator flag until we figure out what that is/will be. (#52) - Renamed sex to gender. (#63) - Certificate of Conduct now stored as the date recieved, NULL indicating that it was not recieved. (#93) - UserType class uses reflection (which is probably a bad idea). --- .../src/AbaLookup/Entity/Location.php | 133 ------------ .../src/AbaLookup/Entity/Pairing.php | 10 +- .../AbaLookup/src/AbaLookup/Entity/User.php | 192 +++++++++--------- .../src/AbaLookup/Entity/UserLocation.php | 97 --------- .../src/AbaLookup/Entity/UserType.php | 34 ++++ .../src/AbaLookup/Form/RegisterForm.php | 29 +-- .../AbaLookupTest/BaseControllerTestCase.php | 3 +- .../AbaLookupTest/Entity/LocationTest.php | 144 ------------- .../test/AbaLookupTest/Entity/PairingTest.php | 5 +- .../AbaLookupTest/Entity/ScheduleTest.php | 11 +- .../AbaLookupTest/Entity/UserLocationTest.php | 101 --------- .../test/AbaLookupTest/Entity/UserTest.php | 127 +++++++----- .../Form/ProfileEditFormTest.php | 3 +- .../AbaLookupTest/Form/RegisterFormTest.php | 40 ++-- .../View/Helper/ScheduleHelperTest.php | 13 +- .../view/aba-lookup/users/profile.phtml | 15 +- 16 files changed, 266 insertions(+), 691 deletions(-) delete mode 100644 module/AbaLookup/src/AbaLookup/Entity/Location.php delete mode 100644 module/AbaLookup/src/AbaLookup/Entity/UserLocation.php create mode 100644 module/AbaLookup/src/AbaLookup/Entity/UserType.php delete mode 100644 module/AbaLookup/test/AbaLookupTest/Entity/LocationTest.php delete mode 100644 module/AbaLookup/test/AbaLookupTest/Entity/UserLocationTest.php diff --git a/module/AbaLookup/src/AbaLookup/Entity/Location.php b/module/AbaLookup/src/AbaLookup/Entity/Location.php deleted file mode 100644 index 190bab9..0000000 --- a/module/AbaLookup/src/AbaLookup/Entity/Location.php +++ /dev/null @@ -1,133 +0,0 @@ -name = $name; - $this->enabled = TRUE; - } - - /** - * Sets the name of the location - * - * @param string $name The name of the location. - * @throws InvalidArgumentException - * @return $this - */ - public function setName($name) - { - if (!isset($name) || !is_string($name) || !$name) { - throw new InvalidArgumentException(); - } - $this->name = $name; - return $this; - } - - /** - * Sets the enabled value of the location - * - * @param bool $enabled Whether this location is to be enabled. - * @throws InvalidArgumentException - * @return $this - */ - public function setEnabled($enabled) - { - if (!is_bool($enabled)) { - throw new InvalidArgumentException(); - } - $this->enabled = $enabled; - return $this; - } - - /** - * Enables the location - * - * @return $this - */ - public function enable() - { - $this->enabled = TRUE; - return $this; - } - - /** - * Disables the location - * - * @return $this - */ - public function disable() - { - $this->enabled = FALSE; - return $this; - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Returns whether the location is enabled - * - * @return bool - */ - public function isEnabled() - { - return $this->enabled; - } -} diff --git a/module/AbaLookup/src/AbaLookup/Entity/Pairing.php b/module/AbaLookup/src/AbaLookup/Entity/Pairing.php index 781fccc..9f57722 100644 --- a/module/AbaLookup/src/AbaLookup/Entity/Pairing.php +++ b/module/AbaLookup/src/AbaLookup/Entity/Pairing.php @@ -43,6 +43,8 @@ class Pairing protected $score; /** + * Whether this pairing should be excluded from results + * * @Column(type = "boolean") */ protected $excluded; @@ -52,7 +54,7 @@ class Pairing * * @param User $a The 1st user in this pairing. * @param User $a The 2nd user in this pairing. - * @param float $score The score. + * @param float $score The score for this pairing. * @throws InvalidArgumentException */ public function __construct(User $a, User $b, $score) @@ -87,9 +89,9 @@ public function setScore($score) } /** - * Sets this pairing to be excluded + * Sets whether this pairing is to be excluded from results * - * @param bool $excluded Whether this pairing should be excluded in future matching. + * @param bool $excluded This pairing should be excluded from results. * @throws InvalidArgumentException * @return $this */ @@ -135,6 +137,8 @@ public function getScore() } /** + * Returns whether this pairing is being excluded from results + * * @return bool */ public function isExcluded() diff --git a/module/AbaLookup/src/AbaLookup/Entity/User.php b/module/AbaLookup/src/AbaLookup/Entity/User.php index ff30ba4..fcb8ad3 100644 --- a/module/AbaLookup/src/AbaLookup/Entity/User.php +++ b/module/AbaLookup/src/AbaLookup/Entity/User.php @@ -26,7 +26,7 @@ class User const MINIMUM_LENGTH_DISPLAY_NAME = 1; /** - * The minimum length for users' passwords + * The minimum length for passwords */ const MINIMUM_LENGTH_PASSWORD = 8; @@ -50,16 +50,22 @@ class User protected $id; /** + * The user's display name + * * @Column(type = "string", name = "display_name") */ protected $displayName; /** + * The user's email address + * * @Column(type = "string", unique = TRUE) */ protected $email; /** + * The user's password + * * @Column(type = "string") */ protected $password; @@ -75,46 +81,55 @@ class User protected $phone; /** - * @Column(type = "boolean") + * The type of the user + * + * @see UserType The possible values for this property. + * @Column(type = "string", name = "user_type") */ - protected $therapist; + protected $userType; /** - * The sex of the user + * The gender of the user * - * The user can choose to not dicslose their sex, thus + * The user can choose to not dicslose their gender, thus * this field can be NULL. This field is either a 'M' for * male or an 'F' for female. * - * @Column(type = "string", nullable = TRUE, length = 1) + * @Column(type = "string", length = 1, nullable = TRUE) */ - protected $sex; + protected $gender; /** * Whether the user has completed their course * - * @Column(type = "boolean", name = "aba_course") + * This field can be NULL, which represents that the user has not + * yet completed the ABA training course. + * + * @Column(type = "boolean", name = "aba_course", nullable = TRUE) */ protected $abaCourse; /** - * Whether the user has recieved their certificate of conduct/vulnerable sector check + * The date on which the user last recieved their Certificate of Conduct * - * @Column(type = "boolean", name = "certificate_of_conduct") + * This field can be NULL, which represents that the user has never recieved + * their Certificate of Conduct or, in the case of a parent, the field is + * not relevant. The field is stored as the number of seconds since the UNIX epoch. + * + * @Column(type = "integer", name = "certificate_of_conduct", nullable = TRUE) */ protected $certificateOfConduct; /** - * Whether the user has verified their email address + * The user's postal code * - * @Column(type = "boolean") - */ - protected $verified; - - /** - * @Column(type = "boolean") + * The user can optionally provide their postal code to be provied the + * option of viewing/generating coarse location-based matches. Is they + * decide to not provide this field, it will be NULL. + * + * @Column(type = "string", name = "postal_code", nullable = TRUE) */ - protected $moderator; + protected $postalCode; /** * Initialise static fields @@ -130,35 +145,31 @@ public static function init() * Constructor * * @param string $displayName The display name for the user. - * @param string $email The email address of the user. - * @param string $password The password for the user. - * @param bool $therapist Is the user a therapist? - * @param string|NULL The sex of the user. - * @param bool $abaCourse Has the user completed the course. - * @param bool $certificateOfConduct Has the user recieved their certificate of conduct. + * @param string $email The email address for the user. + * @param string $password The user's password in plaintext. + * @param string $userType The type of the user. + * @param string|NULL $gender The gender of the user. + * @param bool|NULL $abaCourse Whether the user has completed the ABA training course. + * @param integer|NULL $certificateOfConduct The date on which the user last recieved their Certificate of Conduct. * @throws InvalidArgumentException */ public function __construct($displayName, $email, $password, - $therapist, - $sex = NULL, - $abaCourse = FALSE, - $certificateOfConduct = FALSE + $userType, + $gender = NULL, + $abaCourse = NULL, + $certificateOfConduct = NULL ) { - if (!isset($displayName, $email, $password) || !is_bool($therapist)) { - throw new InvalidArgumentException(); - } - $this->displayName = $displayName; - $this->email = $email; - $this->password = self::$bcrypt->create($password); - $this->phone = NULL; - $this->therapist = $therapist; - $this->sex = $sex; - $this->abaCourse = $abaCourse; - $this->certificateOfConduct = $certificateOfConduct; - $this->verified = FALSE; - $this->moderator = FALSE; + $this->setDisplayName($displayName); + $this->setEmail($email); + $this->setPassword($password); + $this->setPhone(NULL); // Default + $this->setUserType($userType); + $this->setGender($gender); + $this->setAbaCourse($abaCourse); + $this->setCertificateOfConduct($certificateOfConduct); + $this->setPostalCode(NULL); // Default } /** @@ -196,7 +207,7 @@ public function setEmail($email) /** * Sets the password for the user * - * The password passed must be in plaintext, as it will + * The password must be in plaintext when passed in, as it will * be hashed internally. * * @param string $password The plaintext password for the user. @@ -215,13 +226,13 @@ public function setPassword($password) /** * Sets the phone number for the user * - * @param int $phone The phone number for the user. + * @param int|NULL $phone The phone number for the user. * @throws InvalidArgumentException * @return $this */ public function setPhone($phone) { - if (!isset($phone) || !is_int($phone)) { + if ($phone !== NULL && !is_int($phone)) { throw new InvalidArgumentException(); } $this->phone = $phone; @@ -229,47 +240,47 @@ public function setPhone($phone) } /** - * Sets whether or not the user is a therapist + * Sets the user type * - * @param bool $therapist Whether or not the user is a therapist. + * @param string $userType The type of the user. * @throws InvalidArgumentException * @return $this */ - public function setTherapist($therapist) + public function setUserType($userType) { - if (!isset($therapist) || !is_bool($therapist)) { + if (!isset($userType) || !is_string($userType) || !$userType) { throw new InvalidArgumentException(); } - $this->therapist = $therapist; + $this->userType = $userType; return $this; } /** - * Sets the sex of the user + * Sets the gender of the user * - * @param string $sex The sex of the user (NULL, 'M', or 'F'). + * @param string|NULL $gender The gender of the user (NULL, 'M', or 'F'). * @throws InvalidArgumentException * @return $this */ - public function setSex($sex) + public function setGender($gender) { - if ($sex !== NULL && $sex !== 'M' && $sex !== 'F') { + if ($gender !== NULL && $gender !== 'M' && $gender !== 'F') { throw new InvalidArgumentException(); } - $this->sex = $sex; + $this->gender = $gender; return $this; } /** - * Sets whether the user has completed the course + * Sets whether the user has completed the ABA training course * - * @param bool $abaCourse Whether or not the user has completed their course. + * @param bool|NULL $abaCourse Whether or not the user has completed their course. * @throws InvalidArgumentException * @return $this */ public function setAbaCourse($abaCourse) { - if (!isset($abaCourse) || !is_bool($abaCourse)) { + if ($abaCourse !== NULL && !is_bool($abaCourse)) { throw new InvalidArgumentException(); } $this->abaCourse = $abaCourse; @@ -277,15 +288,18 @@ public function setAbaCourse($abaCourse) } /** - * Sets whether the user has recieved their certificate of conduct + * Sets the date on which the user last recieved their certificate of conduct + * + * The {@code $certificateOfConduct} field is stored as the number of seconds + * since the UNIX epoch. As such, the given value must be an integer. * - * @param bool $certificateOfConduct Whether the user has recieved their certificate of conduct. + * @param int|NULL $certificateOfConduct The date on which the user last recieved their certificate of conduct. * @throws InvalidArgumentException * @return $this */ public function setCertificateOfConduct($certificateOfConduct) { - if (!isset($certificateOfConduct) || !is_bool($certificateOfConduct)) { + if ($certificateOfConduct !== NULL && !is_int($certificateOfConduct)) { throw new InvalidArgumentException(); } $this->certificateOfConduct = $certificateOfConduct; @@ -293,34 +307,18 @@ public function setCertificateOfConduct($certificateOfConduct) } /** - * Sets whether or not the user has been verified - * - * @param bool $verified Whether or not the user has been verified. - * @throws InvalidArgumentException - * @return $this - */ - public function setVerified($verified) - { - if (!isset($verified) || !is_bool($verified)) { - throw new InvalidArgumentException(); - } - $this->verified = $verified; - return $this; - } - - /** - * Sets if the user is or is not a moderator + * Sets the postal code for the user * - * @param bool $moderator Whether the user is a moderator or not. + * @param string|NULL $postalCode The postal code for the user. * @throws InvalidArgumentException * @return $this */ - public function setModerator($moderator) + public function setPostalCode($postalCode) { - if (!isset($moderator) || !is_bool($moderator)) { + if ($postalCode !== NULL && !is_string($postalCode)) { throw new InvalidArgumentException(); } - $this->moderator = $moderator; + $this->postalCode = $postalCode; return $this; } @@ -376,23 +374,23 @@ public function getPhone() } /** - * @return bool + * @return string */ - public function isTherapist() + public function getUserType() { - return $this->therapist; + return $this->userType; } /** - * @return string + * @return string|NULL */ - public function getSex() + public function getGender() { - return $this->sex; + return $this->gender; } /** - * @return bool + * @return bool|NULL */ public function getAbaCourse() { @@ -400,27 +398,19 @@ public function getAbaCourse() } /** - * @return bool + * @return int|NULL */ - public function hasCertificateOfConduct() + public function getCertificateOfConduct() { return $this->certificateOfConduct; } /** - * @return bool - */ - public function isVerified() - { - return $this->verified; - } - - /** - * @return bool + * @return string|NULL */ - public function isModerator() + public function getPostalCode() { - return $this->moderator; + return $this->postalCode; } } diff --git a/module/AbaLookup/src/AbaLookup/Entity/UserLocation.php b/module/AbaLookup/src/AbaLookup/Entity/UserLocation.php deleted file mode 100644 index dd69725..0000000 --- a/module/AbaLookup/src/AbaLookup/Entity/UserLocation.php +++ /dev/null @@ -1,97 +0,0 @@ -user = $user; - $this->location = $location; - } - - /** - * Sets the user - * - * @param $user The user object. - * @return $this - */ - public function setUser(User $user) - { - $this->user = $user; - return $this; - } - - /** - * Sets the location for the user - * - * @param $location The location object. - * @return $this - */ - public function setLocation(Location $location) - { - $this->location = $location; - return $this; - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @return User - */ - public function getUser() - { - return $this->user; - } - - /** - * @return Location - */ - public function getLocation() - { - return $this->location; - } -} diff --git a/module/AbaLookup/src/AbaLookup/Entity/UserType.php b/module/AbaLookup/src/AbaLookup/Entity/UserType.php new file mode 100644 index 0000000..d97dd3f --- /dev/null +++ b/module/AbaLookup/src/AbaLookup/Entity/UserType.php @@ -0,0 +1,34 @@ +getConstants(); + foreach ($constants as $k => $v) { + if ($v === $value) { + return TRUE; + } + } + return FALSE; + } +} diff --git a/module/AbaLookup/src/AbaLookup/Form/RegisterForm.php b/module/AbaLookup/src/AbaLookup/Form/RegisterForm.php index 06b8d36..2a1b34f 100644 --- a/module/AbaLookup/src/AbaLookup/Form/RegisterForm.php +++ b/module/AbaLookup/src/AbaLookup/Form/RegisterForm.php @@ -4,6 +4,7 @@ use AbaLookup\Entity\User, + AbaLookup\Entity\UserType, Zend\Filter\Digits, Zend\Filter\StringTrim, Zend\Form\Exception\DomainException, @@ -28,7 +29,7 @@ class RegisterForm extends Form const ELEMENT_NAME_CONFIRM_PASSWORD = 'confirm-password'; const ELEMENT_NAME_PHONE_NUMBER = 'phone-number'; const ELEMENT_NAME_USER_TYPE = 'user-type'; - const ELEMENT_NAME_SEX = 'sex'; + const ELEMENT_NAME_GENDER = 'gender'; const ELEMENT_NAME_ABA_COURSE = 'aba-course'; const ELEMENT_NAME_CERTIFICATE_OF_CONDUCT = 'certificate-of-conduct'; @@ -48,8 +49,8 @@ public function __construct() 'label' => 'Parent or therapist', 'empty_option' => 'Please choose parent or therapist', 'value_options' => [ - 0 => 'Parent', - 1 => 'Therapist', + UserType::TYPE_PARENT => 'Parent', + UserType::TYPE_ABA_THERAPIST => 'Therapist', ], ], 'attributes' => [ @@ -113,12 +114,12 @@ public function __construct() 'label' => 'Your phone number (optional)' ], ]); - // Sex + // Gender $this->add([ - 'name' => self::ELEMENT_NAME_SEX, + 'name' => self::ELEMENT_NAME_GENDER, 'type' => 'select', 'options' => [ - 'label' => 'Sex', + 'label' => 'Gender', 'value_options' => [ 'Undisclosed', 'M' => 'Male', @@ -126,7 +127,7 @@ public function __construct() ], ], 'attributes' => [ - 'id' => self::ELEMENT_NAME_SEX, + 'id' => self::ELEMENT_NAME_GENDER, 'value' => 0 ], ]); @@ -151,7 +152,7 @@ public function __construct() ], 'options' => [ 'label' => 'Certificate of conduct', - 'checked_value' => TRUE + 'checked_value' => 0 ], ]); // Submit @@ -253,10 +254,10 @@ protected function isUserTypeValid() $userType = $this->data[self::ELEMENT_NAME_USER_TYPE]; // Is valid? $isValid = isset($userType) - && (new NotEmpty())->isValid($userType) + && UserType::contains($userType); ; if (!$isValid) { - $this->message = 'You must specify either parent or therapist.'; + $this->message = 'You must choose a user type.'; } return $isValid; } @@ -357,7 +358,7 @@ public function getUser() $password = $this->data[self::ELEMENT_NAME_PASSWORD]; $phone = $this->data[self::ELEMENT_NAME_PHONE_NUMBER]; $userType = $this->data[self::ELEMENT_NAME_USER_TYPE]; - $sex = $this->data[self::ELEMENT_NAME_SEX]; + $gender = $this->data[self::ELEMENT_NAME_GENDER]; $abaCourse = $this->data[self::ELEMENT_NAME_ABA_COURSE]; $certificateOfConduct = $this->data[self::ELEMENT_NAME_CERTIFICATE_OF_CONDUCT]; // Create and return a new user @@ -365,10 +366,10 @@ public function getUser() $displayName, $email, $password, - (bool) $userType, - $sex, + $userType, + $gender, (bool) $abaCourse, - (bool) $certificateOfConduct + $certificateOfConduct ); if ($phone) { // The user entered a phone number diff --git a/module/AbaLookup/test/AbaLookupTest/BaseControllerTestCase.php b/module/AbaLookup/test/AbaLookupTest/BaseControllerTestCase.php index 99fe867..a919650 100644 --- a/module/AbaLookup/test/AbaLookupTest/BaseControllerTestCase.php +++ b/module/AbaLookup/test/AbaLookupTest/BaseControllerTestCase.php @@ -5,6 +5,7 @@ use AbaLookup\Entity\Schedule, AbaLookup\Entity\User, + AbaLookup\Entity\UserType, PHPUnit_Framework_Exception, ReflectionProperty, SimpleXMLElement, @@ -98,7 +99,7 @@ public function mockEntityManager(User $user, Schedule $schedule) public function mockUser() { // Mock user - $user = new User('Jane', 'jane@email.com', 'password', TRUE, 'F', TRUE, TRUE); + $user = new User('Jane', 'jane@email.com', 'password', UserType::TYPE_PARENT); $reflectionProperty = new ReflectionProperty('AbaLookup\Entity\User', 'id'); $reflectionProperty->setAccessible(TRUE); $reflectionProperty->setValue($user, 1); diff --git a/module/AbaLookup/test/AbaLookupTest/Entity/LocationTest.php b/module/AbaLookup/test/AbaLookupTest/Entity/LocationTest.php deleted file mode 100644 index 09c2d61..0000000 --- a/module/AbaLookup/test/AbaLookupTest/Entity/LocationTest.php +++ /dev/null @@ -1,144 +0,0 @@ -name = 'Paradise'; - $this->location = new Location($this->name); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfNullPassedToConstructor() - { - new Location(NULL); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfNonStringPassedToConstructor() - { - new Location(FALSE); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfEmptyStringPassedToConstructor() - { - new Location(''); - } - - public function testGetName() - { - $this->assertEquals($this->name, $this->location->getName()); - } - - /** - * @depends testGetName - */ - public function testSetName() - { - $name = 'Placentia'; - $this->assertEquals($name, $this->location->setName($name)->getName()); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfSetNamePassedNull() - { - $this->location->setName(NULL); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfSetNamePassedNonString() - { - $this->location->setName(3); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfSetNamePassedEmptyString() - { - $this->location->setName(''); - } - - public function testIsEnabled() - { - $this->assertTrue($this->location->isEnabled()); - } - - /** - * @depends testIsEnabled - */ - public function testEnable() - { - $this->location->enable(); - $this->assertTrue($this->location->isEnabled()); - } - - /** - * @depends testIsEnabled - */ - public function testDisable() - { - $this->location->disable(); - $this->assertFalse($this->location->isEnabled()); - } - - /** - * @depends testIsEnabled - */ - public function testSetEnabledTrue() - { - $this->location->setEnabled(TRUE); - $this->assertTrue($this->location->isEnabled()); - } - - /** - * @depends testIsEnabled - */ - public function testSetEnabledFalse() - { - $this->location->setEnabled(FALSE); - $this->assertFalse($this->location->isEnabled()); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsThrownIfSetEnabledPassedNonBool() - { - $this->location->setEnabled(''); - } -} diff --git a/module/AbaLookup/test/AbaLookupTest/Entity/PairingTest.php b/module/AbaLookup/test/AbaLookupTest/Entity/PairingTest.php index a910f39..4e64c17 100644 --- a/module/AbaLookup/test/AbaLookupTest/Entity/PairingTest.php +++ b/module/AbaLookup/test/AbaLookupTest/Entity/PairingTest.php @@ -5,6 +5,7 @@ use AbaLookup\Entity\Pairing, AbaLookup\Entity\User, + AbaLookup\Entity\UserType, PHPUnit_Framework_TestCase ; @@ -34,8 +35,8 @@ class PairingTest extends PHPUnit_Framework_TestCase */ public function setUp() { - $this->a = new User('John Smith', 'johns@email.com', 'password', FALSE, 'M', FALSE, TRUE); - $this->b = new User('Jane Smith', 'janes@email.com', 'password', TRUE, 'F', TRUE, TRUE); + $this->a = new User('John Smith', 'johns@email.com', 'password', UserType::TYPE_ABA_THERAPIST); + $this->b = new User('Jane Smith', 'janes@email.com', 'password', UserType::TYPE_PARENT); $this->score = 3.0; $this->pairing = new Pairing($this->a, $this->b, $this->score); } diff --git a/module/AbaLookup/test/AbaLookupTest/Entity/ScheduleTest.php b/module/AbaLookup/test/AbaLookupTest/Entity/ScheduleTest.php index 032fddc..c223bec 100644 --- a/module/AbaLookup/test/AbaLookupTest/Entity/ScheduleTest.php +++ b/module/AbaLookup/test/AbaLookupTest/Entity/ScheduleTest.php @@ -5,6 +5,7 @@ use AbaLookup\Entity\Schedule, AbaLookup\Entity\User, + AbaLookup\Entity\UserType, PHPUnit_Framework_TestCase ; @@ -28,15 +29,7 @@ class ScheduleTest extends PHPUnit_Framework_TestCase */ public function setUp() { - $this->user = new User( - 'John Smith', - 'js@email.com', - 'password', - FALSE, - NULL, - FALSE, - FALSE - ); + $this->user = new User('John Smith', 'js@email.com', 'password', UserType::TYPE_PARENT); $this->schedule = new Schedule($this->user); } diff --git a/module/AbaLookup/test/AbaLookupTest/Entity/UserLocationTest.php b/module/AbaLookup/test/AbaLookupTest/Entity/UserLocationTest.php deleted file mode 100644 index 01eae23..0000000 --- a/module/AbaLookup/test/AbaLookupTest/Entity/UserLocationTest.php +++ /dev/null @@ -1,101 +0,0 @@ -displayName = 'Jane'; - $this->email = 'jane@email.com'; - $this->password = 'password'; - $this->therapist = TRUE; - $this->sex = 'F'; - $this->abaCourse = TRUE; - $this->certificateOfConduct = TRUE; - $this->user = new User( - $this->displayName, - $this->email, - $this->password, - $this->therapist, - $this->sex, - $this->abaCourse, - $this->certificateOfConduct - ); - $this->name = 'Somewhere'; - $this->location = new Location($this->name); - $this->ul = new UserLocation($this->user, $this->location); - } - - public function testGetUser() - { - $this->assertEquals($this->user, $this->ul->getUser()); - } - - /** - * @depends testGetUser - */ - public function testSetUser() - { - $user = new User('John', 'someone@email.com', 'password', FALSE, NULL, FALSE, FALSE); - $this->assertEquals($user, $this->ul->setUser($user)->getUser()); - } - - public function testGetLocation() - { - $this->assertEquals($this->location, $this->ul->getLocation()); - } - - /** - * @depends testGetLocation - */ - public function testSetLocation() - { - $location = new Location('Barçelona'); - $this->assertEquals($location, $this->ul->setLocation($location)->getLocation()); - } -} diff --git a/module/AbaLookup/test/AbaLookupTest/Entity/UserTest.php b/module/AbaLookup/test/AbaLookupTest/Entity/UserTest.php index 0fa0861..2efe463 100644 --- a/module/AbaLookup/test/AbaLookupTest/Entity/UserTest.php +++ b/module/AbaLookup/test/AbaLookupTest/Entity/UserTest.php @@ -4,6 +4,7 @@ use AbaLookup\Entity\User, + AbaLookup\Entity\UserType, PHPUnit_Framework_TestCase ; @@ -24,10 +25,11 @@ class UserTest extends PHPUnit_Framework_TestCase protected $email; protected $password; protected $phone; - protected $therapist; - protected $sex; + protected $userType; + protected $gender; protected $abaCourse; protected $certificateOfConduct; + protected $postalCode; /** * Resets for isolation @@ -38,20 +40,22 @@ public function setUp() $this->email = 'jane@email.com'; $this->password = 'password'; $this->phone = 7095551234; - $this->therapist = TRUE; - $this->sex = 'F'; + $this->userType = UserType::TYPE_ABA_THERAPIST; + $this->gender = 'F'; $this->abaCourse = TRUE; - $this->certificateOfConduct = TRUE; + $this->certificateOfConduct = time(); + $this->postalCode = 'A1B 3X9'; $this->user = new User( $this->displayName, $this->email, $this->password, - $this->therapist, - $this->sex, + $this->userType, + $this->gender, $this->abaCourse, $this->certificateOfConduct ); $this->user->setPhone($this->phone); + $this->user->setPostalCode($this->postalCode); } /** @@ -59,7 +63,7 @@ public function setUp() */ public function testExceptionIsThrownIfConstructorPassedNullDisplayName() { - new User(NULL, $this->email, $this->password, $this->therapist); + new User(NULL, $this->email, $this->password, $this->userType); } /** @@ -67,7 +71,7 @@ public function testExceptionIsThrownIfConstructorPassedNullDisplayName() */ public function testExceptionIsThrownIfConstructorPassedNullEmail() { - new User($this->displayName, NULL, $this->password, $this->therapist); + new User($this->displayName, NULL, $this->password, $this->userType); } /** @@ -75,7 +79,7 @@ public function testExceptionIsThrownIfConstructorPassedNullEmail() */ public function testExceptionIsThrownIfConstructorPassedNullPassword() { - new User($this->displayName, $this->email, NULL, $this->therapist); + new User($this->displayName, $this->email, NULL, $this->userType); } /** @@ -197,53 +201,53 @@ public function testSetPhone() /** * @expectedException InvalidArgumentException */ - public function testExceptionIsThrownIfNonIntegerNumberPassed() + public function testExceptionIsThrownIfNonIntegerPhoneNumberPassed() { $this->user->setPhone(''); } - public function testIsTherapist() + public function testGetUserType() { - $this->assertTrue($this->user->isTherapist()); + $this->assertEquals($this->userType, $this->user->getUserType()); } /** - * @depends testIsTherapist + * @depends testGetUserType */ - public function testSetTherapist() + public function testSetUserType() { - $this->user->setTherapist(FALSE); - $this->assertFalse($this->user->isTherapist()); + $this->user->setUserType(UserType::TYPE_PARENT); + $this->assertEquals($this->user->getUserType(), UserType::TYPE_PARENT); } /** * @expectedException InvalidArgumentException */ - public function testExceptionIsThrownIfNonBoolTherapistValueGiven() + public function testExceptionIsThrownIfNonStringUserTypeGiven() { - $this->user->setTherapist(NULL); + $this->user->setUserType(NULL); } - public function testGetSex() + public function testGetGender() { - $this->assertEquals($this->sex, $this->user->getSex()); + $this->assertEquals($this->gender, $this->user->getGender()); } /** - * @depends testGetSex + * @depends testGetGender */ - public function testSetSex() + public function testSetGender() { - $this->user->setSex(NULL); - $this->assertNull($this->user->getSex()); + $this->user->setGender(NULL); + $this->assertNull($this->user->getGender()); } /** * @expectedException InvalidArgumentException */ - public function testExceptionIsThrownIfInvalidSexPassed() + public function testExceptionIsThrownIfInvalidGenderPassed() { - $this->user->setSex(3); + $this->user->setGender(3); } public function testGetAbaCourse() @@ -260,6 +264,15 @@ public function testSetAbaCourse() $this->assertFalse($this->user->getAbaCourse()); } + /** + * @depends testGetAbaCourse + */ + public function testAbaCourseCanBeNull() + { + $this->user->setAbaCourse(NULL); + $this->assertNull($this->user->getAbaCourse()); + } + /** * @expectedException InvalidArgumentException */ @@ -268,69 +281,75 @@ public function testExceptionIsThrownIfNonBoolAbaCoursePassed() $this->user->setAbaCourse(3); } - public function testHasCertificateOfConduct() + public function testGetCertificateOfConduct() { - $this->assertTrue($this->user->hasCertificateOfConduct()); + $this->assertEquals($this->certificateOfConduct, $this->user->getCertificateOfConduct()); } /** - * @depends testHasCertificateOfConduct + * @depends testGetCertificateOfConduct */ public function testSetCertificateOfConduct() { - $this->user->setCertificateOfConduct(FALSE); - $this->assertFalse($this->user->hasCertificateOfConduct()); + $now = time(); + $this->user->setCertificateOfConduct($now); + $this->assertEquals($now, $this->user->getCertificateOfConduct()); } /** - * @expectedException InvalidArgumentException + * @depends testGetCertificateOfConduct */ - public function testExceptionIsThrownIfNonBoolCertificateOfConduct() + public function testSetCertificateOfConductCanBeNull() { - $this->user->setCertificateOfConduct(3); + $this->user->setCertificateOfConduct(NULL); + $this->assertNull($this->user->getCertificateOfConduct()); } - public function testIsVerified() + /** + * @expectedException InvalidArgumentException + */ + public function testExceptionIsThrownIfCertificateOfConductPassedNonNullAndNonInteger() { - $this->assertFalse($this->user->isVerified()); + $this->user->setCertificateOfConduct(''); } - /** - * @depends testIsVerified - */ - public function testSetVerified() + public function testGetPostalCode() { - $this->user->setVerified(TRUE); - $this->assertTrue($this->user->isVerified()); + $this->assertEquals($this->postalCode, $this->user->getPostalCode()); } /** - * @expectedException InvalidArgumentException + * @depends testGetPostalCode */ - public function testExceptionIsThrownIfNonBoolVerified() + public function testSetPostalCode() { - $this->user->setVerified(''); + $this->postalCode = 'A1B 2C3'; + $this->user->setPostalCode($this->postalCode); + $this->assertEquals($this->postalCode, $this->user->getPostalCode()); } - public function testIsModerator() + /** + * @depends testGetPostalCode + */ + public function testPostalCodeCanBeNull() { - $this->assertFalse($this->user->isModerator()); + $this->user->setPostalCode(NULL); + $this->assertNull($this->user->getPostalCode()); } /** - * @depends testIsModerator + * @expectedException InvalidArgumentException */ - public function testSetModerator() + public function testExceptionisThrownIfSetPostalCodePassedInteger() { - $this->user->setModerator(TRUE); - $this->assertTrue($this->user->isModerator()); + $this->user->setPostalCode(3); } /** * @expectedException InvalidArgumentException */ - public function testExceptionIsThrownIfNonBoolModerator() + public function testExceptionIsThrownIfSetPostalCodePassedBoolean() { - $this->user->setModerator(NULL); + $this->user->setPostalCode(FALSE); } } diff --git a/module/AbaLookup/test/AbaLookupTest/Form/ProfileEditFormTest.php b/module/AbaLookup/test/AbaLookupTest/Form/ProfileEditFormTest.php index e225af9..8e41441 100644 --- a/module/AbaLookup/test/AbaLookupTest/Form/ProfileEditFormTest.php +++ b/module/AbaLookup/test/AbaLookupTest/Form/ProfileEditFormTest.php @@ -4,6 +4,7 @@ use AbaLookup\Entity\User, + AbaLookup\Entity\UserType, AbaLookup\Form\ProfileEditForm, PHPUnit_Framework_TestCase ; @@ -42,7 +43,7 @@ protected function setFormData($displayName, */ public function setUp() { - $this->user = new User('Ramus', 'foo@bar.com', 'password', FALSE); + $this->user = new User('Ramus', 'foo@bar.com', 'password', UserType::TYPE_PARENT); $this->form = new ProfileEditForm($this->user); } diff --git a/module/AbaLookup/test/AbaLookupTest/Form/RegisterFormTest.php b/module/AbaLookup/test/AbaLookupTest/Form/RegisterFormTest.php index 7908689..95f35f5 100644 --- a/module/AbaLookup/test/AbaLookupTest/Form/RegisterFormTest.php +++ b/module/AbaLookup/test/AbaLookupTest/Form/RegisterFormTest.php @@ -3,6 +3,7 @@ namespace AbaLookupTest; use + AbaLookup\Entity\UserType, AbaLookup\Form\RegisterForm, PHPUnit_FrameWork_TestCase ; @@ -22,10 +23,10 @@ protected function setFormData($displayName, $password = 'password', $confirmPassword = 'password', $phoneNumber = '7095551234', - $userType = '0', - $sex = NULL, + $userType = UserType::TYPE_PARENT, + $gender = NULL, $abaCourse = FALSE, - $certificateOfConduct = FALSE + $certificateOfConduct = 0 ) { $this->form->setData([ RegisterForm::ELEMENT_NAME_DISPLAY_NAME => $displayName, @@ -34,7 +35,7 @@ protected function setFormData($displayName, RegisterForm::ELEMENT_NAME_CONFIRM_PASSWORD => $confirmPassword, RegisterForm::ELEMENT_NAME_PHONE_NUMBER => $phoneNumber, RegisterForm::ELEMENT_NAME_USER_TYPE => $userType, - RegisterForm::ELEMENT_NAME_SEX => $sex, + RegisterForm::ELEMENT_NAME_GENDER => $gender, RegisterForm::ELEMENT_NAME_ABA_COURSE => $abaCourse, RegisterForm::ELEMENT_NAME_CERTIFICATE_OF_CONDUCT => $certificateOfConduct ]); @@ -62,8 +63,8 @@ public function testValidDataDoesValidate() $emailAddress = 'jdoe@email.com'; $password = 'password'; $phoneNumber = '7095551234'; - $userType = '0'; // Parent - $sex = 'F'; + $userType = UserType::TYPE_PARENT; + $gender = 'F'; $this->setFormData( $displayName, $emailAddress, @@ -71,7 +72,7 @@ public function testValidDataDoesValidate() $password, $phoneNumber, $userType, - $sex + $gender ); $this->assertTrue($this->form->isValid()); $user = $this->form->getUser(); @@ -79,9 +80,9 @@ public function testValidDataDoesValidate() $this->assertEquals($displayName, $user->getDisplayName()); $this->assertEquals($emailAddress, $user->getEmail()); $this->assertTrue($user->verifyPassword($password)); - $this->assertFalse($user->isTherapist()); + $this->assertEquals(UserType::TYPE_PARENT, $user->getUserType()); $this->assertTrue(((int) $phoneNumber) === $user->getPhone()); - $this->assertEquals($sex, $user->getSex()); + $this->assertEquals($gender, $user->getGender()); } public function testDisplayNameWithNonEnglishCharactersDoesValidate() @@ -206,6 +207,19 @@ public function testPhoneNumberWithSpacesDoesValidate() $this->assertTrue($this->form->isValid()); } + public function testRandomUserTypeDoesNotValidate() + { + $this->setFormData( + 'John Doe', + 'jdoe@email.com', + 'password', + 'password', + '7095551234', + 'this is random' + ); + $this->assertFalse($this->form->isValid()); + } + public function testNullUserTypeDoesNotValidate() { $this->setFormData( @@ -219,7 +233,7 @@ public function testNullUserTypeDoesNotValidate() $this->assertFalse($this->form->isValid()); } - public function testUndisclosedSexDoesValidate() + public function testUndisclosedGenderDoesValidate() { $this->setFormData( 'John Doe', @@ -227,13 +241,13 @@ public function testUndisclosedSexDoesValidate() 'password', 'password', '7095551234', - '1', + UserType::TYPE_ABA_THERAPIST, 'Undisclosed' ); $this->assertTrue($this->form->isValid()); } - public function testNullSexDoesValidate() + public function testNullGenderDoesValidate() { $this->setFormData( 'John Doe', @@ -241,7 +255,7 @@ public function testNullSexDoesValidate() 'password', 'password', '7095551234', - '1', + UserType::TYPE_ABA_THERAPIST, NULL ); $this->assertTrue($this->form->isValid()); diff --git a/module/AbaLookup/test/AbaLookupTest/View/Helper/ScheduleHelperTest.php b/module/AbaLookup/test/AbaLookupTest/View/Helper/ScheduleHelperTest.php index 14b6d77..47b4cee 100644 --- a/module/AbaLookup/test/AbaLookupTest/View/Helper/ScheduleHelperTest.php +++ b/module/AbaLookup/test/AbaLookupTest/View/Helper/ScheduleHelperTest.php @@ -5,6 +5,7 @@ use AbaLookup\Entity\Schedule, AbaLookup\Entity\User, + AbaLookup\Entity\UserType, AbaLookup\View\Helper\ScheduleHelper, PHPUnit_Framework_TestCase ; @@ -17,15 +18,9 @@ class ScheduleHelperTest extends PHPUnit_Framework_TestCase public function setUp() { $this->helper = new ScheduleHelper(); - $this->schedule = new Schedule(new User( - 'John Smith', - 'js@email.com', - 'password', - FALSE, - NULL, - FALSE, - FALSE - )); + $this->schedule = new Schedule( + new User('John Smith', 'js@email.com', 'password', UserType::TYPE_PARENT) + ); $this->helper->__invoke($this->schedule); } diff --git a/module/AbaLookup/view/aba-lookup/users/profile.phtml b/module/AbaLookup/view/aba-lookup/users/profile.phtml index 10c3ebb..a4e7fad 100644 --- a/module/AbaLookup/view/aba-lookup/users/profile.phtml +++ b/module/AbaLookup/view/aba-lookup/users/profile.phtml @@ -16,24 +16,21 @@

Phone number

user->getPhone() ? $this->user->getPhone() : "n/a"; ?>

-

Verification status

-

user->isVerified()) ? "Verified" : "You need to verify your email address"; ?>

+ user->getUserType() === \ABALookup\Entity\UserType::TYPE_ABA_THERAPIST): ?> - user->isTherapist()): ?> - -

Sex

+

Gender

user->getSex(); - if (!isset($sex)) { + $gender = $this->user->getGender(); + if (!isset($gender)) { echo "Undisclosed"; } else { - echo ($sex == "F") ? "Female" : "Male"; + echo ($gender == "F") ? "Female" : "Male"; } ?>

Certificate of conduct

-

user->hasCertificateOfConduct()) ? "Accepted" : "You may need to obtain a Certificate of Conduct"; ?>

+

user->getCertificateOfConduct(); ?>

ABA therapy course

user->getAbaCourse()) ? "Completed" : "Not yet completed"; ?>