first test passing
This commit is contained in:
parent
9440934228
commit
59478fab17
|
|
@ -23,7 +23,8 @@
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"CakeCarts\\Test\\": "tests/",
|
"CakeCarts\\Test\\": "tests/",
|
||||||
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
|
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
|
||||||
|
"TestApp\\": "tests/test_app/src/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ class CartItemsController extends AppController
|
||||||
// component work only for specified methods.
|
// component work only for specified methods.
|
||||||
'actions' => ['add'],
|
'actions' => ['add'],
|
||||||
]);
|
]);
|
||||||
|
if ($this->components()->has('Authorization')) {
|
||||||
|
$this->Authorization->skipAuthorization();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,7 +39,6 @@ class CartItemsController extends AppController
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||||
$this->Authorization->skipAuthorization();
|
|
||||||
|
|
||||||
Log::debug(print_r('$this->request->getData()', true));
|
Log::debug(print_r('$this->request->getData()', true));
|
||||||
Log::debug(print_r($this->request->getData(), true));
|
Log::debug(print_r($this->request->getData(), true));
|
||||||
|
|
@ -49,11 +51,11 @@ class CartItemsController extends AppController
|
||||||
$postData['price'] = $price;
|
$postData['price'] = $price;
|
||||||
$postData['subtotal'] = isset($price) ? bcmul("$price", "$qty", 5) : null;
|
$postData['subtotal'] = isset($price) ? bcmul("$price", "$qty", 5) : null;
|
||||||
|
|
||||||
$newCartItem = $this->Carts->CartItems->newEntity($postData, [
|
$newCartItem = $this->CartItems->newEntity($postData, [
|
||||||
'validate' => Configure::readOrFail('CakeCarts.CartItems.requirePricing') ? 'requirePricing' : 'default',
|
'validate' => Configure::readOrFail('CakeCarts.CartItems.requirePricing') ? 'requirePricing' : 'default',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($this->Carts->CartItems->save($newCartItem)) {
|
if ($this->CartItems->save($newCartItem)) {
|
||||||
$this->Flash->success('Added to cart');
|
$this->Flash->success('Added to cart');
|
||||||
|
|
||||||
return $this->redirect($this->referer([
|
return $this->redirect($this->referer([
|
||||||
|
|
@ -62,9 +64,9 @@ class CartItemsController extends AppController
|
||||||
'action' => 'index'
|
'action' => 'index'
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
Log::debug(print_r('$newCartItem->getErrors()', true));
|
// Log::debug(print_r('$newCartItem->getErrors()', true));
|
||||||
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.');
|
$this->Flash->error('Failed to add to cart.');
|
||||||
|
|
||||||
return $this->redirect($this->referer([
|
return $this->redirect($this->referer([
|
||||||
|
|
@ -91,7 +93,6 @@ class CartItemsController extends AppController
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
||||||
$this->Authorization->skipAuthorization();
|
|
||||||
|
|
||||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||||
$postData = $this->request->getData();
|
$postData = $this->request->getData();
|
||||||
|
|
@ -142,7 +143,6 @@ class CartItemsController extends AppController
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
$this->ShoppingCart->checkIfIsOwnCart($cartItem->cart);
|
||||||
$this->Authorization->skipAuthorization();
|
|
||||||
|
|
||||||
unset($cartItem->cart);
|
unset($cartItem->cart);
|
||||||
if ($this->CartItems->delete($cartItem)) {
|
if ($this->CartItems->delete($cartItem)) {
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,17 @@ class CartItemsTable extends Table
|
||||||
public function validationDefault(Validator $validator): Validator
|
public function validationDefault(Validator $validator): Validator
|
||||||
{
|
{
|
||||||
$validator
|
$validator
|
||||||
->uuid('product_sku_id')
|
->scalar('foreign_key')
|
||||||
->requirePresence('product_sku_id', 'create')
|
->allowEmptyString('foreign_key');
|
||||||
->notEmptyString('product_sku_id');
|
|
||||||
|
$validator
|
||||||
|
->uuid('foreign_key_uuid')
|
||||||
|
->allowEmptyString('foreign_key_uuid');
|
||||||
|
|
||||||
|
$validator
|
||||||
|
->scalar('model')
|
||||||
|
->requirePresence('model', 'create')
|
||||||
|
->notEmptyString('model');
|
||||||
|
|
||||||
$validator
|
$validator
|
||||||
->uuid('cart_id')
|
->uuid('cart_id')
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace CakeCarts\Test\TestCase\Controller;
|
||||||
use Cake\TestSuite\IntegrationTestTrait;
|
use Cake\TestSuite\IntegrationTestTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
use CakeCarts\Controller\CartItemsController;
|
use CakeCarts\Controller\CartItemsController;
|
||||||
|
use CakeCarts\Model\Table\CartItemsTable;
|
||||||
|
use CakeCarts\Model\Table\CartsTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CakeCarts\Controller\CartItemsController Test Case
|
* CakeCarts\Controller\CartItemsController Test Case
|
||||||
|
|
@ -16,6 +18,13 @@ class CartItemsControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
use IntegrationTestTrait;
|
use IntegrationTestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test subject
|
||||||
|
*
|
||||||
|
* @var \CakeCarts\Model\Table\CartItemsTable
|
||||||
|
*/
|
||||||
|
protected $CartItems;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixtures
|
* Fixtures
|
||||||
*
|
*
|
||||||
|
|
@ -26,27 +35,14 @@ class CartItemsControllerTest extends TestCase
|
||||||
'plugin.CakeCarts.Carts',
|
'plugin.CakeCarts.Carts',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
public function setUp(): void
|
||||||
* Test index method
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @link \CakeCarts\Controller\CartItemsController::index()
|
|
||||||
*/
|
|
||||||
public function testIndex(): void
|
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Not implemented yet.');
|
parent::setUp(); // TODO: Change the autogenerated stub
|
||||||
|
|
||||||
|
$config = $this->getTableLocator()->exists('CartItems') ? [] : ['className' => CartItemsTable::class];
|
||||||
|
$this->CartItems = $this->getTableLocator()->get('CartItems', $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test view method
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @link \CakeCarts\Controller\CartItemsController::view()
|
|
||||||
*/
|
|
||||||
public function testView(): void
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete('Not implemented yet.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test add method
|
* Test add method
|
||||||
|
|
@ -56,7 +52,26 @@ class CartItemsControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testAdd(): void
|
public function testAdd(): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Not implemented yet.');
|
$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' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||||
|
'model' => 'ProductSkus',
|
||||||
|
'qty' => 10,
|
||||||
|
'price' => 0.75,
|
||||||
|
];
|
||||||
|
$this->post($url, $postData);
|
||||||
|
$this->assertResponseCode(302);
|
||||||
|
$afterCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count();
|
||||||
|
|
||||||
|
$this->assertEquals($beforeCnt + 1, $afterCnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<?php
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<?php
|
||||||
Loading…
Reference in New Issue