diff --git a/composer.json b/composer.json index a509ce5..f5df1c6 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "phpunit/phpunit": "^10.1", "cakephp/migrations": "^4.0.0" }, + "suggest": { + "hi-powered-dev/cake-products": "Manage products and SKUs with a heirarhical category structure, includes attributes and variants" + }, "autoload": { "psr-4": { "CakeCarts\\": "src/" diff --git a/src/Controller/CartItemsController.php b/src/Controller/CartItemsController.php index 12befc1..1b1ef1a 100644 --- a/src/Controller/CartItemsController.php +++ b/src/Controller/CartItemsController.php @@ -66,7 +66,6 @@ class CartItemsController extends AppController } // Log::debug(print_r('$newCartItem->getErrors()', true)); // Log::debug(print_r($newCartItem->getErrors(), true)); - dd(print_r($newCartItem->getErrors(), true)); $this->Flash->error('Failed to add to cart.'); return $this->redirect($this->referer([ diff --git a/src/Model/Enum/CartTypeId.php b/src/Model/Enum/CartTypeId.php index 125def1..c0b3a90 100644 --- a/src/Model/Enum/CartTypeId.php +++ b/src/Model/Enum/CartTypeId.php @@ -17,7 +17,7 @@ enum CartTypeId: int implements EnumLabelInterface return match($this) { self::Cart => 'Cart', self::Wishlist => 'Wishlist', - self::CustomList => 'CustomList' + self::CustomList => 'List' }; } } diff --git a/tests/Fixture/CartItemsFixture.php b/tests/Fixture/CartItemsFixture.php index a0a7bea..f9c2138 100644 --- a/tests/Fixture/CartItemsFixture.php +++ b/tests/Fixture/CartItemsFixture.php @@ -23,7 +23,40 @@ class CartItemsFixture extends TestFixture 'foreign_key' => null, 'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c', 'model' => 'ProductSkus', - 'cart_id' => '21794607-f68e-424f-91ba-3230e2f92e2b', + 'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51ea', + 'position' => 1, + 'qty' => 1, + 'price' => 1.5, + 'subtotal' => 1.5, + ], + [ + 'id' => '74d1aa54-92a2-4039-ba10-61e1190c51eb', + 'foreign_key' => null, + 'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c', + 'model' => 'ProductSkus', + 'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51eb', + 'position' => 1, + 'qty' => 1, + 'price' => 1.5, + 'subtotal' => 1.5, + ], + [ + 'id' => '74d1aa54-92a2-4039-bc10-61e4190c51ec', + 'foreign_key' => null, + 'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c', + 'model' => 'ProductSkus', + 'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51ec', + 'position' => 1, + 'qty' => 1, + 'price' => 1.5, + 'subtotal' => 1.5, + ], + [ + 'id' => '79f66e8d-8d8d-4095-adc4-fd15234a4394', + 'foreign_key' => null, + 'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c', + 'model' => 'ProductSkus', + 'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51ed', 'position' => 1, 'qty' => 1, 'price' => 1.5, diff --git a/tests/Fixture/CartsFixture.php b/tests/Fixture/CartsFixture.php index 1a657fc..f092a25 100644 --- a/tests/Fixture/CartsFixture.php +++ b/tests/Fixture/CartsFixture.php @@ -61,10 +61,10 @@ class CartsFixture extends TestFixture 'removed_reason_id' => null, 'num_items' => 1, ], - // normal cart - deleted + // wishlist cart - deleted [ 'id' => '74d1aa54-92a2-4039-bc10-61e1190c51ed', - 'cart_type_id' => CartTypeId::Cart->value, + 'cart_type_id' => CartTypeId::Wishlist->value, 'session_id' => 'session_2', 'user_id' => null, 'user_id_uuid' => '5a34a6ae-7d3f-4dcf-bac7-57335b51e697', diff --git a/tests/TestCase/Controller/CartItemsControllerTest.php b/tests/TestCase/Controller/CartItemsControllerTest.php index 4a36afd..7c56f47 100644 --- a/tests/TestCase/Controller/CartItemsControllerTest.php +++ b/tests/TestCase/Controller/CartItemsControllerTest.php @@ -62,16 +62,19 @@ class CartItemsControllerTest extends TestCase $beforeCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count(); $postData = [ 'foreign_key' => null, - 'foreign_key_uuid' => '3a477e3e-7977-4813-81f6-f85949613979', + 'foreign_key_uuid' => $skuId, 'model' => 'ProductSkus', 'qty' => 10, 'price' => 0.75, + 'subtotal' => 1, ]; $this->post($url, $postData); $this->assertResponseCode(302); $afterCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count(); - $this->assertEquals($beforeCnt + 1, $afterCnt); + + $new = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId, 'qty' => 10, 'model' => 'ProductSkus'])->firstOrFail(); + $this->assertEquals(7.5, $new->subtotal); } /** @@ -82,7 +85,28 @@ class CartItemsControllerTest extends TestCase */ public function testEdit(): void { - $this->markTestIncomplete('Not implemented yet.'); + $id = '79f66e8d-8d8d-4095-adc4-fd15234a4397'; + $url = [ + 'plugin' => 'CakeCarts', + 'controller' => 'CartItems', + 'action' => 'edit', + $id + ]; + $this->session(['Auth.User.id' => 1]); + $this->session(['Auth.id' => 1]); + $this->session(['CakeCarts.session_id' => 'session_1']); + $before = $this->CartItems->get($id, contain: ['Carts']); +// dd($before); + $skuId = '3a477e3e-7977-4813-81f6-f85949613979'; + + $postData = [ + 'qty' => 100, + ]; + $this->post($url, $postData); + $this->assertResponseCode(302); + + $new = $this->CartItems->get($id); + $this->assertEquals(100, $new->qty); } /** diff --git a/tests/TestCase/Controller/CartsControllerTest.php b/tests/TestCase/Controller/CartsControllerTest.php index d9f8724..844d1df 100644 --- a/tests/TestCase/Controller/CartsControllerTest.php +++ b/tests/TestCase/Controller/CartsControllerTest.php @@ -15,4 +15,31 @@ use CakeCarts\Controller\CartsController; class CartsControllerTest extends TestCase { use IntegrationTestTrait; + + /** + * Test subject + * + * @var \CakeCarts\Model\Table\CartItemsTable + */ + protected $Carts; + + public function setUp(): void + { + parent::setUp(); // TODO: Change the autogenerated stub + + $config = $this->getTableLocator()->exists('Carts') ? [] : ['className' => CartsTable::class]; + $this->Carts = $this->getTableLocator()->get('Carts', $config); + } + + public function testIndex(): void + { + $url = [ + 'plugin' => 'CakeCarts', + 'controller' => 'Carts', + 'action' => 'index', + ]; + $this->get($url); + + $this->assertResponseCode(200); + } }