From 0976373cb9b70b78280860a00f0ec3be899c62ba Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Sat, 1 Jun 2024 21:11:38 +0400 Subject: [PATCH] save should return false when review size exceeds 2000 --- tests/ReviewTest.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/ReviewTest.php b/tests/ReviewTest.php index 0ef9d52..fa61a80 100644 --- a/tests/ReviewTest.php +++ b/tests/ReviewTest.php @@ -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 @@ -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(), @@ -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( @@ -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);