Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6508 from GSadee/product-association-type
[Admin][ProductAssociationType] CRUD
- Loading branch information
Showing
29 changed files
with
871 additions
and
5 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
features/product/managing_product_association_types/adding_product_association.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@managing_product_association_types | ||
Feature: Adding a new product association type | ||
In order to connect products together in many contexts | ||
As an Administrator | ||
I want to add a new product association type to the store | ||
|
||
Background: | ||
Given I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Adding a new product association type | ||
When I want to create a new product association type | ||
And I specify its code as "cross_sell" | ||
And I specify its name as "Cross sell" | ||
And I add it | ||
Then I should be notified that it has been successfully created | ||
And the product association type "Cross sell" should appear in the store |
16 changes: 16 additions & 0 deletions
16
...res/product/managing_product_association_types/browsing_product_association_types.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@managing_product_association_types | ||
Feature: Browsing product association types | ||
In order to see all product association types in the store | ||
As an Administrator | ||
I want to browse product association types | ||
|
||
Background: | ||
Given the store has a product association type "Cross sell" | ||
And the store has also a product association type "Up sell" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Browsing product association types in the store | ||
When I want to browse product association types | ||
Then I should see 2 product association types in the list | ||
And I should see the product association type "Cross sell" in the list |
15 changes: 15 additions & 0 deletions
15
...ures/product/managing_product_association_types/deleting_product_association_type.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@managing_product_association_types | ||
Feature: Deleting product association types | ||
In order to remove test, obsolete or incorrect product association types | ||
As an Administrator | ||
I want to be able to delete a product association type | ||
|
||
Background: | ||
Given the store has a product association type "Cross sell" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Deleting a product association type | ||
When I delete the "Cross sell" product association type | ||
Then I should be notified that it has been successfully deleted | ||
And this product association type should no longer exist in the registry |
22 changes: 22 additions & 0 deletions
22
features/product/managing_product_association_types/editing_product_association_type.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@managing_product_association_types | ||
Feature: Editing a product association type | ||
In order to change information about a product association type | ||
As an Administrator | ||
I want to be able to edit the product association type | ||
|
||
Background: | ||
Given the store has a product association type "Cross sell" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Changing a name of an existing product association type | ||
When I want to modify the "Cross sell" product association type | ||
And I rename it to "Up sell" | ||
And I save my changes | ||
Then I should be notified that it has been successfully edited | ||
And this product association type name should be "Up sell" | ||
|
||
@ui | ||
Scenario: Seeing a disabled code field while editing a product association type | ||
When I want to modify the "Cross sell" product association type | ||
Then the code field should be disabled |
18 changes: 18 additions & 0 deletions
18
...anaging_product_association_types/product_association_type_unique_code_validation.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@managing_product_association_types | ||
Feature: Product association type unique code validation | ||
In order to uniquely identify product association types | ||
As an Administrator | ||
I want to be prevented from adding two product association types with the same code | ||
|
||
Background: | ||
Given the store has a product association type "Cross sell" with a code "cross_sell" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Trying to add a new product association type with a taken code | ||
When I want to create a new product association type | ||
And I specify its code as "cross_sell" | ||
And I specify its name as "Cross sell" | ||
And I try to add it | ||
Then I should be notified that product association type with this code already exists | ||
And there should still be only one product association type with a code "cross_sell" |
35 changes: 35 additions & 0 deletions
35
...es/product/managing_product_association_types/product_association_type_validation.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@managing_product_association_types | ||
Feature: Product association type validation | ||
In order to avoid making mistakes when managing a product association type | ||
As an Administrator | ||
I want to be prevented from adding it without specifying required fields | ||
|
||
Background: | ||
Given the store has a product association type "Cross sell" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Trying to add a new product association type without specifying its code | ||
When I want to create a new product association type | ||
And I specify its name as "Up sell" | ||
But I do not specify its code | ||
And I try to add it | ||
Then I should be notified that code is required | ||
And the product association type with name "Up sell" should not be added | ||
|
||
@ui | ||
Scenario: Trying to add a new product association type without specifying its name | ||
When I want to create a new product association type | ||
And I specify its code as "up_sell" | ||
But I do not name it | ||
And I try to add it | ||
Then I should be notified that name is required | ||
And the product association type with code "up_sell" should not be added | ||
|
||
@ui | ||
Scenario: Trying to remove name from an existing product association type | ||
When I want to modify the "Cross sell" product association type | ||
And I remove its name | ||
And I try to save my changes | ||
Then I should be notified that name is required | ||
And this product association type should still be named "Cross sell" |
92 changes: 92 additions & 0 deletions
92
src/Sylius/Behat/Context/Setup/ProductAssociationTypeContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Behat\Context\Setup; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Service\SharedStorageInterface; | ||
use Sylius\Component\Association\Model\AssociationTypeInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
|
||
/** | ||
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com> | ||
*/ | ||
final class ProductAssociationTypeContext implements Context | ||
{ | ||
/** | ||
* @var SharedStorageInterface | ||
*/ | ||
private $sharedStorage; | ||
|
||
/** | ||
* @var FactoryInterface | ||
*/ | ||
private $productAssociationTypeFactory; | ||
|
||
/** | ||
* @var RepositoryInterface | ||
*/ | ||
private $productAssociationTypeRepository; | ||
|
||
/** | ||
* @param SharedStorageInterface $sharedStorage | ||
* @param FactoryInterface $productAssociationTypeFactory | ||
* @param RepositoryInterface $productAssociationTypeRepository | ||
*/ | ||
public function __construct( | ||
SharedStorageInterface $sharedStorage, | ||
FactoryInterface $productAssociationTypeFactory, | ||
RepositoryInterface $productAssociationTypeRepository | ||
) { | ||
$this->sharedStorage = $sharedStorage; | ||
$this->productAssociationTypeFactory = $productAssociationTypeFactory; | ||
$this->productAssociationTypeRepository = $productAssociationTypeRepository; | ||
} | ||
|
||
/** | ||
* @Given the store has (also) a product association type :name | ||
* @Given the store has (also) a product association type :name with a code :code | ||
*/ | ||
public function theStoreHasAProductAssociationType($name, $code = null) | ||
{ | ||
$this->createProductAssociationType($name, $code); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param string|null $code | ||
*/ | ||
private function createProductAssociationType($name, $code = null) | ||
{ | ||
if (null === $code) { | ||
$code = $this->generateCodeFromName($name); | ||
} | ||
|
||
/** @var AssociationTypeInterface $productAssociationType */ | ||
$productAssociationType = $this->productAssociationTypeFactory->createNew(); | ||
$productAssociationType->setCode($code); | ||
$productAssociationType->setName($name); | ||
|
||
$this->productAssociationTypeRepository->add($productAssociationType); | ||
$this->sharedStorage->set('product_association_type', $productAssociationType); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
private function generateCodeFromName($name) | ||
{ | ||
return str_replace([' ', '-'], '_', strtolower($name)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/Sylius/Behat/Context/Transform/ProductAssociationTypeContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sylius\Behat\Context\Transform; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com> | ||
*/ | ||
final class ProductAssociationTypeContext implements Context | ||
{ | ||
/** | ||
* @var RepositoryInterface | ||
*/ | ||
private $productAssociationTypeRepository; | ||
|
||
/** | ||
* @param RepositoryInterface $productAssociationTypeRepository | ||
*/ | ||
public function __construct(RepositoryInterface $productAssociationTypeRepository) | ||
{ | ||
$this->productAssociationTypeRepository = $productAssociationTypeRepository; | ||
} | ||
|
||
/** | ||
* @Transform :productAssociationType | ||
*/ | ||
public function getProductAssociationTypeByName($productAssociationTypeName) | ||
{ | ||
$productAssociationType = $this->productAssociationTypeRepository->findOneBy([ | ||
'name' => $productAssociationTypeName, | ||
]); | ||
|
||
Assert::notNull( | ||
$productAssociationType, | ||
sprintf('Cannot find product association type with name %s', $productAssociationTypeName) | ||
); | ||
|
||
return $productAssociationType; | ||
} | ||
} |
Oops, something went wrong.