coming along

This commit is contained in:
2025-10-11 21:46:16 -07:00
parent 59478fab17
commit 7d219d045a
7 changed files with 94 additions and 8 deletions

View File

@@ -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);
}
/**

View File

@@ -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);
}
}