Merge branch '1.9' into 1.10

* 1.9:
  [Behat][Shop] Refactor name of step for selecting product option
  Add previous exception to DeleteHandlingException
  Wrap resource deletion operation with a transaction
  [Behat] Describe scenario for messing up products assignments after trying to delete taxon
This commit is contained in:
Grzegorz Sadowski 2021-07-02 10:14:12 +02:00
commit ad39560e0b
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
9 changed files with 108 additions and 10 deletions

View file

@ -26,7 +26,7 @@ Feature: Viewing diagonal variants options
@ui @javascript
Scenario: Viewing an "Unavailable" message when selecting an unavailable combination
When I view product "Extra Cool T-Shirt"
And I set its color to "Blue"
And I set its size to "Small"
And I select its color as "Blue"
And I select its size as "Small"
Then I should see that the combination is "Unavailable"
And I should be unable to add it to the cart

View file

@ -19,5 +19,5 @@ Feature: Viewing different price for different product variants selected with op
@ui @javascript
Scenario: Viewing a detailed page with product's price for different option
When I view product "Wyborowa Vodka"
And I set its volume to "0,7L"
And I select its volume as "0,7L"
Then I should see the product price "$25.00"

View file

@ -0,0 +1,29 @@
@managing_taxons
Feature: Displaying products in proper taxon after trying to delete this taxon
In order not to mess up the products to taxons assignments
As an Administrator
I want to keep the taxons structure the same after failed taxon deletion
Background:
Given the store operates on a channel named "Web"
And the store classifies its products as "T-Shirts"
And the "T-Shirts" taxon has children taxon "Men" and "Women"
And the store has a product "T-Shirt Coconut" available in "Web" channel
And this product belongs to "T-Shirts"
And the store has a product "T-Shirt Banana" available in "Web" channel
And this product belongs to "Men"
And the product "T-Shirt Banana" has a main taxon "Men"
And the store has a product "T-Shirt Apple" available in "Web" channel
And this product belongs to "Men"
And the store has a product "T-Shirt Pear" available in "Web" channel
And this product belongs to "Women"
And the store has a product "T-Shirt Watermelon" available in "Web" channel
And this product belongs to "Women"
And I am logged in as an administrator
@ui @javascript
Scenario: Displaying products in proper taxon after trying to delete this taxon
When I try to delete taxon named "Men"
Then I should be notified that I cannot delete a taxon in use
And I should see in taxon "Men" in the store products "T-Shirt Banana" and "T-Shirt Apple"
But I should not see in taxon "Men" in the store products "T-Shirt Pear" and "T-Shirt Watermelon"

View file

@ -405,6 +405,17 @@ final class ManagingTaxonsContext implements Context
);
}
/**
* @Then I should be notified that I cannot delete a taxon in use
*/
public function iShouldBeNotifiedThatICannotDeleteATaxonInUse(): void
{
$this->notificationChecker->checkNotification(
'Cannot delete, the taxon is in use.',
NotificationType::failure()
);
}
/**
* @When I move up :taxonName taxon
*/

View file

@ -282,6 +282,30 @@ final class ProductContext implements Context
Assert::false($this->indexPage->isProductOnList($productName));
}
/**
* @Then I should see in taxon :taxon in the store products :firstProductName and :secondProductName
*/
public function iShouldSeeInTaxonInTheStoreProducts(TaxonInterface $taxon, string ...$productNames): void
{
$this->iCheckListOfProductsForTaxon($taxon);
foreach ($productNames as $productName) {
Assert::true($this->indexPage->isProductOnList($productName));
}
}
/**
* @Then I should not see in taxon :taxon in the store products :firstProductName and :secondProductName
*/
public function iShouldNotSeeInTaxonInTheStoreProducts(TaxonInterface $taxon, string ...$productNames): void
{
$this->iCheckListOfProductsForTaxon($taxon);
foreach ($productNames as $productName) {
Assert::false($this->indexPage->isProductOnList($productName));
}
}
/**
* @Then I should see empty list of products
*/
@ -335,9 +359,9 @@ final class ProductContext implements Context
}
/**
* @When I set its :optionName to :optionValue
* @When I select its :optionName as :optionValue
*/
public function iSetItsOptionTo($optionName, $optionValue)
public function iSelectItsOptionAs(string $optionName, string $optionValue): void
{
$this->showPage->selectOption($optionName, $optionValue);
}

View file

@ -9,17 +9,21 @@ default:
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.taxon
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.locale
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.product
- sylius.behat.context.setup.product_taxon
- sylius.behat.context.setup.taxonomy
- sylius.behat.context.ui.admin.managing_taxons
- sylius.behat.context.ui.admin.removing_taxons
- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.shop.product
filters:
tags: "@managing_taxons && @ui"

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM\Handler;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
use Sylius\Bundle\ResourceBundle\Controller\ResourceDeleteHandlerInterface;
use Sylius\Component\Resource\Exception\DeleteHandlingException;
@ -24,9 +25,13 @@ final class ResourceDeleteHandler implements ResourceDeleteHandlerInterface
/** @var ResourceDeleteHandlerInterface */
private $decoratedHandler;
public function __construct(ResourceDeleteHandlerInterface $decoratedHandler)
/** @var EntityManagerInterface */
private $entityManager;
public function __construct(ResourceDeleteHandlerInterface $decoratedHandler, EntityManagerInterface $entityManager)
{
$this->decoratedHandler = $decoratedHandler;
$this->entityManager = $entityManager;
}
/**
@ -34,10 +39,22 @@ final class ResourceDeleteHandler implements ResourceDeleteHandlerInterface
*/
public function handle(ResourceInterface $resource, RepositoryInterface $repository): void
{
$this->entityManager->beginTransaction();
try {
$this->decoratedHandler->handle($resource, $repository);
$this->entityManager->commit();
} catch (ORMException $exception) {
throw new DeleteHandlingException();
$this->entityManager->rollback();
throw new DeleteHandlingException(
'Ups, something went wrong during deleting a resource, please try again.',
'something_went_wrong_error',
500,
0,
$exception
);
}
}
}

View file

@ -227,6 +227,11 @@
<argument type="service" id="sylius.custom_resource_controller.resource_update_handler.inner" />
</service>
<service id="sylius.custom_resource_controller.resource_delete_handler" class="Sylius\Bundle\CoreBundle\Doctrine\ORM\Handler\ResourceDeleteHandler" decorates="sylius.resource_controller.resource_delete_handler" public="false">
<argument type="service" id="sylius.custom_resource_controller.resource_delete_handler.inner" />
<argument type="service" id="doctrine.orm.entity_manager" />
</service>
<service id="sylius.order_item_names_setter" class="Sylius\Component\Core\Order\OrderItemNamesSetter" />
<service id="Sylius\Component\Core\Order\OrderItemNamesSetterInterface" alias="sylius.order_item_names_setter" />

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace spec\Sylius\Bundle\CoreBundle\Doctrine\ORM\Handler;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ResourceBundle\Controller\ResourceDeleteHandlerInterface;
@ -22,9 +23,9 @@ use Sylius\Component\Resource\Repository\RepositoryInterface;
final class ResourceDeleteHandlerSpec extends ObjectBehavior
{
function let(ResourceDeleteHandlerInterface $decoratedHandler): void
function let(ResourceDeleteHandlerInterface $decoratedHandler, EntityManagerInterface $entityManager): void
{
$this->beConstructedWith($decoratedHandler);
$this->beConstructedWith($decoratedHandler, $entityManager);
}
function it_implements_resource_delete_handler_interface(): void
@ -34,20 +35,27 @@ final class ResourceDeleteHandlerSpec extends ObjectBehavior
function it_uses_decorated_handler_to_handle_resource_deletion(
ResourceDeleteHandlerInterface $decoratedHandler,
EntityManagerInterface $entityManager,
RepositoryInterface $repository,
ResourceInterface $resource
): void {
$entityManager->beginTransaction()->shouldBeCalled();
$decoratedHandler->handle($resource, $repository)->shouldBeCalled();
$entityManager->commit()->shouldBeCalled();
$this->handle($resource, $repository);
}
function it_throws_delete_handling_exception_if_something_gone_wrong_with_orm_while_deleting_resource(
ResourceDeleteHandlerInterface $decoratedHandler,
EntityManagerInterface $entityManager,
RepositoryInterface $repository,
ResourceInterface $resource
): void {
$entityManager->beginTransaction()->shouldBeCalled();
$decoratedHandler->handle($resource, $repository)->willThrow(ORMException::class);
$entityManager->commit()->shouldNotBeCalled();
$entityManager->rollback()->shouldBeCalled();
$this->shouldThrow(DeleteHandlingException::class)->during('handle', [$resource, $repository]);
}