Skip to content

Commit

Permalink
Fix for test and configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Mar 13, 2020
1 parent ae449cd commit 40389ba
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 29 deletions.
57 changes: 43 additions & 14 deletions src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,29 @@

use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Webmozart\Assert\Assert;

final class ManagingProductsContext implements Context
{
/** @var ApiClientInterface */
private $client;

public function __construct(ApiClientInterface $client)
/** @var ResponseCheckerInterface */
private $responseChecker;

public function __construct(ApiClientInterface $client, ResponseCheckerInterface $responseChecker)
{
$this->client = $client;
$this->responseChecker = $responseChecker;
}

/**
* @When I want to create a new configurable product
*/
public function iWantToCreateANewConfigurableProduct(): void
{
$this->client->buildCreateRequest('products');
$this->client->buildCreateRequest();
}

/**
Expand All @@ -45,27 +50,39 @@ public function iSpecifyItsCodeAs(string $code = null): void
}

/**
* @When I name it :name in :language
* @When I rename it to :name in :language
* @When I name it :name in :localeCode
* @When I rename it to :name in :localeCode
*/
public function iRenameItToIn(string $name, string $language): void
public function iRenameItToIn(string $name, string $localeCode): void
{
$data = ['translations' => [$language => ['locale' => $language]]];
$data['translations'][$language]['name'] = $name;
$data = [
'translations' => [
$localeCode => [
'locale' => $localeCode,
'name' => $name,
],
],
];

$this->client->addCompoundRequestData($data);
$this->client->updateRequestData($data);
}

/**
* @When I set its slug to :slug
* @When I set its slug to :slug in :language
* @When I set its slug to :slug in :localeCode
* @When I remove its slug
*/
public function iSetItsSlugTo(?string $slug = null, $language = 'en_US'): void
public function iSetItsSlugTo(?string $slug = null, $localeCode = 'en_US'): void
{
$data = ['translations' => [$language => ['slug' => $slug]]];
$data = [
'translations' => [
$localeCode => [
'slug' => $slug,
],
],
];

$this->client->addCompoundRequestData($data);
$this->client->updateRequestData($data);
}

/**
Expand All @@ -85,8 +102,20 @@ public function iAddIt(): void
*/
public function theProductShouldAppearInTheShop(string $productName): void
{
$this->client->index('products');
$this->client->index();

Assert::true(
$this
->responseChecker
->hasItemWithTranslation($this->client->getLastResponse(),'en_US', 'name', $productName)
);
}

Assert::true($this->client->hasItemWithTranslation('en_US', 'name', $productName));
/**
* @Then I should be notified that it has been successfully created
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void
{
Assert::true($this->responseChecker->isCreationSuccessful($this->client->getLastResponse()));
}
}
6 changes: 6 additions & 0 deletions src/Sylius/Behat/Resources/config/services/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<argument>product_options</argument>
</service>

<service id="sylius.behat.api_platform_client.products" class="Sylius\Behat\Client\ApiPlatformClient">
<argument type="service" id="test.client" />
<argument type="service" id="sylius.behat.shared_storage" />
<argument>products</argument>
</service>

<service id="sylius.behat.api_platform_client.product_review" class="Sylius\Behat\Client\ApiPlatformClient">
<argument type="service" id="test.client" />
<argument type="service" id="sylius.behat.shared_storage" />
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<argument type="service" id="session" />
</service>

<service id="sylius.behat.context.api.admin.managing_products" class="Sylius\Behat\Context\Api\Admin\ManagingProductsContext">
<argument type="service" id="sylius.behat.api_platform_client.products" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
</service>

<service id="sylius.behat.context.api.admin.managing_tax_categories" class="Sylius\Behat\Context\Api\Admin\ManagingTaxCategoriesContext">
<argument type="service" id="sylius.behat.api_platform_client.tax_category" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Resources/config/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ imports:
- suites/api/currency/managing_currencies.yml
- suites/api/currency/managing_exchange_rates.yml
- suites/api/payment/managing_payments.yml
- suites/api/product/managing_products.yml
- suites/api/product/managing_product_options.yml
- suites/api/product/managing_product_reviews.yml
- suites/api/product/managing_product_variants.yml
- suites/api/product/managing_products.yml
- suites/api/shipping/managing_shipping_categories.yml
- suites/api/taxation/managing_tax_categories.yml
- suites/api/taxon/managing_taxons.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ default:
- sylius.behat.context.transform.taxon
- sylius.behat.context.transform.zone

- sylius.behat.context.setup.admin_api_security
- sylius.behat.context.setup.admin_user
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
Expand All @@ -36,14 +37,12 @@ default:
- sylius.behat.context.setup.product_option
- sylius.behat.context.setup.product_review
- sylius.behat.context.setup.product_taxon
- sylius.behat.context.setup.admin_api_security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.shipping_category
- sylius.behat.context.setup.taxonomy
- sylius.behat.context.setup.zone

- sylius.behat.context.api.admin.managing_product
- sylius.behat.context.api.admin.notification
- sylius.behat.context.api.admin.managing_products

filters:
tags: "@managing_products && @api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
shortName="ProductTranslation"
>
<attribute name="validation_groups">sylius</attribute>

<collectionOperations />

<itemOperations>
<itemOperation name="get" />
</itemOperations>

<property name="id" identifier="true" writable="false" />
<property name="name" identifier="false" required="true" />
<property name="locale" identifier="false" required="true" />
<property name="slug" identifier="false" required="true" />
<property name="description" identifier="false" required="false" />
<property name="metaKeywords" identifier="false" required="false" />
<property name="metaDescription" identifier="false" required="false" />
<property name="shortDescription" identifier="false" required="false" />
<property name="name" required="true" />
<property name="locale" required="true" />
<property name="slug" required="true" />
<property name="description" required="false" />
<property name="metaKeywords" required="false" />
<property name="metaDescription" required="false" />
<property name="shortDescription" required="false" />
</resource>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<attribute name="translations">
<group>product:read</group>
<group>product:create</group>
<group>product:update</group>
</attribute>
</class>
</serializer>
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
<attribute name="name">
<group>product:read</group>
<group>product:create</group>
<group>product:update</group>
</attribute>
<attribute name="locale">
<group>product:create</group>
<group>product:update</group>
</attribute>
<attribute name="slug">
<group>product:create</group>
<group>product:read</group>
</attribute>
</class>

</serializer>

0 comments on commit 40389ba

Please sign in to comment.