Skip to content

Commit ca7cf9f

Browse files
committed
SW-27055 - Add test for SW-24541 to ensure that the view contains the same cart as the database
1 parent ff06ff2 commit ca7cf9f

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* Shopware 5
6+
* Copyright (c) shopware AG
7+
*
8+
* According to our dual licensing model, this program can be used either
9+
* under the terms of the GNU Affero General Public License, version 3,
10+
* or under a proprietary license.
11+
*
12+
* The texts of the GNU Affero General Public License with an additional
13+
* permission and of our proprietary license can be found at and
14+
* in the LICENSE file you have received along with this program.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* "Shopware" is a registered trademark of shopware AG.
22+
* The licensing of the program under the AGPLv3 does not imply a
23+
* trademark license. Therefore any rights, title and interest in
24+
* our trademarks remain entirely with us.
25+
*/
26+
27+
namespace Shopware\Tests\Functional\Components\Cart;
28+
29+
use Doctrine\DBAL\Connection;
30+
use Shopware\Tests\Functional\Components\CheckoutTest;
31+
use Shopware\Tests\Functional\Traits\ContainerTrait;
32+
use Shopware\Tests\Functional\Traits\DatabaseTransactionBehaviour;
33+
34+
class CartDatabaseViewTest extends CheckoutTest
35+
{
36+
use ContainerTrait;
37+
use DatabaseTransactionBehaviour;
38+
39+
public bool $clearBasketOnReset = false;
40+
41+
public function testEnsureCartInViewHasSameIDsAsTheDatabase(): void
42+
{
43+
$productNumber = $this->createProduct(5, 19.00);
44+
45+
$this->loginFrontendCustomer();
46+
47+
$this->addProduct($productNumber);
48+
$this->visitConfirm();
49+
50+
$cartItems = $this->View()->getAssign('sBasket')['content'];
51+
$cartPositionIds = array_map('\intval', array_column($cartItems, 'id'));
52+
53+
$connection = $this->getContainer()->get(Connection::class);
54+
$preparedStatement = $connection->prepare('SELECT id FROM s_order_basket WHERE id = :id');
55+
foreach ($cartPositionIds as $cartPositionId) {
56+
$preparedStatement->bindValue('id', $cartPositionId);
57+
$cartPositionDatabaseId = (int) $preparedStatement->executeQuery()->fetchOne();
58+
static::assertSame($cartPositionId, $cartPositionDatabaseId, 'Cart position in view is not the same as in the database.');
59+
}
60+
}
61+
}

tests/Functional/Components/Cart/CartRaceConditionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828

2929
use Doctrine\DBAL\Connection;
3030
use Shopware\Tests\Functional\Components\CheckoutTest;
31+
use Shopware\Tests\Functional\Traits\DatabaseTransactionBehaviour;
3132

3233
class CartRaceConditionTest extends CheckoutTest
3334
{
35+
use DatabaseTransactionBehaviour;
36+
3437
public bool $clearBasketOnReset = false;
3538

3639
public function testPriceChangesInConfirmWithoutPriceModifications(): void

0 commit comments

Comments
 (0)