Ejemplo n.º 1
0
 public function testOpenConnectionToInvalidDatabase()
 {
     ob_start();
     DBMaker::delete('ptest1');
     Database::clearDB();
     $db = Database::getDB($dbName = 'ptest1', $configPath = "C:" . DIRECTORY_SEPARATOR . "xampp" . DIRECTORY_SEPARATOR . "myConfig.ini");
     $output = ob_get_clean();
     $this->assertNull($db, 'It should not create a connection to a database that does not exist');
     $this->assertFalse(empty($output), "It should produce error messages when database does not exist");
 }
Ejemplo n.º 2
0
 public function testGetSkillsBySkillId()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $skills = SkillsDB::getSkillsBy('skillId', 9);
     $this->assertEquals(count($skills), 1, 'The database should return exactly on Skill');
     $skill = $skills[0];
     $this->assertEquals(9, $skill->getSkillId(), 'The database should have exactly one Skill with the provided skillId');
 }
Ejemplo n.º 3
0
 public function testGetLastNRobots()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $numRobotsToFetch = 3;
     $lastNRobots = HomeView::getLastNCreatedRobots($numRobotsToFetch);
     //print_r($lastNRobots);
     $this->assertEquals(count($lastNRobots), $numRobotsToFetch, 'It should fetch the number of robots specified');
 }
Ejemplo n.º 4
0
 public function testGetAllSubmissions()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $submissions = SubmissionsDB::getAllSubmissions();
     $this->assertEquals(3, count($submissions), 'It should fetch all of the submissions in the test database');
     foreach ($submissions as $submission) {
         $this->assertTrue(is_a($submission, 'Submission'), 'It should return valid Submission objects');
     }
 }
Ejemplo n.º 5
0
 public function testCallRunFromGet()
 {
     DBMaker::create('ptest1');
     Database::clearDB();
     $db = Database::getDB($dbName = 'ptest1', $configPath = "C:" . DIRECTORY_SEPARATOR . "xampp" . DIRECTORY_SEPARATOR . "myConfig.ini");
     $_SERVER["REQUEST_METHOD"] = "GET";
     ob_start();
     LoginController::run();
     $output = ob_get_clean();
     $this->assertFalse(empty($output), "It should show something from a GET");
 }
 public function testGetSkillAssocsByUserDataId()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $testUserDataId = 3;
     $skillAssocs = SkillAssocsDB::getSkillAssocsBy('userDataId', $testUserDataId);
     foreach ($skillAssocs as $skillAssoc) {
         $this->assertEquals($skillAssoc->getUserDataId(), $testUserDataId, 'All returned SkillAssocs should have the specified userDataId');
     }
 }
Ejemplo n.º 7
0
 public function testGetAllUsers()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $users = UsersDB::getAllUsers();
     $this->assertEquals(4, count($users), 'It should fetch all of the users in the test database');
     foreach ($users as $user) {
         $this->assertTrue(is_a($user, 'User'), 'It should return valid User objects');
     }
 }
Ejemplo n.º 8
0
 public function testGetAllReviews()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $reviews = ReviewsDB::getAllReviews();
     $this->assertEquals(6, count($reviews), 'It should fetch all of the reviews in the test database');
     foreach ($reviews as $review) {
         $this->assertTrue(is_a($review, 'Review'), 'It should return valid Review objects');
     }
 }
Ejemplo n.º 9
0
 /**
  * @runInSeparateProcess
  */
 public function testCallRunFromGet()
 {
     ob_start();
     DBMaker::create('ptest1');
     Database::clearDB();
     $db = Database::getDB($dbName = 'ptest1', $configPath = "C:" . DIRECTORY_SEPARATOR . "xampp" . DIRECTORY_SEPARATOR . "myConfig.ini");
     $_SERVER["REQUEST_METHOD"] = "GET";
     $_SESSION = array('base' => 'mvcdbcrud', 'control' => 'submission', 'action' => 'new', 'arguments' => null);
     SubmissionController::run();
     $output = ob_get_clean();
     $this->assertFalse(empty($output), "It should show something from a GET");
 }
Ejemplo n.º 10
0
 public function testGetSubmissionBySubmitterName()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $submissions = SubmissionsDB::getSubmissionsBy('submitterName', 'Kay');
     $this->assertEquals(count($submissions), 2, 'Kay should have two submissions');
     foreach ($submissions as $submission) {
         $this->assertTrue(is_a($submission, "Submission"), 'The returned values should be Submission objects');
         $this->assertTrue(empty($submission->getErrors()), "The returned submissions should have no errors");
     }
 }
Ejemplo n.º 11
0
 public function testGetReviewByReviewerName()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $reviews = ReviewsDB::getReviewsBy('reviewerName', 'Alice');
     $this->assertEquals(count($reviews), 3, 'Alice should have three reviews');
     foreach ($reviews as $review) {
         $this->assertTrue(is_a($review, "Review"), 'The returned values should be Review objects');
         $this->assertTrue(empty($review->getErrors()), "The returned reviews should have no errors");
     }
 }
 /**
  * @runInSeparateProcess
  */
 public function testCallRunFromGet()
 {
     ob_start();
     DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB($dbName = 'botspacetest', $configPath = 'C:\\xampp\\myConfig.ini');
     $_SERVER['REQUEST_METHOD'] = "GET";
     $_SERVER['HTTP_HOST'] = "localhost";
     $_SESSION = array("base" => "ha_lab3");
     SignupController::run();
     $output = ob_get_clean();
     $this->assertFalse(empty($output), "It should show something from a GET");
 }
 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');
 }
 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');
 }
Ejemplo n.º 16
0
 public function testInsertDuplicateUserData()
 {
     ob_start();
     $myDb = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $beforeCount = count(UserDataDB::getUserDataBy());
     $userDataCopy = UserDataDB::getUserDataRowSetsBy('userDataId', 1);
     $userDataCopy = $userDataCopy[0];
     $s1 = new UserData($userDataCopy);
     $insertedUserData = UserDataDB::addUserData($s1);
     $this->assertGreaterThan(0, $insertedUserData->getErrorCount(), 'Duplicate attempt should return with an error');
     $afterCount = count(UserDataDB::getUserDataBy());
     $this->assertEquals($afterCount, $beforeCount, 'The database should have the same number of elements after the insertion attempt');
     ob_get_clean();
 }
Ejemplo n.º 17
0
 public function testUpdateUserEmail()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $testUserId = 1;
     $users = UsersDB::getUsersBy('userId', $testUserId);
     $user = $users[0];
     $params = $user->getParameters();
     $this->assertEquals($user->getEmail(), '*****@*****.**', 'Before the update it should have email bjabituya@yahoo.com');
     $params['email'] = '*****@*****.**';
     $newUser = new User($params);
     $newUser->setUserId($testUserId);
     $user = UsersDB::updateUser($newUser);
     $this->assertEquals($user->getEmail(), '*****@*****.**', 'After the update it should have email bjabituya2000@yahoo.com');
     $this->assertTrue(empty($user->getErrors()), 'The updated user should have no errors');
 }
Ejemplo n.º 18
0
 public function testUpdateUserName()
 {
     // Test the update of the userName
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $users = UsersDB::getUsersBy('userId', 1);
     $user = $users[0];
     $parms = $user->getParameters();
     $this->assertEquals($user->getUserName(), 'Kay', 'Before the update it should have user name Kay');
     $parms['userName'] = '******';
     $newUser = new User($parms);
     $newUser->setUserId(1);
     $user = UsersDB::updateUser($newUser);
     $this->assertEquals($user->getUserName(), 'Kay1', 'Before the update it should have user name Kay1');
     $this->assertTrue(empty($user->getErrors()), 'The updated user should not have errors');
 }
 public function testUpdateUserData()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $testUserDataId = 1;
     $userDataArray = UserDataDB::getUserDataBy('userDataId', $testUserDataId);
     $userData = $userDataArray[0];
     $params = $userData->getParameters();
     $this->assertEquals($userData->getUserName(), 'jabituya', 'Before the update it should have username jabituya');
     $testUserDataRowsArray = UserDataDB::getUserDataRowSetsBy('userDataId', $testUserDataId);
     $testUserDataRow = $testUserDataRowsArray[0];
     $params['user_name'] = 'jabituya2000';
     $newUserData = new UserData($params);
     $newUserData->setUserDataId($testUserDataId);
     $userData = UserDataDB::updateUserData($newUserData);
     $this->assertEquals($userData->getUserName(), 'jabituya2000', 'After the update it should have username jabituya2000');
     $this->assertTrue(empty($userData->getErrors()), 'The updated user data should have no errors');
 }
 public function testUpdateMeasurementValue()
 {
     $myDb = DBMaker::create('sensordatarepotest');
     Database::clearDB();
     $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini');
     $testMeasurementId = 1;
     $measurements = MeasurementsDB::getMeasurementsBy('measurement_id', $testMeasurementId);
     $measurement = $measurements[0];
     $this->assertEquals($measurement->getMeasurementValue(), '45.2', 'Before the update, the measurement should have value 45.2');
     $params = $measurement->getParameters();
     $params['measurement_value'] = '25.4';
     $params['sensorType'] = 'HEADING';
     $params['sequenceType'] = 'SEQUENTIAL';
     $newMeasurement = new Measurement($params);
     $newMeasurement->setMeasurementId($testMeasurementId);
     $returnedMeasurement = MeasurementsDB::updateMeasurement($newMeasurement);
     $this->assertEquals($returnedMeasurement->getMeasurementValue(), $params['measurement_value'], 'After the update it should have the value ' . $params['measurement_value']);
     $this->assertTrue(empty($returnedMeasurement->getErrors()), 'The updated measurement should be error-free');
 }
Ejemplo n.º 21
0
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Basic tests for makeDB</title>
</head>
<body>
<h1>makeDB tests</h1>

<?php 
include_once "../models/Database.class.php";
include_once "../models/Messages.class.php";
include_once "./DBMaker.class.php";
?>

<h1>Tests for making a database using prepared statements</h1>

<h2>It should create a database for a particular name</h2>
<?php 
$myDb = DBMaker::create('ptest');
?>

</body>
</html>
 public function testUpdateDatasetDescription()
 {
     $myDb = DBMaker::create('sensordatarepotest');
     Database::clearDB();
     $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini');
     $testDatasetId = 1;
     $datasets = DatasetsDB::getDatasetsBy('dataset_id', $testDatasetId);
     $dataset = $datasets[0];
     $this->assertTrue(empty($dataset->getDescription()), 'Before the update, it should have an empty description');
     $params = $dataset->getParameters();
     $params['description'] = 'Updated description';
     $newDataset = new Dataset($params);
     $newDataset->setDatasetId($testDatasetId);
     $returnedDataset = DatasetsDB::updateDataset($newDataset);
     $this->assertEquals($returnedDataset->getDescription(), $params['description'], 'After the update it should have the name ' . $params['description']);
 }
Ejemplo n.º 23
0
 public function testUpdateSequenceType()
 {
     $myDb = DBMaker::create('sensordatarepotest');
     Database::clearDB();
     $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini');
     $testSensorId = 2;
     $sensors = SensorsDB::getSensorsBy('sensor_id', $testSensorId);
     $sensor = $sensors[0];
     $this->assertEquals($sensor->getSequenceType(), 'SEQUENTIAL', 'Before the update, it should have sequence type SEQUENTIAL');
     $params = $sensor->getParameters();
     $params['sequence_type'] = 'TIME-CODED';
     $newSensor = new Sensor($params);
     $newSensor->setSensorId($testSensorId);
     $returnedSensor = SensorsDB::updateSensor($newSensor);
     $this->assertEquals($returnedSensor->getSequenceType(), $params['sequence_type'], 'After the update it should have sequence_type ' . $params['sequence_type']);
     $this->assertTrue(empty($returnedSensor->getErrors()), 'The updated sensor should be error-free');
 }
Ejemplo n.º 24
0
 public function testValidUserCreate()
 {
     $myDb = DBMaker::create('ptest');
 }
Ejemplo n.º 25
0
 public function testDatabaseCreate()
 {
     $myDb = DBMaker::create('botspacetest');
 }
Ejemplo n.º 26
0
 public function testUpdateUsername()
 {
     $myDb = DBMaker::create('sensordatarepotest');
     Database::clearDB();
     $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini');
     $testUserId = 1;
     $users = UsersDB::getUsersBy('user_id', $testUserId);
     $user = $users[0];
     $params = $user->getParameters();
     $this->assertEquals($user->getUsername(), 'jabituya', 'Before the update is should have username jabituya');
     $params['username'] = '******';
     $newUser = new User($params);
     $newUser->setUserId($testUserId);
     $updatedUser = UsersDB::updateUser($newUser);
     $this->assertEquals($updatedUser->getUsername(), $params['username'], 'After the update it should have username ' . $params['username']);
     $this->assertTrue(empty($updatedUser->getErrors()), 'The updated user should have no errors');
 }
include_once "../models/Review.class.php";
include_once "../models/ReviewsDB.class.php";
include_once "../models/Submission.class.php";
include_once "../models/SubmissionsDB.class.php";
include_once "../models/User.class.php";
include_once "../models/UsersDB.class.php";
include_once "../views/HomeView.class.php";
include_once "../views/MasterView.class.php";
include_once "../views/SubmissionView.class.php";
include_once "../views/UserView.class.php";
include_once "./DBMaker.class.php";
?>

<h2>It should should a new submission form input during $POST with incomplete information</h2>
<?php 
DBMaker::create('ptest');
$_SERVER["REQUEST_METHOD"] = "POST";
$_SESSION = array('base' => 'mvcdbcrud', 'control' => 'submission', 'action' => 'new', 'arguments' => null);
$_POST = array("submitterName" => "Kay");
SubmissionController::run();
?>

<h2>It should call show a new submission form for a $GET request</h2>
<?php 
$_SERVER["REQUEST_METHOD"] = "GET";
$_SESSION = array('base' => 'mvcdbcrud', 'control' => 'submission', 'action' => 'new', 'arguments' => null);
SubmissionController::run();
?>
</body>
</html>