test fixes shopping cart component
Some checks failed
CI / testsuite (mysql, 8.2, ) (push) Successful in 4m18s
CI / testsuite (pgsql, 8.4, ) (push) Successful in 7m8s
CI / testsuite (sqlite, 8.2, ) (push) Successful in 3m21s
CI / testsuite (pgsql, 8.2, ) (push) Successful in 13m24s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 3m45s
CI / testsuite (mysql, 8.4, ) (push) Successful in 19m22s
CI / Coding Standard & Static Analysis (push) Failing after 2m57s
CI / testsuite (sqlite, 8.4, ) (push) Successful in 15m45s
Some checks failed
CI / testsuite (mysql, 8.2, ) (push) Successful in 4m18s
CI / testsuite (pgsql, 8.4, ) (push) Successful in 7m8s
CI / testsuite (sqlite, 8.2, ) (push) Successful in 3m21s
CI / testsuite (pgsql, 8.2, ) (push) Successful in 13m24s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 3m45s
CI / testsuite (mysql, 8.4, ) (push) Successful in 19m22s
CI / Coding Standard & Static Analysis (push) Failing after 2m57s
CI / testsuite (sqlite, 8.4, ) (push) Successful in 15m45s
This commit is contained in:
@@ -4,6 +4,13 @@ declare(strict_types=1);
|
||||
namespace CakeCarts\Test\TestCase\Controller\Component;
|
||||
|
||||
use Cake\Controller\ComponentRegistry;
|
||||
use Cake\Controller\Controller;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Event\Event;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
use Cake\Http\Response;
|
||||
use Cake\Http\ServerRequest;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeCarts\Controller\Component\ShoppingCartComponent;
|
||||
|
||||
@@ -12,13 +19,21 @@ use CakeCarts\Controller\Component\ShoppingCartComponent;
|
||||
*/
|
||||
class ShoppingCartComponentTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test subject
|
||||
use IntegrationTestTrait;
|
||||
|
||||
protected ShoppingCartComponent $component;
|
||||
protected Controller $controller;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var \CakeCarts\Controller\Component\ShoppingCartComponent
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $ShoppingCart;
|
||||
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeCarts.CartItems',
|
||||
'plugin.CakeCarts.Carts',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
@@ -26,8 +41,11 @@ class ShoppingCartComponentTest extends TestCase {
|
||||
*/
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$registry = new ComponentRegistry();
|
||||
$this->ShoppingCart = new ShoppingCartComponent($registry);
|
||||
$request = new ServerRequest();
|
||||
$this->controller = new Controller($request);
|
||||
$registry = new ComponentRegistry($this->controller);
|
||||
|
||||
$this->component = new ShoppingCartComponent($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,5 +58,67 @@ class ShoppingCartComponentTest extends TestCase {
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCartForUserById()
|
||||
{
|
||||
$this->session([
|
||||
'CakeCarts.session_id' => 'cli',
|
||||
]);
|
||||
$cart = $this->component->getCartForUserById('74d1aa54-92a2-4039-bc10-61e1190c51ea');
|
||||
$this->assertNotNull($cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCartForUserByIdDoesNotExist()
|
||||
{
|
||||
$this->expectException(RecordNotFoundException::class);
|
||||
$cart = $this->component->getCartForUserById('74d1aa54-92a2-4039-bc10-61e1190c51ec');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetUserIdField()
|
||||
{
|
||||
$this->assertNotNull($this->component->getUserIdField());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSessionId()
|
||||
{
|
||||
$this->assertNotNull($this->component->getSessionId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckIfIsOwnCartIsOwnCart()
|
||||
{
|
||||
$this->session([
|
||||
'CakeCarts.session_id' => 'session_1',
|
||||
]);
|
||||
$cart = $this->fetchTable('Carts')->get('74d1aa54-92a2-4039-bc10-61e1190c51ea');
|
||||
$this->component->checkIfIsOwnCart($cart);
|
||||
// if exception not thrown test passes
|
||||
$this->assertEquals(1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckIfIsOwnCartIsNotOwnCart()
|
||||
{
|
||||
$this->expectExceptionCode(404);
|
||||
$cart = $this->fetchTable('Carts')->get('74d1aa54-92a2-4039-bc10-61e1190c51ec');
|
||||
$this->component->checkIfIsOwnCart($cart);
|
||||
// if exception not thrown test fails
|
||||
$this->expectException(RecordNotFoundException::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user