Beispiel #1
0
 public function testInsertDuplicateReview()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $beforeCount = count(ReviewsDB::getReviewsBy());
     $duplicateTest = $validTest = array("reviewerName" => "John", "submissionId" => "1", "score" => "5", "review" => "This was a great presentation");
     $s1 = new Review($duplicateTest);
     $review = ReviewsDB::addReview($s1);
     $this->assertTrue(!is_null($review), 'The returned review should not be null');
     $this->assertTrue(!empty($review->getErrors()), 'The returned review should have errors');
     $afterCount = count(ReviewsDB::getReviewsBy());
     $this->assertEquals($afterCount, $beforeCount, 'The database should have the same number of reviews after trying to insert duplicate');
 }
 public static function newReview()
 {
     // Process a new review
     $review = null;
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $review = new Review($_POST);
         $review = ReviewsDB::addReview($review);
     }
     if (is_null($review) || $review->getErrorCount() != 0) {
         $_SESSION['review'] = $review;
         ReviewView::showNew();
     } else {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     }
 }
Beispiel #3
0
$s1New = ReviewsDB::addReview($s1);
$afterCount = count(ReviewsDB::getReviewsBy());
echo "The new review is: {$s1New}<br>";
echo "Before the database has {$beforeCount}<br>";
echo "Now the database has {$afterCount}<br>";
?>

<h2>It should not allow insertion of a duplicate review</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
$beforeCount = count(ReviewsDB::getReviewsBy());
$duplicateTest = array("reviewerName" => "Alice", "submissionId" => "1", "score" => "5", "review" => "This was a great presentation");
$s1 = new Review($duplicateTest);
$s1New = ReviewsDB::addReview($s1);
$afterCount = count(ReviewsDB::getReviewsBy());
echo "The errors are: <br>";
print_r($s1New->getErrors());
echo "<br>Before the database has {$beforeCount}<br>";
echo "Now the database has {$afterCount}<br>";
?>

<h2>It should all update of a valid review</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
$beforeCount = count(ReviewsDB::getReviewsBy());
$reviews = ReviewsDB::getReviewsBy('reviewId', 1);
$currentReview = $reviews[0];