Skip to content

Commit

Permalink
Merge pull request #1 from Arminek/attribute_select_behat
Browse files Browse the repository at this point in the history
[Behat] Add scenarios for adding select attribute type
  • Loading branch information
Lowlo committed Feb 17, 2017
2 parents 65a9194 + 5bd4d1f commit 311785e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
@@ -0,0 +1,35 @@
@managing_product_attributes
Feature: Adding a new select product attribute
In order to show specific product's parameters to customer
As an Administrator
I want to add a new select product attribute

Background:
Given the store is available in "English (United States)"
And I am logged in as an administrator

@ui @javascript
Scenario: Adding a new select product attribute
Given I want to create a new select product attribute
When I specify its code as "mug_material"
And I name it "Mug material" in "English (United States)"
And I add material "Banana Skin"
And I add it
Then I should be notified that it has been successfully created
And the select attribute "Mug material" should appear in the store

@ui @javascript
Scenario: Adding multiple select product attribute
Given I want to create a new select product attribute
When I specify its code as "mug_material"
And I name it "Mug material" in "English (United States)"
And I add material "Banana Skin"
And I also add material "Plastic"
And I add it
Then I should be notified that it has been successfully created
And the select attribute "Mug material" should appear in the store

@ui
Scenario: Seeing disabled type field while adding a select product attribute
When I want to create a new select product attribute
Then the type field should be disabled
Expand Up @@ -28,6 +28,13 @@ Feature: Viewing product's attributes
When I check this product's details
Then I should see the product attribute "T-shirt with cotton" with value "Yes"

@ui
Scenario: Viewing a detailed page with product's select attribute
Given the store has a product "T-shirt banana"
And this product has select attribute "T-shirt material" with values "Banana skin", "cotton"
When I check this product's details
Then I should see the product attribute "T-shirt material" with value "Banana skin cotton"

@ui
Scenario: Viewing a detailed page with product's date attribute
Given the store has a product "T-shirt banana"
Expand Down
21 changes: 21 additions & 0 deletions src/Sylius/Behat/Context/Setup/ProductAttributeContext.php
Expand Up @@ -104,6 +104,27 @@ public function theStoreHasATextProductAttribute($type, $name)
$this->saveProductAttribute($productAttribute);
}

/**
* @Given /^(this product) has (.+?) attribute "([^"]+)" with values "([^"]+)", "([^"]+)"$/
*/
public function thisProductHasSelectAttributeWithValues(
ProductInterface $product,
$productAttributeType,
$productAttributeName,
$firstAttributeValue,
$secondAttributeValue,
$language = 'en_US'
) {
$values = [$firstAttributeValue, $secondAttributeValue];

$attribute = $this->provideProductAttribute($productAttributeType, $productAttributeName);
$attribute->setConfiguration(['multiple' => true, 'choices' => $values, 'min' => null, 'max' => null]);
$attributeValue = $this->createProductAttributeValue(array_keys($values), $attribute, $language);
$product->addAttribute($attributeValue);

$this->objectManager->flush();
}

/**
* @Given /^(this product) has (.+?) attribute "([^"]+)" with value "([^"]+)"$/
* @Given /^(this product) has (.+?) attribute "([^"]+)" with value "([^"]+)" in ("[^"]+" locale)$/
Expand Down
Expand Up @@ -96,6 +96,14 @@ public function iAddIt()
$this->createPage->create();
}

/**
* @When /^I(?:| also) add material "([^"]+)"/
*/
public function iAddMaterial($materialName)
{
$this->createPage->addAttributeValue($materialName);
}

/**
* @Then I should see the product attribute :name in the list
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Sylius/Behat/Page/Admin/ProductAttribute/CreatePage.php
Expand Up @@ -21,6 +21,11 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
{
use SpecifiesItsCode;

/**
* @var int
*/
private $choiceListIndex = 0;

/**
* {@inheritdoc}
*/
Expand All @@ -37,12 +42,24 @@ public function isTypeDisabled()
return 'disabled' === $this->getElement('type')->getAttribute('disabled');
}

/**
* {@inheritdoc}
*/
public function addAttributeValue($value)
{
$this->getDocument()->clickLink('Add');
$this->getElement('attribute_choice_list_element', ['%index%' => $this->choiceListIndex])->setValue($value);
$this->choiceListIndex++;
}

/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'attribute_choice_list' => 'div[data-form-collection="list"]',
'attribute_choice_list_element' => '#sylius_product_attribute_configuration_choices_%index%',
'code' => '#sylius_product_attribute_code',
'name' => '#sylius_product_attribute_translations_en_US_name',
'type' => '#sylius_product_attribute_type',
Expand Down
Expand Up @@ -33,4 +33,9 @@ public function nameIt($name, $language);
* @return bool
*/
public function isTypeDisabled();

/**
* @param string $value
*/
public function addAttributeValue($value);
}

0 comments on commit 311785e

Please sign in to comment.