From 26026df51560ecafaff4339d22dd4a3f8eb01a9f Mon Sep 17 00:00:00 2001 From: jaatsiyah Date: Sat, 18 May 2024 17:58:54 +0700 Subject: [PATCH 1/2] Unit Test added --- tests/Feature/funcCreateTest.php | 26 ++++++++++++++++ tests/Feature/funcCreateUpdate.php | 26 ++++++++++++++++ tests/Feature/funcDeleteTest.php | 38 +++++++++++++++++++++++ tests/Feature/funcUpdateTest.php | 48 ++++++++++++++++++++++++++++++ tests/Feature/funcViewTest.php | 33 ++++++++++++++++++++ 5 files changed, 171 insertions(+) create mode 100644 tests/Feature/funcCreateTest.php create mode 100644 tests/Feature/funcCreateUpdate.php create mode 100644 tests/Feature/funcDeleteTest.php create mode 100644 tests/Feature/funcUpdateTest.php create mode 100644 tests/Feature/funcViewTest.php diff --git a/tests/Feature/funcCreateTest.php b/tests/Feature/funcCreateTest.php new file mode 100644 index 0000000..830b42a --- /dev/null +++ b/tests/Feature/funcCreateTest.php @@ -0,0 +1,26 @@ +get(route('products.create')); + + $response->assertStatus(200); + + $response->assertViewIs('products.create'); + } +} diff --git a/tests/Feature/funcCreateUpdate.php b/tests/Feature/funcCreateUpdate.php new file mode 100644 index 0000000..c10b33c --- /dev/null +++ b/tests/Feature/funcCreateUpdate.php @@ -0,0 +1,26 @@ +get(route('products.create')); + + $response->assertStatus(200); + + $response->assertViewIs('products.create'); + } +} diff --git a/tests/Feature/funcDeleteTest.php b/tests/Feature/funcDeleteTest.php new file mode 100644 index 0000000..4b475f0 --- /dev/null +++ b/tests/Feature/funcDeleteTest.php @@ -0,0 +1,38 @@ + 'P12345', + 'name' => 'Product to be deleted', + 'quantity' => 10, + 'price' => 99.99, + 'description' => 'Product description', + ]); + + // Send the delete request + $response = $this->delete(route('products.destroy', $product->id)); + + // Assert the response status + $response->assertRedirect(route('products.index')); + $response->assertSessionHas('success', 'Product is deleted successfully.'); + + // Assert the product was deleted + $this->assertDatabaseMissing('products', ['id' => $product->id]); + } +} diff --git a/tests/Feature/funcUpdateTest.php b/tests/Feature/funcUpdateTest.php new file mode 100644 index 0000000..390f090 --- /dev/null +++ b/tests/Feature/funcUpdateTest.php @@ -0,0 +1,48 @@ + 'H001', + 'name' => 'Kaveh', + 'quantity' => 1, + 'price' => 99.99, + 'description' => 'Husbunya Ren', + ]); + + $updateData = [ + 'code' => 'H001', + 'name' => 'Kaveh', + 'quantity' => 1, + 'price' => 199.99, + 'description' => 'Malewife keduanya Ren', + ]; + + $response = $this->put(route('products.update', $product->id), $updateData); + + $response->assertRedirect(); + $response->assertSessionHas('success', 'Product is updated successfully.'); + + $updatedProduct = Product::find($product->id); + + $this->assertEquals($updateData['code'], $updatedProduct->code); + $this->assertEquals($updateData['name'], $updatedProduct->name); + $this->assertEquals($updateData['quantity'], $updatedProduct->quantity); + $this->assertEquals($updateData['price'], $updatedProduct->price); + $this->assertEquals($updateData['description'], $updatedProduct->description); + } +} diff --git a/tests/Feature/funcViewTest.php b/tests/Feature/funcViewTest.php new file mode 100644 index 0000000..e54c1d5 --- /dev/null +++ b/tests/Feature/funcViewTest.php @@ -0,0 +1,33 @@ + 'H001', + 'name' => 'Kaveh', + 'quantity' => 1, + 'price' => 99.99, + 'description' => 'Husbunya Ren', + ]); + + $response = $this->get(route('products.show', $product->id)); + + $response->assertStatus(200); + $response->assertViewIs('products.show'); + $response->assertViewHas('product', $product); + } +} From 9476c99413bb1c73118c2b5d44c2eab84d012eec Mon Sep 17 00:00:00 2001 From: jaatsiyah Date: Wed, 5 Jun 2024 20:04:49 +0700 Subject: [PATCH 2/2] Unit test changed --- tests/Feature/funcViewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/funcViewTest.php b/tests/Feature/funcViewTest.php index e54c1d5..ea7f65b 100644 --- a/tests/Feature/funcViewTest.php +++ b/tests/Feature/funcViewTest.php @@ -18,7 +18,7 @@ public function test_show_product(): void { $product = Product::create([ 'code' => 'H001', - 'name' => 'Kaveh', + 'name' => 'Kaaveh', 'quantity' => 1, 'price' => 99.99, 'description' => 'Husbunya Ren',