mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[API] Finish covering viewing product attributes
This commit is contained in:
parent
d9f9022660
commit
46f3afb02b
6 changed files with 87 additions and 50 deletions
|
|
@ -17,24 +17,24 @@ Feature: Viewing product's select attributes
|
|||
Then I should see the product attribute "T-Shirt material" with value "Banana skin" on the list
|
||||
And I should also see the product attribute "T-Shirt material" with value "Cotton" on the list
|
||||
|
||||
@ui
|
||||
@ui @api
|
||||
Scenario: Viewing a detailed page with product's select attribute after changing a value
|
||||
Given this product has select attribute "T-Shirt material" with values "Banana skin" and "Cotton"
|
||||
When the administrator changes this product attribute's value "Cotton" to "Orange skin"
|
||||
When this product attribute's value changed from "Cotton" to "Orange skin"
|
||||
And I check this product's details
|
||||
Then I should see the product attribute "T-Shirt material" with value "Banana skin" on the list
|
||||
And I should also see the product attribute "T-Shirt material" with value "Orange skin" on the list
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api @no-postgres
|
||||
Scenario: Viewing a detailed page with product's select attribute after removing an only value
|
||||
Given this product has select attribute "T-Shirt material" with value "Cotton"
|
||||
When the administrator deletes the value "Cotton" from this product attribute
|
||||
When this product attribute's value "Cotton" has been removed
|
||||
And I check this product's details
|
||||
Then I should not see the product attribute "T-Shirt material"
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api @no-postgres
|
||||
Scenario: Viewing a detailed page with product's select attribute after removing one of the value
|
||||
Given this product has select attribute "T-Shirt material" with values "Banana skin" and "Cotton"
|
||||
When the administrator deletes the value "Cotton" from this product attribute
|
||||
When this product attribute's value "Cotton" has been removed
|
||||
And I check this product's details
|
||||
Then I should see the product attribute "T-Shirt material" with value "Banana skin"
|
||||
|
|
|
|||
|
|
@ -37,8 +37,15 @@ final class ProductAttributeContext implements Context
|
|||
public function iShouldSeeTheProductAttributeWithValue(string $attributeName, string $expectedAttribute): void
|
||||
{
|
||||
$attribute = $this->getAttributeByName($attributeName);
|
||||
$attributeValue = $attribute['value'];
|
||||
|
||||
Assert::same($attribute['value'], $expectedAttribute);
|
||||
if (is_array($attributeValue)) {
|
||||
Assert::inArray($expectedAttribute, $attributeValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Assert::same($attributeValue, $expectedAttribute);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,6 +78,14 @@ final class ProductAttributeContext implements Context
|
|||
Assert::inArray($expectedAttribute, $attribute['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should not see the product attribute :attributeName
|
||||
*/
|
||||
public function iShouldNotSeeTheProductAttribute(string $attributeName): void
|
||||
{
|
||||
Assert::false($this->hasAttributeByName($attributeName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should (also) see the product attribute :attributeName with date :expectedAttribute
|
||||
*/
|
||||
|
|
@ -113,6 +128,17 @@ final class ProductAttributeContext implements Context
|
|||
Assert::same($attribute['name'], $name);
|
||||
}
|
||||
|
||||
private function hasAttributeByName(string $name): bool
|
||||
{
|
||||
foreach ($this->getAttributes() as $attribute) {
|
||||
if ($attribute['name'] === $name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getAttributeByName(string $name): array
|
||||
{
|
||||
foreach ($this->getAttributes() as $attribute) {
|
||||
|
|
|
|||
|
|
@ -423,6 +423,59 @@ final class ProductAttributeContext implements Context
|
|||
$this->objectManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^(this product attribute)'s value changed from "([^"]+)" to "([^"]+)"$/
|
||||
*/
|
||||
public function thisAttributeValueChangedFromTo(
|
||||
ProductAttributeInterface $attribute,
|
||||
string $from,
|
||||
string $to,
|
||||
): void {
|
||||
$configuration = $attribute->getConfiguration();
|
||||
$choices = $configuration['choices'] ?? [];
|
||||
|
||||
foreach ($choices as $uuid => $choice) {
|
||||
foreach ($choice as $localeCode => $item) {
|
||||
if ($item === $from) {
|
||||
$choices[$uuid][$localeCode] = $to;
|
||||
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configuration['choices'] = $choices;
|
||||
$attribute->setConfiguration($configuration);
|
||||
|
||||
$this->objectManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^(this product attribute)'s value "([^"]+)" has been removed$/
|
||||
*/
|
||||
public function thisAttributeValueHasBeenRemoved(
|
||||
ProductAttributeInterface $attribute,
|
||||
string $value,
|
||||
): void {
|
||||
$configuration = $attribute->getConfiguration();
|
||||
$choices = $configuration['choices'] ?? [];
|
||||
|
||||
foreach ($choices as $uuid => $choice) {
|
||||
foreach ($choice as $item) {
|
||||
if ($value === $item) {
|
||||
unset($choices[$uuid]);
|
||||
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configuration['choices'] = $choices;
|
||||
$attribute->setConfiguration($configuration);
|
||||
|
||||
$this->objectManager->flush();
|
||||
}
|
||||
|
||||
private function createProductAttribute(
|
||||
string $type,
|
||||
string $name,
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
|
|||
use Sylius\Behat\Page\Admin\ProductAttribute\CreatePageInterface;
|
||||
use Sylius\Behat\Page\Admin\ProductAttribute\UpdatePageInterface;
|
||||
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
|
||||
use Sylius\Behat\Service\SharedSecurityServiceInterface;
|
||||
use Sylius\Component\Core\Model\AdminUserInterface;
|
||||
use Sylius\Component\Product\Model\ProductAttributeInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
|
|
@ -30,7 +28,6 @@ final class ManagingProductAttributesContext implements Context
|
|||
private IndexPageInterface $indexPage,
|
||||
private UpdatePageInterface $updatePage,
|
||||
private CurrentPageResolverInterface $currentPageResolver,
|
||||
private SharedSecurityServiceInterface $sharedSecurityService,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -233,25 +230,6 @@ final class ManagingProductAttributesContext implements Context
|
|||
$this->indexPage->open();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^(the administrator) changes (this product attribute)'s value "([^"]*)" to "([^"]*)"$/
|
||||
*/
|
||||
public function theAdministratorChangesThisProductAttributesValueTo(
|
||||
AdminUserInterface $user,
|
||||
ProductAttributeInterface $productAttribute,
|
||||
string $oldValue,
|
||||
string $newValue,
|
||||
): void {
|
||||
$this->sharedSecurityService->performActionAsAdminUser(
|
||||
$user,
|
||||
function () use ($productAttribute, $oldValue, $newValue) {
|
||||
$this->iWantToEditThisAttribute($productAttribute);
|
||||
$this->iChangeItsValueTo($oldValue, $newValue);
|
||||
$this->iSaveMyChanges();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its min length as :min
|
||||
* @When I specify its min entries value as :min
|
||||
|
|
@ -286,24 +264,6 @@ final class ManagingProductAttributesContext implements Context
|
|||
// Intentionally left blank to fulfill context expectation
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^(the administrator) deletes the value "([^"]+)" from (this product attribute)$/
|
||||
*/
|
||||
public function theAdministratorDeletesTheValueFromThisProductAttribute(
|
||||
AdminUserInterface $user,
|
||||
string $value,
|
||||
ProductAttributeInterface $productAttribute,
|
||||
): void {
|
||||
$this->sharedSecurityService->performActionAsAdminUser(
|
||||
$user,
|
||||
function () use ($productAttribute, $value) {
|
||||
$this->iWantToEditThisAttribute($productAttribute);
|
||||
$this->iDeleteValue($value);
|
||||
$this->iSaveMyChanges();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I check (also) the :productAttributeName product attribute
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -207,7 +207,6 @@
|
|||
<argument type="service" id="sylius.behat.page.admin.product_attribute.index" />
|
||||
<argument type="service" id="sylius.behat.page.admin.product_attribute.update" />
|
||||
<argument type="service" id="sylius.behat.current_page_resolver" />
|
||||
<argument type="service" id="sylius.behat.shared_security" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.ui.admin.managing_product_options" class="Sylius\Behat\Context\Ui\Admin\ManagingProductOptionsContext">
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ default:
|
|||
- sylius.behat.context.transform.taxon
|
||||
- Sylius\Behat\Context\Transform\CatalogPromotionContext
|
||||
|
||||
# - sylius.behat.context.setup.admin_user
|
||||
# - sylius.behat.context.setup.admin_api_security
|
||||
- sylius.behat.context.setup.admin_user
|
||||
- sylius.behat.context.setup.channel
|
||||
- sylius.behat.context.setup.customer
|
||||
- sylius.behat.context.setup.locale
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue