mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Behat][API][Admin] Cover adding images to existing product
This commit is contained in:
parent
440c8f78f6
commit
26cb059b03
9 changed files with 159 additions and 48 deletions
|
|
@ -5,71 +5,72 @@ Feature: Adding images to an existing product
|
|||
I want to be able to add new images to a taxon
|
||||
|
||||
Background:
|
||||
Given I am logged in as an administrator
|
||||
Given the store operates on a single channel in "United States"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding a single image to an existing product
|
||||
Given the store has a product "Lamborghini Gallardo Model"
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image with "banner" type
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image with "banner" type to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And the product "Lamborghini Gallardo Model" should have an image with "banner" type
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding multiple images to an existing product
|
||||
Given the store has a product "Lamborghini Gallardo Model"
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image with "banner" type
|
||||
And I attach the "lamborghini.jpg" image with "thumbnail" type
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image with "banner" type to this product
|
||||
And I attach the "lamborghini.jpg" image with "thumbnail" type to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And the product "Lamborghini Gallardo Model" should have an image with "banner" type
|
||||
And it should also have an image with "thumbnail" type
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding multiple images of the same type to an existing product
|
||||
Given the store has a product "Lamborghini Ford Model"
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image with "banner" type
|
||||
And I attach the "ford.jpg" image with "banner" type
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image with "banner" type to this product
|
||||
And I attach the "ford.jpg" image with "banner" type to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And this product should have 2 images
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding a single image to an existing configurable product
|
||||
Given the store has a "Lamborghini Gallardo Model" configurable product
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image with "banner" type
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image with "banner" type to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And the product "Lamborghini Gallardo Model" should have an image with "banner" type
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding multiple images of the same type to an existing configurable product
|
||||
Given the store has a "Lamborghini Ford Model" configurable product
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image with "banner" type
|
||||
And I attach the "ford.jpg" image with "banner" type
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image with "banner" type to this product
|
||||
And I attach the "ford.jpg" image with "banner" type to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And this product should have 2 images
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding an image to an existing product without providing its type
|
||||
Given the store has a product "Lamborghini Gallardo Model"
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And this product should have only one image
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @api
|
||||
Scenario: Adding an image to an existing configurable product without providing its type
|
||||
Given the store has a "Lamborghini Gallardo Model" configurable product
|
||||
When I want to modify this product
|
||||
And I attach the "lamborghini.jpg" image
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And I attach the "lamborghini.jpg" image to this product
|
||||
And I save my changes to the images
|
||||
Then I should be notified that it has been successfully uploaded
|
||||
And this product should have only one image
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ Feature: Adding a new product with images
|
|||
And the product "Lamborghini Gallardo Model" should have an image with "banner" type
|
||||
And it should also have an image with "thumbnail" type
|
||||
|
||||
@ui @javascript
|
||||
@ui @javascript @no-api
|
||||
Scenario: Adding a new configurable product with a single image
|
||||
Given the store has a product option "Model scale" with a code "model_scale"
|
||||
And this product option has the "1:43" option value with code "model_scale_medium"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* 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\RequestBuilder;
|
||||
use Sylius\Behat\Client\ResponseCheckerInterface;
|
||||
use Sylius\Behat\Context\Api\Resources;
|
||||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Component\Core\Model\ProductInterface;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class ManagingProductImagesContext implements Context
|
||||
{
|
||||
public function __construct(
|
||||
private ApiClientInterface $client,
|
||||
private ResponseCheckerInterface $responseChecker,
|
||||
private SharedStorageInterface $sharedStorage,
|
||||
private \ArrayAccess $minkParameters,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I attach the "([^"]+)" image with "([^"]+)" type to (this product)$/
|
||||
*/
|
||||
public function iAttachTheImageWithTypeToThisProduct(string $path, ?string $type, ProductInterface $product): void
|
||||
{
|
||||
$builder = RequestBuilder::create(
|
||||
sprintf('/api/v2/admin/products/%s/images', $product->getCode()),
|
||||
Request::METHOD_POST,
|
||||
);
|
||||
$builder->withHeader('CONTENT_TYPE', 'multipart/form-data');
|
||||
$builder->withHeader('HTTP_ACCEPT', 'application/ld+json');
|
||||
$builder->withHeader('HTTP_Authorization', 'Bearer ' . $this->sharedStorage->get('token'));
|
||||
$builder->withFile('file', new UploadedFile($this->minkParameters['files_path'] . $path, basename($path)));
|
||||
|
||||
if (null !== $type) {
|
||||
$builder->withParameter('type', $type);
|
||||
}
|
||||
|
||||
$this->client->request($builder->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I attach the "([^"]+)" image to (this product)$/
|
||||
*/
|
||||
public function iAttachTheImageToThisProduct(string $path, ProductInterface $product): void
|
||||
{
|
||||
$this->iAttachTheImageWithTypeToThisProduct($path, null, $product);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the product :product should have an image with :type type
|
||||
* @Then /^(it) should(?:| also) have an image with "([^"]*)" type$/
|
||||
*/
|
||||
public function theProductShouldHaveAnImageWithType(ProductInterface $product, string $type): void
|
||||
{
|
||||
Assert::true($this->responseChecker->hasSubResourceWithValue(
|
||||
$this->client->show(Resources::PRODUCTS, $product->getCode()),
|
||||
'images',
|
||||
'type',
|
||||
$type,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^(this product) should have only one image$/
|
||||
* @Then /^(this product) should(?:| still) have (\d+) images?$/
|
||||
*/
|
||||
public function thisProductShouldHaveImages(ProductInterface $product, int $count = 1): void
|
||||
{
|
||||
Assert::count(
|
||||
$this->responseChecker->getValue($this->client->show(Resources::PRODUCTS, $product->getCode()), 'images'),
|
||||
$count,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -403,6 +403,14 @@ final class ManagingProductsContext implements Context
|
|||
$this->client->show(Resources::PRODUCTS, $product->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I save my changes to the images
|
||||
*/
|
||||
public function iSaveMyChangesToTheImages(): void
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully created
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -107,20 +107,6 @@ final class ManagingTaxonImagesContext implements Context
|
|||
$this->client->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully uploaded
|
||||
*/
|
||||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyUploaded(): void
|
||||
{
|
||||
Assert::true(
|
||||
$this->responseChecker->isCreationSuccessful($this->client->getLastResponse()),
|
||||
sprintf(
|
||||
'Resource could not be created: %s',
|
||||
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the changes have been successfully applied
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -38,6 +38,20 @@ final class ResponseContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully uploaded
|
||||
*/
|
||||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyUploaded(): void
|
||||
{
|
||||
Assert::true(
|
||||
$this->responseChecker->isCreationSuccessful($this->client->getLastResponse()),
|
||||
sprintf(
|
||||
'Resource could not be created: %s',
|
||||
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that I can no longer change payment method of this order
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -518,6 +518,7 @@ final class ManagingProductsContext implements Context
|
|||
/**
|
||||
* @When I save my changes
|
||||
* @When I try to save my changes
|
||||
* @When I save my changes to the images
|
||||
*/
|
||||
public function iSaveMyChanges()
|
||||
{
|
||||
|
|
@ -832,8 +833,10 @@ final class ManagingProductsContext implements Context
|
|||
/**
|
||||
* @When I attach the :path image with :type type
|
||||
* @When I attach the :path image
|
||||
* @When I attach the :path image with :type type to this product
|
||||
* @When I attach the :path image to this product
|
||||
*/
|
||||
public function iAttachImageWithType($path, $type = null)
|
||||
public function iAttachImageWithType(string $path, ?string $type = null): void
|
||||
{
|
||||
$currentPage = $this->resolveCurrentPage();
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,13 @@
|
|||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.api.admin.managing_product_images" class="Sylius\Behat\Context\Api\Admin\ManagingProductImagesContext">
|
||||
<argument type="service" id="sylius.behat.api_platform_client.admin" />
|
||||
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
|
||||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
<argument type="service" id="behat.mink.parameters" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.api.admin.managing_product_options" class="Sylius\Behat\Context\Api\Admin\ManagingProductOptionsContext">
|
||||
<argument type="service" id="sylius.behat.api_platform_client.admin" />
|
||||
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ default:
|
|||
- sylius.behat.context.setup.taxonomy
|
||||
- sylius.behat.context.setup.zone
|
||||
|
||||
- sylius.behat.context.api.admin.managing_product_images
|
||||
- sylius.behat.context.api.admin.managing_products
|
||||
- sylius.behat.context.api.admin.response
|
||||
- sylius.behat.context.api.admin.save
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue