*/ protected array $fixtures = [ 'plugin.CakeCarts.CartItems', 'plugin.CakeCarts.Carts', ]; public function setUp(): void { parent::setUp(); // TODO: Change the autogenerated stub $config = $this->getTableLocator()->exists('CartItems') ? [] : ['className' => CartItemsTable::class]; $this->CartItems = $this->getTableLocator()->get('CartItems', $config); } /** * Test add method * * @return void * @link \CakeCarts\Controller\CartItemsController::add() */ public function testAdd(): void { $url = [ 'plugin' => 'CakeCarts', 'controller' => 'CartItems', 'action' => 'add', ]; $skuId = '3a477e3e-7977-4813-81f6-f85949613979'; $beforeCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count(); $postData = [ 'foreign_key' => null, '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); } /** * Test edit method * * @return void * @link \CakeCarts\Controller\CartItemsController::edit() */ public function testEdit(): void { $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); } /** * Test delete method * * @return void * @link \CakeCarts\Controller\CartItemsController::delete() */ public function testDelete(): void { $this->markTestIncomplete('Not implemented yet.'); } }