public function testInvalidUserDataIdSkillAssocsCreate() { $validSkillId = 11; $invalidUserDataId = -3; $s1 = new SkillAssocs($invalidUserDataId, $validSkillId); $this->assertTrue(!empty($s1->getError('userDataId')) && strcmp(Messages::getError('USER_DATA_ID_INVALID'), $s1->getError('userDataId')) == 0, 'It should have a userDataId error if the userDataId is invalid'); }
public function testInvalidCreatorIdRobotAssocCreate() { $validRobotId = 1; $invalidCreatorId = -20; $s1 = new RobotAssoc($validRobotId, $invalidCreatorId); $this->assertTrue(!empty($s1->getError('creatorId')) && strcmp(Messages::getError('CREATOR_ID_INVALID'), $s1->getError('creatorId')) == 0, 'It should have a creatorId error if the creatorId is invalid'); }
public function setError($errorName, $errorValue) { // Sets a particular error value and increments error count if (!isset($this->errors, $errorName)) { $this->errors[$errorName] = Messages::getError($errorValue); $this->errorCount++; } }
public function setError($errorName, $errorValue) { // Set a particular error value and increments error count if (!array_key_exists($errorName, $this->errors)) { $this->errors[$errorName] = Messages::getError($errorValue); $this->errorCount++; } }
public function testInvalidCreatorRobotDataCreate() { $validRobotName = "TARS"; $invalidCreators = array("-2"); $validStatus = "in-development"; $s1 = new RobotData(array("robot_name" => $validRobotName, "creators" => $invalidCreators, "status" => $validStatus)); $this->assertTrue(!empty($s1->getError('creator')) && strcmp(Messages::getError('ROBOT_CREATOR_INVALID'), $s1->getError('creator')) == 0, 'It should have a creator error if the creator id is invalid'); }
public function testInsertDuplicateRobotData() { $myDb = DBMaker::create('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini'); $beforeCount = count(RobotDataDB::getRobotDataBy()); $robotDataCopy = RobotDataDB::getRobotDataBy('robotId', 2); $robotDataCopy = $robotDataCopy[0]; $this->assertEquals(0, $robotDataCopy->getErrorCount(), 'The robot data copy object should have no errors'); $dupRobotData = RobotDataDB::addRobotData($robotDataCopy); $afterCount = count(RobotDataDB::getRobotDataBy()); $this->assertTrue(!empty($dupRobotData->getError('robotId')) && strcmp(Messages::getError('ROBOT_DATA_INVALID'), $dupRobotData->getError('robotId')) == 0, 'It should have a robotDataId error if the robot data is a duplicate'); $this->assertEquals($afterCount, $beforeCount, 'There should be no additional robot data entries after the insertion attempt'); }
public function testInsertDuplicateRobotAssoc() { $myDB = DBMaker::create('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini'); $beforeCount = count(RobotAssocsDB::getRobotAssocsBy()); $robotAssocCopy = RobotAssocsDB::getRobotAssocsRowsBy('robotAssocId', 2); $robotAssocCopy = $robotAssocCopy[0]; $s1 = new RobotAssoc($robotAssocCopy); $dupRobotAssoc = RobotAssocsDB::addRobotAssoc($s1); $afterCount = count(RobotAssocsDB::getRobotAssocsBy()); $this->assertTrue(!empty($dupRobotAssoc->getError('robotAssocId')) && strcmp(Messages::getError('ROBOT_ASSOC_INVALID'), $s1->getError('robotAssocId')) == 0, 'It should have a robotAssocId error if the robot association is a duplicate'); $this->assertEquals($afterCount, $beforeCount, 'There should be no additional robot association entries after the insertion attempt'); }
?> <h2>It should set errors from a file</h2> <?php Messages::setErrors("../resources/errors_English.txt"); echo "LAST_NAME_TOO_SHORT: " . Messages::getError("LAST_NAME_TOO_SHORT") . "<br>"; echo "EMAIL_INVALID: " . Messages::getError("EMAIL_INVALID") . "<br>"; echo "LAST_NAME_INVALID: " . Messages::getError("LAST_NAME_HAS_INVALID_CHARS") . "<br>"; echo empty(Messages::getError("LAST_NAME_TOO_SHORT")) ? "Failed: it did not set LAST_NAME_TOO_SHORT from file" : ""; ?> <h2>It should allow reset</h2> <?php Messages::reset(); echo "LAST_NAME_TOO_SHORT: " . Messages::getError("LAST_NAME_TOO_SHORT") . "<br>"; echo "EMAIL_INVALID: " . Messages::getError("EMAIL_INVALID") . "<br>"; echo "LAST_NAME_HAS_INVALID_CHARS: " . Messages::getError("LAST_NAME_HAS_INVALID_CHARS") . "<br>"; ?> <h2>It should allow change of locale</h2> <?php Messages::$locale = 'Spanish'; Messages::reset(); echo "LAST_NAME_TOO_SHORT: " . Messages::getError("LAST_NAME_TOO_SHORT") . "<br>"; echo "EMAIL_INVALID: " . Messages::getError("EMAIL_INVALID") . "<br>"; echo "LAST_NAME_HAS_INVALID_CHARS: " . Messages::getError("LAST_NAME_HAS_INVALID_CHARS") . "<br>"; ?> </body> </html>
public function setError($errorName, $errorValue) { $this->errors[$errorName] = Messages::getError($errorValue); $this->errorCount++; }
public function testHasNoMessage() { Messages::reset(); $errorMessage = Messages::getError("GIANTS_ARE_HERE"); $this->assertTrue(empty($errorMessage), 'It should not have an error messages for giants'); }
public function testInvalidSkillName() { $invalidTest = array("skill_name" => "compooter-vision"); $s1 = new Skill($invalidTest); $this->assertTrue(!empty($s1->getError('skill_name')) && strcmp(Messages::getError('SKILL_AREA_INVALID'), $s1->getError('skill_name')) == 0, 'It should have a skill_name error if the name is invalid'); }
public function setError($name, $error) { if (!array_key_exists($name, $this->errors)) { $this->errors[$name] = Messages::getError($error); $this->hasErrors = true; } }
<?php include_once "../models/Messages.class.php"; ?> <h2>It should set errors from a file</h2> <?php Messages::setErrors("../resources/errors_English.txt"); echo "LAST_NAME_TOO_SHORT: " . Messages::getError("LAST_NAME_TOO_SHORT") . "<br>"; echo "EMAIL_INVALID: " . Messages::getError("EMAIL_INVALID") . "<br>"; echo "LAST_NAME_INVALID: " . Messages::getError("LAST_NAME_HAS_INVALID_CHARS") . "<br>"; echo empty(Messages::getError("LAST_NAME_TOO_SHORT")) ? "Failed: it did not set LAST_NAME_TOO_SHORT from file" : ""; ?> <h2>It should allow reset</h2> <?php Messages::reset(); echo "LAST_NAME_TOO_SHORT: " . Messages::getError("LAST_NAME_TOO_SHORT") . "<br>"; echo "EMAIL_INVALID: " . Messages::getError("EMAIL_INVALID") . "<br>"; echo "LAST_NAME_HAS_INVALID_CHARS: " . Messages::getError("LAST_NAME_HAS_INVALID_CHARS") . "<br>"; ?> <h2>It should return blank for messages that don't exist</h2> <?php Messages::reset(); echo "GIANTS_ARE_HERE: " . Messages::getError("GIANTS_ARE_HERE") . "<br>"; ?> </body> </html>
<h2>It should allow change of locale</h2> <?php Messages::$locale = 'German'; Messages::reset(); echo "EMAIL_EMPTY: " . Messages::getError("EMAIL_EMPTY") . "<br>"; echo "EMAIL_INVALID: " . Messages::getError("EMAIL_INVALID") . "<br>"; echo "USER_NAME_EMPTY: " . Messages::getError("USER_NAME_EMPTY") . "<br>"; echo "USER_NAME_TOO_SHORT: " . Messages::getError("USER_NAME_TOO_SHORT") . "<br>"; echo "USER_NAME_HAS_INVALID_CHARS: " . Messages::getError("USER_NAME_HAS_INVALID_CHARS") . "<br>"; echo "SKILL_AREA_INVALID: " . Messages::getError("SKILL_AREA_INVALID") . "<br>"; echo "SKILL_LEVEL_INVALID: " . Messages::getError("SKILL_LEVEL_INVALID") . "<br>"; echo "SKILL_LEVEL_NOT_SET: " . Messages::getError("SKILL_LEVEL_NOT_SET") . "<br>"; echo "PASSWORD_EMPTY: " . Messages::getError("PASSWORD_EMPTY") . "<br>"; echo "PASSWORD_TOO_SHORT: " . Messages::getError("PASSWORD_TOO_SHORT") . "<br>"; echo "PROFILE_PIC_WRONG_TYPE: " . Messages::getError("PROFILE_PIC_WRONG_TYPE") . "<br>"; echo "HOBBY_DATE_EMPTY: " . Messages::getError("HOBBY_DATE_EMPTY") . "<br>"; echo "HOBBY_DATE_FORMAT_INVALID: " . Messages::getError("HOBBY_DATE_FORMAT_INVALID") . "<br>"; echo "HOBBY_DATE_INVALID: " . Messages::getError("HOBBY_DATE_INVALID") . "<br>"; echo "FAV_COLOR_EMPTY: " . Messages::getError("FAV_COLOR_EMPTY") . "<br>"; echo "FAV_COLOR_INVALID: " . Messages::getError("FAV_COLOR_INVALID") . "<br>"; echo "URL_INVALID: " . Messages::getError("URL_INVALID") . "<br>"; echo "PHONE_NUMBER_INVALID: " . Messages::getError("PHONE_NUMBER_INVALID") . "<br>"; echo "ROBOT_NAME_EMPTY: " . Messages::getError("ROBOT_NAME_EMPTY") . "<br>"; echo "ROBOT_CREATOR_EMPTY: " . Messages::getError("ROBOT_CREATOR_EMPTY") . "<br>"; echo "ROBOT_STATUS_EMPTY: " . Messages::getError("ROBOT_STATUS_EMPTY") . "<br>"; echo "ROBOT_STATUS_INVALID: " . Messages::getError("ROBOT_STATUS_INVALID") . "<br>"; ?> </body> </html>
public function testInsertDuplicateSkillAssoc() { $myDB = DBMaker::create('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini'); $beforeCount = count(SkillAssocsDB::getSkillAssocsBy()); $skillAssocCopy = SkillAssocsDB::getSkillAssocsRowsBy('skillAssocId', 4); $skillAssocCopy = $skillAssocCopy[0]; $s1 = new SkillAssocs($skillAssocCopy); $dupSkillAssoc = SkillAssocsDB::addSkillAssoc($s1); $afterCount = count(SkillAssocsDB::getSkillAssocsBy()); $this->assertTrue(!empty($dupSkillAssoc->getError('skillAssocId')) && strcmp(Messages::getError('SKILL_ASSOC_INVALID'), $dupSkillAssoc->getError('skillAssocId')) == 0, 'It should have a skillAssocId error if the skill association is a duplicate'); $this->assertEquals($afterCount, $beforeCount, 'There should be no additional skill associations entries after the insertion attempt'); }