Files
cake-carts/tests/TestCase/Controller/Component/ShoppingCartComponentTest.php
Brandon Shipley 11aafbb232
Some checks failed
CI / testsuite (mysql, 8.2, ) (push) Has started running
CI / testsuite (mysql, 8.4, ) (push) Has started running
CI / testsuite (pgsql, 8.2, ) (push) Has been cancelled
CI / testsuite (pgsql, 8.4, ) (push) Has been cancelled
CI / testsuite (sqlite, 8.2, ) (push) Has been cancelled
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Has been cancelled
CI / testsuite (sqlite, 8.4, ) (push) Has been cancelled
CI / Coding Standard & Static Analysis (push) Has been cancelled
tests should be passing now
2026-02-14 00:45:29 -08:00

117 lines
2.6 KiB
PHP

<?php
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\Http\ServerRequest;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeCarts\Controller\Component\ShoppingCartComponent;
/**
* CakeCarts\Controller\Component\ShoppingCartComponent Test Case
*/
class ShoppingCartComponentTest extends TestCase {
use IntegrationTestTrait;
protected ShoppingCartComponent $component;
protected Controller $controller;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeCarts.CartItems',
'plugin.CakeCarts.Carts',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$request = new ServerRequest();
$this->controller = new Controller($request);
$registry = new ComponentRegistry($this->controller);
$this->component = new ShoppingCartComponent($registry);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void {
unset($this->component);
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->expectException(RecordNotFoundException::class);
$cart = $this->fetchTable('Carts')->get('00e6ec6b-eef8-429c-9196-e7e0668ba749');
$this->component->checkIfIsOwnCart($cart);
// if exception not thrown test fails
}
}