Skip to content

Commit

Permalink
refactor + set channel on request
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Apr 27, 2021
1 parent 04a502a commit 9d91e25
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Feature: Viewing products from a specific taxon and a channel
And the store has a product "T-Shirt Batman" available in "United States" channel
And this product belongs to "T-Shirts"

@ui
@ui @api
Scenario: Viewing products from a specific taxon in selected channel
Given I am browsing channel "Poland"
When I browse products from taxon "T-Shirts"
Then I should see the product "T-Shirt Banana"
And I should not see the product "T-Shirt Batman"

@ui
@ui @api
Scenario: Viewing information about empty list of products from a given taxon in selected channel
Given I am browsing channel "United States"
When I browse products from taxon "Funny"
Expand Down
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sylius\Behat\Client\Request;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Taxonomy\Model\TaxonInterface;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
Expand Down Expand Up @@ -50,6 +51,14 @@ public function __construct(
$this->iriConverter = $iriConverter;
}

/**
* @Given I am browsing channel :channel
*/
public function iAmBrowsingChannel(ChannelInterface $channel)
{
$this->sharedStorage->set('hostname', $channel->getHostname());
}

/**
* @When /^I check (this product)'s details$/
* @When I view product :product
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Setup/ChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function theStoreOperatesOnAChannelNamed(string $channelName, string $cur
$channelCode = StringInflector::nameToLowercaseCode($channelName);
$defaultData = $this->defaultChannelFactory->create($channelCode, $channelName, $currencyCode);

$defaultData['channel']->setHostname($hostname);
$defaultData['channel']->setHostname(strtolower($hostname ?: str_replace(' ', '-', $channelName)));

$this->sharedStorage->setClipboard($defaultData);
$this->sharedStorage->set('channel', $defaultData['channel']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ default:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.channel
- sylius.behat.context.transform.currency
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.taxon

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.customer
- sylius.behat.context.setup.locale
- sylius.behat.context.setup.product
Expand Down
11 changes: 9 additions & 2 deletions src/Sylius/Bundle/ApiBundle/Filter/TaxonFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ public function __construct(ManagerRegistry $managerRegistry, IriConverterInterf
$this->iriConverter = $iriConverter;
}

public function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
{
public function filterProperty(
string $property,
$value,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
string $operationName = null,
array $context = []
) {
if ($property !== 'taxon') {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function let(ManagerRegistry $managerRegistry, IriConverterInterface $iriConvert
$this->beConstructedWith($managerRegistry, $iriConverter);
}

function it_adds_taxon_filter_if_property_is_product_taxon(
function it_adds_taxon_filter_if_property_is_taxon(
IriConverterInterface $iriConverter,
TaxonInterface $taxon,
TaxonInterface $taxonRoot,
Expand Down

0 comments on commit 9d91e25

Please sign in to comment.