Merge branch '1.11' into 1.12

* 1.11:
  [Behat] Fix return type of cart transformer
  [Behat] Fix problem with duplicated step in cart contexts
  [Behat][Admin] Cover trying to show cart in the admin panel
  Changing the naming of the order function
  Throwing a not found when order is still a cart
This commit is contained in:
Rafikooo 2023-01-31 16:10:45 +01:00
commit 63ed46f0d0
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B
8 changed files with 91 additions and 4 deletions

View file

@ -0,0 +1,16 @@
@managing_orders
Feature: Being unable to see details of a cart
In order to see details only of a placed order
As an Administrator
I want to be unable to view basic information about a cart
Background:
Given the store operates on a single channel in "United States"
And the store has a product "PHP T-Shirt" priced at "$12.00"
And the customer added "PHP T-Shirt" product to the cart
And I am logged in as an administrator
@ui
Scenario: Seeing basic information about an order
When I try to view the summary of the customer's latest cart
Then I should be informed that the order does not exist

View file

@ -15,11 +15,16 @@ namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Webmozart\Assert\Assert;
final class CartTokenContext implements Context
final class CartContext implements Context
{
public function __construct(private SharedStorageInterface $sharedStorage)
{
public function __construct(
private OrderRepositoryInterface $orderRepository,
private SharedStorageInterface $sharedStorage,
) {
}
/**
@ -45,4 +50,20 @@ final class CartTokenContext implements Context
return $this->provideCartToken();
}
/**
* @Transform /^(customer's latest cart)$/
*/
public function provideLatestCart(): OrderInterface
{
$carts = $this->orderRepository->findBy(
['state' => OrderInterface::STATE_CART],
['createdAt' => 'DESC'],
1,
);
Assert::count($carts, 1);
return $carts[0];
}
}

View file

@ -19,6 +19,7 @@ use Sylius\Behat\Page\Admin\Order\HistoryPageInterface;
use Sylius\Behat\Page\Admin\Order\IndexPageInterface;
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
use Sylius\Behat\Page\Admin\Order\UpdatePageInterface;
use Sylius\Behat\Page\ErrorPageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Behat\Service\SharedSecurityServiceInterface;
use Sylius\Behat\Service\SharedStorageInterface;
@ -36,6 +37,7 @@ final class ManagingOrdersContext implements Context
private ShowPageInterface $showPage,
private UpdatePageInterface $updatePage,
private HistoryPageInterface $historyPage,
private ErrorPageInterface $errorPage,
private NotificationCheckerInterface $notificationChecker,
private SharedSecurityServiceInterface $sharedSecurityService,
) {
@ -67,6 +69,14 @@ final class ManagingOrdersContext implements Context
$this->showPage->open(['id' => $order->getId()]);
}
/**
* @When /^I try to view the summary of the (customer's latest cart)$/
*/
public function iTryToViewTheSummaryOfTheCustomersLatestCart(OrderInterface $cart): void
{
$this->showPage->tryToOpen(['id' => $cart->getId()]);
}
/**
* @When /^I mark (this order) as paid$/
*/
@ -961,6 +971,14 @@ final class ManagingOrdersContext implements Context
Assert::same($this->showPage->getShippedAtDate(), $dateTime);
}
/**
* @Then I should be informed that the order does not exist
*/
public function iShouldBeInformedThatTheOrderDoesNotExist(): void
{
Assert::same($this->errorPage->getCode(), 404);
}
/**
* @param string $type
* @param string $element

View file

@ -75,6 +75,7 @@
<service id="sylius.behat.context.transform.order" class="Sylius\Behat\Context\Transform\OrderContext">
<argument type="service" id="sylius.repository.customer" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>
<service id="sylius.behat.context.transform.payment" class="Sylius\Behat\Context\Transform\PaymentMethodContext">
@ -159,7 +160,8 @@
<argument type="service" id="sylius.behat.shared_storage" />
</service>
<service id="sylius.behat.context.transform.cart" class="Sylius\Behat\Context\Transform\CartTokenContext">
<service id="sylius.behat.context.transform.cart" class="Sylius\Behat\Context\Transform\CartContext">
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

View file

@ -125,6 +125,7 @@
<argument type="service" id="sylius.behat.page.admin.order.show" />
<argument type="service" id="sylius.behat.page.admin.order.update" />
<argument type="service" id="sylius.behat.page.admin.order.history" />
<argument type="service" id="sylius.behat.page.error" />
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="sylius.behat.shared_security" />
</service>

View file

@ -31,6 +31,7 @@ default:
- Sylius\Calendar\Tests\Behat\Context\Setup\CalendarContext
- sylius.behat.context.transform.address
- sylius.behat.context.transform.cart
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.country
- sylius.behat.context.transform.currency

View file

@ -20,6 +20,10 @@ sylius_admin_order_show:
_controller: sylius.controller.order::showAction
_sylius:
section: admin
repository:
method: findOrderById
arguments:
- '$id'
permission: true
template: "@SyliusAdmin/Order/show.html.twig"
@ -30,6 +34,10 @@ sylius_admin_order_history:
_controller: sylius.controller.order::showAction
_sylius:
section: admin
repository:
method: findOrderById
arguments:
- '$id'
permission: true
template: "@SyliusAdmin/Order/history.html.twig"
@ -40,6 +48,10 @@ sylius_admin_order_update:
_controller: sylius.controller.order::updateAction
_sylius:
section: admin
repository:
method: findOrderById
arguments:
- '$id'
permission: true
template: "@SyliusAdmin/Order/update.html.twig"
form:
@ -53,6 +65,10 @@ sylius_admin_order_cancel:
defaults:
_controller: sylius.controller.order::applyStateMachineTransitionAction
_sylius:
repository:
method: findOrderById
arguments:
- '$id'
permission: true
state_machine:
graph: sylius_order

View file

@ -39,6 +39,18 @@ class OrderRepository extends BaseOrderRepository implements OrderRepositoryInte
$this->associationHydrator = new AssociationHydrator($entityManager, $class);
}
public function findOrderById(string $id): ?OrderInterface
{
return $this->createQueryBuilder('o')
->andWhere('o.id = :id')
->andWhere('o.state != :state')
->setParameter('id', $id)
->setParameter('state', OrderInterface::STATE_CART)
->getQuery()
->getOneOrNullResult()
;
}
public function createListQueryBuilder(): QueryBuilder
{
return $this->createQueryBuilder('o')