Example #1
0
 public static function convertIdToItem($numArray, $flag = false)
 {
     //this form of foreach gives you the key and the value.
     foreach ($numArray as $key => $num) {
         //get db connection
         $dbh = Database::getDB();
         //prepare sql
         $getItem = $dbh->prepare("SELECT productName, price\r\n\t\t\t\t\t\t\t\t  FROM inventory\r\n\t\t\t\t\t\t\t\t  WHERE iid=:key");
         //Bind parameters
         $getItem->bindParam(':key', $key, PDO::PARAM_INT);
         //Execute
         $getItem->execute();
         //Fetch the row to see if it exists
         $item = $getItem->fetch(PDO::FETCH_ASSOC);
         //check if exists now, if it does print name, else print Item not available
         if (isset($item['productName'])) {
             echo "({$num})" . $item['productName'] . " - \$" . $item['price'] * $num;
             if ($flag) {
                 echo "[ID={$key}]";
             }
             echo "\n\n";
         } else {
             echo "Item Not Available\n";
         }
         //Remove db connection
         Database::clearDB();
     }
 }
Example #2
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");
 }
 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');
 }
 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');
 }
Example #5
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');
     }
 }
 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');
     }
 }
Example #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');
     }
 }
Example #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');
     }
 }
 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");
 }
 /**
  * @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");
 }
Example #11
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");
     }
 }
Example #12
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 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');
 }
 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 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();
 }
 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');
 }
Example #19
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 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');
 }
 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');
 }
Example #22
0
<h1>SubmissionsDB tests</h1>


<?php 
include_once "../models/Database.class.php";
include_once "../models/Messages.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 "./makeDB.php";
?>


<h2>It should get all submissions from a test database</h2>
<?php 
makeDB('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$submissions = SubmissionsDB::getAllSubmissions();
$submissionCount = count($submissions);
echo "Number of submissions in db is: {$submissionCount} <br>";
foreach ($submissions as $submission) {
    echo "{$submission} <br>";
}
?>
	


</body>
</html>
Example #23
0
    public static function show()
    {
        //Check if user is logged in. If so prefill the forms.
        if (isset($_SESSION['user_session'])) {
            //get db connection
            $dbh = Database::getDB();
            $getUserInfo = $dbh->prepare("SELECT uid, email, firstName, lastName, phoneNumber \r\n\t\t\t\t\t\t\t\t\t\t  FROM users WHERE email=:email");
            //Bind the values
            $getUserInfo->bindParam(':email', $_SESSION['user_session'], PDO::PARAM_STR);
            //execute
            $getUserInfo->execute();
            //Fetch the row to see if it exists
            $userInfo = $getUserInfo->fetch(PDO::FETCH_ASSOC);
            Database::clearDB();
        }
        ?>
	<script>
	function clicked(e)
	{
	    if(!confirm('Are you ready to order?'))e.preventDefault();
	}
	</script>
	<div class="row">
	<div class="wrapperCustom">
	<div class="col-lg-12">
		 <div class="backgroundHeader">
		  	<h1 class="aboutHeading">Place Order</h1><br><br>
		  </div>
	  </div>
	 <div class="col-lg-3 col-md-3 col-sm-2 col-xs-0"></div>
	 <div class="col-lg-6 col-md-6 col-sm-8 col-xs-12 orderContent">
		<form action="models/placeOrder.php" method="POST">
		<div class="loginForm">
			<div>
				<span class="orderTitle">First name</span><br>
				<input class="orderInput" type="text" name="firstNameOrder" placeholder="First Name" maxlength="40" required value="<?php 
        if (isset($userInfo['firstName'])) {
            echo $userInfo['firstName'];
        }
        ?>
" pattern="[a-zA-Z-]{1,40}" title="Please enter a valid first name">
			</div>
			<br>
			<div>
				<span class="orderTitle">Last name</span><br>
				<input class="orderInput" type="text" name="lastNameOrder" placeholder="Last Name" maxlength="40" required value="<?php 
        if (isset($userInfo['lastName'])) {
            echo $userInfo['lastName'];
        }
        ?>
" pattern="[a-zA-Z-]{1,40}" title="Please enter a valid last name">
			</div>
			<br>
			<div>
				<span class="orderTitle">Email</span><br>
				<input class="orderInput" type="email" name="emailOrder" placeholder="Email Address" maxlength="50" required value="<?php 
        if (isset($userInfo['email'])) {
            echo $userInfo['email'];
        }
        ?>
" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" title="Please enter a valid email">
			</div>
			<br>
			<div>
				<span class="orderTitle">Phone Number</span><br>
				<input class="orderInput" type="tel" name="phoneNumberOrder" maxlength="20" placeholder="Phone Number" required value="<?php 
        if (isset($userInfo['phoneNumber'])) {
            echo $userInfo['phoneNumber'];
        }
        ?>
" pattern="[0-9-]{7,}" title="Please enter a valid phone number. Ex) 210-123-4567">
			</div>
			<br>
			<div>
				<span class="orderTitle">Item List *Pulled From Your Cart*</span><br>
				<textarea readonly class="orderList2"><?php 
        getUserData::getCartContents();
        ?>
</textarea>
				
				
			</div>
			<br>
			<div>
				<span class="orderTitle">Order Notes</span><br>
				<textarea rows="4" cols="50" name="orderNotes" class="orderInputTextBox"></textarea>
			</div>
			<br><br>
			<input class="orderSubmit" type="submit" value="Submit" <?php 
        if (isset($_SESSION['numOfCartItems'])) {
            if ($_SESSION['numOfCartItems'] == 0) {
                echo "disabled";
            }
        } else {
            echo "disabled";
        }
        ?>
 onclick="clicked(event)">
		</div>
	  </form>
	<span id="orderWarning">Please allow at least 30 minutes for order to be completed before picking up.</span><br><br><br>
	<span id="onlineOrderWarning">*****Online Ordering Coming Soon*****</span>
	</div>
	<div class="col-lg-3 col-md-3 col-sm-2 col-xs-0"></div>
	</div>
	</div>
<?php 
        //sendEmail::Email();
    }
 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']);
 }
Example #25
0
 public static function convertIdToItem($numArray, $flag = false, $htmlFlag = 0)
 {
     //this form of foreach gives you the key and the value.
     foreach ($numArray as $key => $num) {
         //get db connection
         $dbh = Database::getDB();
         //prepare sql
         $getItem = $dbh->prepare("SELECT productName, price\r\n\t\t\t\t\t\t\t\t  FROM inventory\r\n\t\t\t\t\t\t\t\t  WHERE iid=:key");
         //Bind parameters
         $getItem->bindParam(':key', $key, PDO::PARAM_INT);
         //Execute
         $getItem->execute();
         //Fetch the row to see if it exists
         $item = $getItem->fetch(PDO::FETCH_ASSOC);
         //check if exists now, if it does print name, else print Item not available
         if (isset($item['productName'])) {
             //these 3 ifs are only used for viewCartView.  Rest of function is for other guys
             if ($htmlFlag == 2) {
                 echo $item['productName'];
                 echo "<br><br>";
             } elseif ($htmlFlag == 3) {
                 echo "\$" . number_format($item['price'] * $num, 2);
                 echo "<br><br>";
             } elseif ($htmlFlag == 4) {
                 echo $num;
                 echo "<br><br>";
             } else {
                 //For place order
                 echo "({$num})" . $item['productName'] . " - \$" . $item['price'] * $num;
                 if ($flag) {
                     echo "[ID={$key}]";
                 }
                 //for html pages
                 if ($htmlFlag == 1) {
                     echo "<br>";
                 } else {
                     //for text areas
                     echo "\n\n";
                 }
             }
         } else {
             echo "Item Not Available\n";
         }
         //Remove db connection
         Database::clearDB();
     }
 }
 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');
 }
 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');
 }