-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #14899 [PriceHistory] Extract config (NoResponseMate)
This PR was merged into the 1.13 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.13 | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Related tickets | - | | License | MIT | Commits ------- c845cd6 [PriceHistory][Behat] Update channel edition scenarios cade56c [PriceHistory] Add ChannelPriceHistoryConfig 77addfe [Channel][PriceHistory] Extract config 28e8a8b [API] Crud of ChannelPriceHistoryConfig 2ed5c9c [Admin] Use ChannelPriceHistoryConfig in channel crud c932710 [PriceHistory] Update prices processing on period change 36c4c33 [API] Remove leftover validation listener
- Loading branch information
Showing
74 changed files
with
1,979 additions
and
647 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
src/Sylius/Behat/Context/Api/Admin/ManagingChannelPriceHistoryConfigsContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
<?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 ApiPlatform\Core\Api\IriConverterInterface; | ||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Client\ApiClientInterface; | ||
use Sylius\Behat\Client\ResponseCheckerInterface; | ||
use Sylius\Behat\Context\Api\Resources; | ||
use Sylius\Behat\Service\SharedStorageInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\TaxonInterface; | ||
use Sylius\Component\Resource\Model\ResourceInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ManagingChannelPriceHistoryConfigsContext implements Context | ||
{ | ||
public function __construct( | ||
private SharedStorageInterface $sharedStorage, | ||
private ApiClientInterface $client, | ||
private ResponseCheckerInterface $responseChecker, | ||
private IriConverterInterface $iriConverter, | ||
) { | ||
} | ||
|
||
/** | ||
* @When /^I want to modify the price history config of (channel "[^"]+")$/ | ||
*/ | ||
public function iWantToModifyThePriceHistoryConfigOfChannel(ChannelInterface $channel): void | ||
{ | ||
$this->sharedStorage->set('channel', $channel); | ||
$this->client->buildUpdateRequest( | ||
Resources::CHANNEL_PRICE_HISTORY_CONFIGS, | ||
(string) $channel->getChannelPriceHistoryConfig()->getId(), | ||
); | ||
} | ||
|
||
/** | ||
* @When /^I change showing of the lowest price of discounted products to be (enabled|disabled)$/ | ||
*/ | ||
public function iChangeShowingOfTheLowestPriceOfDiscountedProducts(string $visible): void | ||
{ | ||
$this->client->addRequestData( | ||
'lowestPriceForDiscountedProductsVisible', | ||
$visible === 'enabled', | ||
); | ||
} | ||
|
||
/** | ||
* @When /^I change the lowest price for discounted products checking period to (-?\d+) days$/ | ||
*/ | ||
public function iChangeTheLowestPriceForDiscountedProductsCheckingPeriodToDays(int $days): void | ||
{ | ||
$this->client->addRequestData('lowestPriceForDiscountedProductsCheckingPeriod', $days); | ||
} | ||
|
||
/** | ||
* @When I exclude the :taxon taxon from showing the lowest price of discounted products | ||
*/ | ||
public function iExcludeTheTaxonFromShowingTheLowestPriceOfDiscountedProducts(TaxonInterface $taxon): void | ||
{ | ||
$this->iExcludeTheTaxonsFromShowingTheLowestPriceOfDiscountedProducts([$taxon]); | ||
} | ||
|
||
/** | ||
* @When /^I exclude the ("[^"]+" and "[^"]+" taxons) from showing the lowest price of discounted products$/ | ||
*/ | ||
public function iExcludeTheTaxonsFromShowingTheLowestPriceOfDiscountedProducts(iterable $taxons): void | ||
{ | ||
$taxonsIris = []; | ||
foreach ($taxons as $taxon) { | ||
$taxonsIris[] = $this->iriConverter->getIriFromItem($taxon); | ||
} | ||
|
||
$this->client->addRequestData('taxonsExcludedFromShowingLowestPrice', $taxonsIris); | ||
} | ||
|
||
/** | ||
* @Then /^the ("[^"]+" channel) should have the lowest price of discounted products prior to the current discount (enabled|disabled)$/ | ||
*/ | ||
public function theChannelShouldHaveTheLowestPriceOfDiscountedProductsPriorToTheCurrentDiscountEnabledOrDisabled( | ||
ChannelInterface $channel, | ||
string $visible, | ||
): void { | ||
$lowestPriceForDiscountedProductsVisible = $this->responseChecker->getValue( | ||
$this->client->show( | ||
Resources::CHANNEL_PRICE_HISTORY_CONFIGS, | ||
(string) $channel->getChannelPriceHistoryConfig()->getId(), | ||
), | ||
'lowestPriceForDiscountedProductsVisible', | ||
); | ||
|
||
Assert::same($lowestPriceForDiscountedProductsVisible, $visible === 'enabled'); | ||
} | ||
|
||
/** | ||
* @Then /^the ("[^"]+" channel) should have the lowest price for discounted products checking period set to (\d+) days$/ | ||
* @Then /^(its) lowest price for discounted products checking period should be set to (\d+) days$/ | ||
*/ | ||
public function theChannelShouldHaveTheLowestPriceForDiscountedProductsCheckingPeriodSetToDays( | ||
ChannelInterface $channel, | ||
int $days, | ||
): void { | ||
$lowestPriceForDiscountedProductsCheckingPeriod = $this->responseChecker->getValue( | ||
$this->client->show( | ||
Resources::CHANNEL_PRICE_HISTORY_CONFIGS, | ||
(string) $channel->getChannelPriceHistoryConfig()->getId(), | ||
), | ||
'lowestPriceForDiscountedProductsCheckingPeriod', | ||
); | ||
|
||
Assert::same($lowestPriceForDiscountedProductsCheckingPeriod, $days); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the lowest price for discounted products checking period must be greater than 0 | ||
*/ | ||
public function iShouldBeNotifiedThatTheLowestPriceForDiscountedProductsCheckingPeriodMustBeGreaterThanZero(): void | ||
{ | ||
Assert::true($this->responseChecker->hasViolationWithMessage( | ||
$this->client->getLastResponse(), | ||
'Value must be greater than 0', | ||
'lowestPriceForDiscountedProductsCheckingPeriod', | ||
)); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that the lowest price for discounted products checking period must be lower | ||
*/ | ||
public function iShouldBeNotifiedThatTheLowestPriceForDiscountedProductsCheckingPeriodMustBeLower(): void | ||
{ | ||
Assert::true($this->responseChecker->hasViolationWithMessage( | ||
$this->client->getLastResponse(), | ||
'Value must be less than 2147483647', | ||
'lowestPriceForDiscountedProductsCheckingPeriod', | ||
)); | ||
} | ||
|
||
/** | ||
* @Then /^(this channel) should have ("[^"]+" taxon) excluded from displaying the lowest price of discounted products$/ | ||
*/ | ||
public function thisChannelShouldHaveTaxonExcludedFromDisplayingTheLowestPriceOfDiscountedProducts( | ||
ChannelInterface $channel, | ||
TaxonInterface $taxon, | ||
): void { | ||
$excludedTaxons = $this->responseChecker->getValue( | ||
$this->client->show( | ||
Resources::CHANNEL_PRICE_HISTORY_CONFIGS, | ||
(string) $channel->getChannelPriceHistoryConfig()->getId(), | ||
), | ||
'taxonsExcludedFromShowingLowestPrice', | ||
); | ||
|
||
Assert::true($this->isResourceAdminIriInArray($taxon, $excludedTaxons)); | ||
} | ||
|
||
/** | ||
* @Then /^(this channel) should have ("([^"]+)" and "([^"]+)" taxons) excluded from displaying the lowest price of discounted products$/ | ||
*/ | ||
public function thisChannelShouldHaveTaxonsExcludedFromDisplayingTheLowestPriceOfDiscountedProducts( | ||
ChannelInterface $channel, | ||
iterable $taxons, | ||
): void { | ||
$excludedTaxons = $this->responseChecker->getValue( | ||
$this->client->show( | ||
Resources::CHANNEL_PRICE_HISTORY_CONFIGS, | ||
(string) $channel->getChannelPriceHistoryConfig()->getId(), | ||
), | ||
'taxonsExcludedFromShowingLowestPrice', | ||
); | ||
|
||
foreach ($taxons as $taxon) { | ||
Assert::true($this->isResourceAdminIriInArray($taxon, $excludedTaxons)); | ||
} | ||
} | ||
|
||
/** | ||
* @Then /^(this channel) should not have ("[^"]+" taxon) excluded from displaying the lowest price of discounted products$/ | ||
*/ | ||
public function thisChannelShouldNotHaveTaxonExcludedFromDisplayingTheLowestPriceOfDiscountedProducts( | ||
ChannelInterface $channel, | ||
TaxonInterface $taxon, | ||
): void { | ||
$excludedTaxons = (array) $this->responseChecker->getValue( | ||
$this->client->show( | ||
Resources::CHANNEL_PRICE_HISTORY_CONFIGS, | ||
(string) $channel->getChannelPriceHistoryConfig()->getId(), | ||
), | ||
'taxonsExcludedFromShowingLowestPrice', | ||
); | ||
|
||
Assert::false($this->isResourceAdminIriInArray($taxon, $excludedTaxons)); | ||
} | ||
|
||
private function isResourceAdminIriInArray(ResourceInterface $resource, array $iris): bool | ||
{ | ||
$iri = $this->iriConverter->getIriFromItemInSection($resource, 'admin'); | ||
|
||
return in_array($iri, $iris, true); | ||
} | ||
} |
Oops, something went wrong.