public function testInvalidSkillAssocsCreate()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $invalidSkillId = 0;
     $validUserDataId = 1;
     $s1 = new SkillAssocs($validUserDataId, $invalidSkillId);
     $beforeCount = count(SkillAssocsDB::getSkillAssocsBy());
     $newSkillAssoc = SkillAssocsDB::addSkillAssoc($s1);
     $this->assertGreaterThan(0, $newSkillAssoc->getErrorCount(), 'The skill association should return with an error');
     $afterCount = count(SkillAssocsDB::getSkillAssocsBy());
     $this->assertEquals($afterCount, $beforeCount, 'The database should have no additional skill associations after insertion');
 }
 public static function updateUserData($userData)
 {
     try {
         $db = Database::getDB();
         if (is_null($userData) || $userData->getErrorCount() > 0) {
             return $userData;
         }
         $checkUserData = UserDataDB::getUserDataBy('userDataId', $userData->getUserDataId());
         if (empty($checkUserData)) {
             $userData->setError('userDataId', 'USER_DATA_DOES_NOT_EXIST');
             return $userData;
         }
         if ($userData->getErrorCount() > 0) {
             return $userData;
         }
         $query = "UPDATE UserData SET userId = :userId, user_name = :user_name, \r\n\t\t\t\t\tskill_level = :skill_level, profile_pic = :profile_pic, \r\n\t\t\t\t\tstarted_hobby = :started_hobby, fav_color = :fav_color, url = :url,\r\n\t\t\t\t\tphone = :phone\r\n\t\t\t\t\tWHERE userDataId = :userDataId";
         $statement = $db->prepare($query);
         $statement->bindValue(":userId", $userData->getUserId());
         $statement->bindValue(":user_name", $userData->getUserName());
         $statement->bindValue(":skill_level", $userData->getSkillLevel());
         $statement->bindValue(":profile_pic", $userData->getProfilePic());
         $statement->bindValue(":started_hobby", $userData->getStartedHobby());
         $statement->bindValue(":fav_color", $userData->getFavColor());
         $statement->bindValue(":url", $userData->getUrl());
         $statement->bindValue(":phone", $userData->getPhone());
         $statement->bindValue(":userDataId", $userData->getUserDataId());
         $statement->execute();
         $statement->closeCursor();
         // Handle updates for the Skill Areas
         // 1 - Delete all existing skill associations for the user
         $deleteQuery = "DELETE from SkillAssocs WHERE userDataId = :userDataId";
         $statement = $db->prepare($deleteQuery);
         $statement->bindValue(":userDataId", $userData->getUserDataId());
         $statement->execute();
         $statement->closeCursor();
         // 2 - Add all of the new skill associations, if any
         $skillAreas = $userData->getSkillAreas();
         $userDataId = $userData->getUserDataId();
         foreach ($skillAreas as $skill_name) {
             // Translate the skill_name into a skillId first
             // skillIds start from 1, whereas array-indexing starts at 0;
             // so we add 1 to the index
             $skillId = array_search($skill_name, Skill::$SKILL_AREAS) + 1;
             $newSkillAssoc = new SkillAssocs($userDataId, $skillId);
             SkillAssocsDB::addSkillAssoc($newSkillAssoc);
         }
     } catch (Exception $e) {
         $userData->setError('userDataId', 'USER_DATA_COULD_NOT_BE_UPDATED');
     }
     return $userData;
 }
 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');
 }