-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] [Product] [ProductTranslation] Add api configuration and test for adding product and product translations #11213
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,121 @@ | ||||||
<?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. | ||||||
*/ | ||||||
|
||||||
declare(strict_types=1); | ||||||
|
||||||
namespace Sylius\Behat\Context\Api\Admin; | ||||||
|
||||||
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; | ||||||
|
||||||
/** @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(); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @When I specify its code as :code | ||||||
* @When I do not specify its code | ||||||
*/ | ||||||
public function iSpecifyItsCodeAs(string $code = null): void | ||||||
{ | ||||||
$this->client->addRequestData('code', $code); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @When I name it :name in :localeCode | ||||||
* @When I rename it to :name in :localeCode | ||||||
*/ | ||||||
public function iRenameItToIn(string $name, string $localeCode): void | ||||||
{ | ||||||
$data = [ | ||||||
'translations' => [ | ||||||
$localeCode => [ | ||||||
'locale' => $localeCode, | ||||||
'name' => $name, | ||||||
], | ||||||
], | ||||||
]; | ||||||
|
||||||
$this->client->updateRequestData($data); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @When I set its slug to :slug | ||||||
* @When I set its slug to :slug in :localeCode | ||||||
* @When I remove its slug | ||||||
*/ | ||||||
public function iSetItsSlugTo(?string $slug = null, $localeCode = 'en_US'): void | ||||||
{ | ||||||
$data = [ | ||||||
'translations' => [ | ||||||
$localeCode => [ | ||||||
'slug' => $slug, | ||||||
], | ||||||
], | ||||||
]; | ||||||
|
||||||
$this->client->updateRequestData($data); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @When I add it | ||||||
* @When I try to add it | ||||||
*/ | ||||||
public function iAddIt(): void | ||||||
{ | ||||||
$this->client->create(); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @Then I should see the product :productName in the list | ||||||
* @Then the product :productName should appear in the store | ||||||
* @Then the product :productName should be in the shop | ||||||
* @Then this product should still be named :productName | ||||||
*/ | ||||||
public function theProductShouldAppearInTheShop(string $productName): void | ||||||
{ | ||||||
$this->client->index(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Assert::true( | ||||||
$this | ||||||
->responseChecker | ||||||
->hasItemWithTranslation($this->client->getLastResponse(),'en_US', 'name', $productName) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing exception message |
||||||
} | ||||||
|
||||||
/** | ||||||
* @Then I should be notified that it has been successfully created | ||||||
*/ | ||||||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void | ||||||
{ | ||||||
Assert::true($this->responseChecker->isCreationSuccessful($this->client->getLastResponse())); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing exception message |
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# This file is part of the Sylius package. | ||
# (c) Paweł Jędrzejewski | ||
|
||
default: | ||
suites: | ||
api_managing_products: | ||
contexts: | ||
- sylius.behat.context.hook.doctrine_orm | ||
|
||
- sylius.behat.context.transform.address | ||
- sylius.behat.context.transform.admin | ||
- sylius.behat.context.transform.channel | ||
- sylius.behat.context.transform.currency | ||
- sylius.behat.context.transform.customer | ||
- sylius.behat.context.transform.lexical | ||
- sylius.behat.context.transform.locale | ||
- sylius.behat.context.transform.payment | ||
- sylius.behat.context.transform.product | ||
- sylius.behat.context.transform.product_association_type | ||
- sylius.behat.context.transform.product_option | ||
- sylius.behat.context.transform.shared_storage | ||
- sylius.behat.context.transform.shipping_method | ||
- 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 | ||
- sylius.behat.context.setup.geographical | ||
- sylius.behat.context.setup.locale | ||
- sylius.behat.context.setup.order | ||
- sylius.behat.context.setup.payment | ||
- sylius.behat.context.setup.product | ||
- sylius.behat.context.setup.product_association | ||
- sylius.behat.context.setup.product_attribute | ||
- sylius.behat.context.setup.product_option | ||
- sylius.behat.context.setup.product_review | ||
- sylius.behat.context.setup.product_taxon | ||
- 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_products | ||
|
||
filters: | ||
tags: "@managing_products && @api" | ||
javascript: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<resources xmlns="https://api-platform.com/schema/metadata" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"> | ||
|
||
<resource | ||
class="%sylius.model.product_translation.class%" | ||
shortName="ProductTranslation" | ||
> | ||
<attribute name="validation_groups">sylius</attribute> | ||
|
||
<collectionOperations /> | ||
|
||
<itemOperations> | ||
<itemOperation name="get" /> | ||
</itemOperations> | ||
|
||
<property name="id" identifier="true" writable="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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"> | ||
|
||
<class name="Sylius\Component\Product\Model\ProductTranslation"> | ||
<attribute name="id"> | ||
<group>product:read</group> | ||
</attribute> | ||
<attribute name="name"> | ||
<group>product:read</group> | ||
<group>product:create</group> | ||
</attribute> | ||
<attribute name="locale"> | ||
<group>product:create</group> | ||
</attribute> | ||
<attribute name="slug"> | ||
<group>product:create</group> | ||
<group>product:read</group> | ||
</attribute> | ||
</class> | ||
</serializer> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work now: