mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Do not show disabled taxons in vertical menu
This commit is contained in:
parent
e2f1e7ac67
commit
07644753b8
7 changed files with 94 additions and 7 deletions
|
|
@ -0,0 +1,19 @@
|
|||
@viewing_products
|
||||
Feature: Viewving children taxons of current taxon on the sidebar
|
||||
In order to be able to easily browse children taxons
|
||||
As a Visitor
|
||||
I want to see the children taxon list of current taxon on the sidebar
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And the store classifies its products as "Category"
|
||||
And the "Category" taxon has child taxon "Clothes"
|
||||
And the "Clothes" taxon has children taxons "T-Shirts", "Coats" and "Trousers"
|
||||
And channel "United States" has menu taxon "Category"
|
||||
|
||||
@ui
|
||||
Scenario: Viewing only enabled taxons in the vertical menu
|
||||
Given the "Coats" taxon is disabled
|
||||
When I try to browse products from taxon "Clothes"
|
||||
Then I should not see "Coats" in the vertical menu
|
||||
And I should see "T-Shirts" and "Trousers" in the vertical menu
|
||||
|
|
@ -127,13 +127,16 @@ final class TaxonomyContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @Given /^the ("[^"]+" taxon) has child taxon "([^"]+)"$/
|
||||
* @Given /^the ("[^"]+" taxon) has children taxon "([^"]+)" and "([^"]+)"$/
|
||||
* @Given /^the ("[^"]+" taxon) has children taxons "([^"]+)" and "([^"]+)"$/
|
||||
* @Given /^the ("[^"]+" taxon) has children taxons "([^"]+)", "([^"]+)" and "([^"]+)"$/
|
||||
*/
|
||||
public function theTaxonHasChildrenTaxonAnd(TaxonInterface $taxon, $firstTaxonName, $secondTaxonName)
|
||||
public function theTaxonHasChildrenTaxonAnd(TaxonInterface $taxon, string ...$taxonsNames)
|
||||
{
|
||||
$taxon->addChild($this->createTaxon($firstTaxonName));
|
||||
$taxon->addChild($this->createTaxon($secondTaxonName));
|
||||
foreach ($taxonsNames as $taxonName) {
|
||||
$taxon->addChild($this->createTaxon($taxonName));
|
||||
}
|
||||
|
||||
$this->objectManager->persist($taxon);
|
||||
$this->objectManager->flush();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Behat\Context\Ui\Shop;
|
|||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Sylius\Behat\Element\Shop\MenuElementInterface;
|
||||
use Sylius\Behat\Page\ErrorPageInterface;
|
||||
use Sylius\Behat\Page\Shop\Product\IndexPageInterface;
|
||||
use Sylius\Behat\Page\Shop\Product\ShowPageInterface;
|
||||
|
|
@ -38,16 +39,21 @@ final class ProductContext implements Context
|
|||
/** @var ErrorPageInterface */
|
||||
private $errorPage;
|
||||
|
||||
/** @var MenuElementInterface */
|
||||
private $verticalMenuElement;
|
||||
|
||||
public function __construct(
|
||||
ShowPageInterface $showPage,
|
||||
IndexPageInterface $indexPage,
|
||||
ProductReviewIndexPageInterface $productReviewsIndexPage,
|
||||
ErrorPageInterface $errorPage
|
||||
ErrorPageInterface $errorPage,
|
||||
MenuElementInterface $verticalMenuElement
|
||||
) {
|
||||
$this->showPage = $showPage;
|
||||
$this->indexPage = $indexPage;
|
||||
$this->productReviewsIndexPage = $productReviewsIndexPage;
|
||||
$this->errorPage = $errorPage;
|
||||
$this->verticalMenuElement = $verticalMenuElement;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -597,6 +603,27 @@ final class ProductContext implements Context
|
|||
Assert::eq($this->errorPage->getTitle(), 'Requested page is invalid.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see :firstMenuItem and :secondMenuItem in the vertical menu
|
||||
*/
|
||||
public function iShouldSeeInTheVerticalMenu(string ...$menuItems)
|
||||
{
|
||||
Assert::allOneOf($menuItems, $this->verticalMenuElement->getMenuItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should not see :firstMenuItem in the vertical menu
|
||||
*/
|
||||
public function iShouldNotSeeInTheVerticalMenu(string ...$menuItems)
|
||||
{
|
||||
$actualMenuItems = $this->verticalMenuElement->getMenuItems();
|
||||
foreach ($menuItems as $menuItem) {
|
||||
if (in_array($menuItem, $actualMenuItems)) {
|
||||
throw new \InvalidArgumentException(sprintf('Vertical menu should not contain %s element', $menuItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $productName
|
||||
* @param string $productAssociationName
|
||||
|
|
|
|||
36
src/Sylius/Behat/Element/Shop/VerticalMenuElement.php
Normal file
36
src/Sylius/Behat/Element/Shop/VerticalMenuElement.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?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\Element\Shop;
|
||||
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use FriendsOfBehat\PageObjectExtension\Element\Element;
|
||||
|
||||
final class VerticalMenuElement extends Element implements MenuElementInterface
|
||||
{
|
||||
public function getMenuItems(): array
|
||||
{
|
||||
$menu = $this->getElement('vertical-menu');
|
||||
|
||||
return array_map(function (NodeElement $element): string {
|
||||
return $element->getText();
|
||||
}, $menu->findAll('css', '[data-test-vertical-menu-item]'));
|
||||
}
|
||||
|
||||
protected function getDefinedElements(): array
|
||||
{
|
||||
return [
|
||||
'vertical-menu' => '[data-test-vertical-menu]',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -448,6 +448,7 @@
|
|||
<argument type="service" id="sylius.behat.page.shop.product.index" />
|
||||
<argument type="service" id="sylius.behat.page.shop.product_reviews.index" />
|
||||
<argument type="service" id="sylius.behat.page.error" />
|
||||
<argument type="service" id="sylius.behat.element.shop.vertical_menu" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.ui.shop.browsing_product" class="Sylius\Behat\Context\Ui\Shop\BrowsingProductContext">
|
||||
|
|
|
|||
|
|
@ -21,5 +21,6 @@
|
|||
<service id="sylius.behat.element.shop.account.register" class="Sylius\Behat\Element\Shop\Account\RegisterElement" parent="sylius.behat.element" public="false" />
|
||||
|
||||
<service id="sylius.behat.element.shop.menu" class="Sylius\Behat\Element\Shop\MenuElement" parent="sylius.behat.element" public="false" />
|
||||
<service id="sylius.behat.element.shop.vertical_menu" class="Sylius\Behat\Element\Shop\VerticalMenuElement" parent="sylius.behat.element" public="false" />
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
{{ sylius_template_event('sylius.shop.product.index.before_vertical_menu', {'taxon': taxon}) }}
|
||||
|
||||
<div class="ui fluid vertical menu">
|
||||
<div class="ui fluid vertical menu" {{ sylius_test_html_attribute('vertical-menu') }}>
|
||||
<div class="header item">{{ taxon.name }}</div>
|
||||
{% for child in taxon.children %}
|
||||
<a href="{{ path('sylius_shop_product_index', {'slug': child.slug, '_locale': child.translation.locale}) }}" class="item">{{ child.name }}</a>
|
||||
{% for child in taxon.children|filter(t => t.enabled == true) %}
|
||||
<a href="{{ path('sylius_shop_product_index', {'slug': child.slug, '_locale': child.translation.locale}) }}" class="item" {{ sylius_test_html_attribute('vertical-menu-item') }}>{{ child.name }}</a>
|
||||
{% endfor %}
|
||||
{% if taxon.parent is not empty and not taxon.parent.isRoot() %}
|
||||
<a href="{{ path('sylius_shop_product_index', {'slug': taxon.parent.slug, '_locale': taxon.parent.translation.locale}) }}" class="item">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue