Skip to content

Commit

Permalink
save should return false when review size exceeds 2000
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jun 1, 2024
1 parent 48c0ef5 commit 0976373
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/ReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public function tearDown(): void
$this->dummy_product = null;

// clear all data from review and client tables
self::query('DELETE FROM comment; DELETE FROM review; DELETE FROM client; DELETE FROM user; DELETE FROM store_product; DELETE FROM product;');
self::query(
'DELETE FROM comment; DELETE FROM review; DELETE FROM client;
DELETE FROM user; DELETE FROM store_product; DELETE FROM product;'
);
}

public function testConstructor(): void
Expand Down Expand Up @@ -236,6 +239,20 @@ public function testSave(): void
$this->assertTrue($success);
$this->assertGreaterThan(0, $specialCharReview->getReviewID());


// Create a review of length exactly 2000
$longTextReview = new Review(
product_id: $this->dummy_product->getProductID(),
client_id: $this->reviewer->getUserID(),
text: str_repeat("A", 2000),
rating: 4,
created_date: new DateTime()
);
// Attempt to save the review with long text
$success = $longTextReview->save();
// Assert that the save operation failed because max length of review is 2000
$this->assertTrue($success);

// Create a review with extremely long text
$longTextReview = new Review(
product_id: $this->dummy_product->getProductID(),
Expand All @@ -246,9 +263,9 @@ public function testSave(): void
);
// Attempt to save the review with long text
$success = $longTextReview->save();
// Assert that the save operation succeeded
$this->assertTrue($success);
$this->assertGreaterThan(0, $longTextReview->getReviewID());
// Assert that the save operation failed because max length of review is 2000
$this->assertFalse($success);


// Test saving duplicate reviews
$duplicateReview = new Review(
Expand All @@ -264,6 +281,7 @@ public function testSave(): void
$this->assertTrue($success);
$this->assertGreaterThan(0, $duplicateReview->getReviewID());
}

public function testGetNestedComments(): void
{
$review = new Review(review_id: 1);
Expand Down

0 comments on commit 0976373

Please sign in to comment.