Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MC-41138' into 2.4-develop-pr54
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Balko committed Mar 12, 2021
2 parents 940480a + 0e92df5 commit 76222ea
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ $_helper = $block->getData('outputHelper');
<?php endforeach; ?>
</ol>
</div>
<?= $block->getToolbarHtml() ?>
<?= $block->getChildBlock('toolbar')->setIsBottom(true)->toHtml() ?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,23 @@
*
* @var $block \Magento\Catalog\Block\Product\ProductList\Toolbar
*/

// phpcs:disable Magento2.Security.IncludeFile.FoundIncludeFile
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
?>
<?php if ($block->getCollection()->getSize()) :?>
<?php $widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getWidgetOptionsJson());
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['productListToolbarForm']);
?>
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
<?php if ($block->isExpanded()) :?>
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
<?php endif; ?>

<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/amount.phtml')) ?>

<?= $block->getPagerHtml() ?>

<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/limiter.phtml')) ?>

<?php if ($block->isExpanded()) :?>
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>
<?php endif; ?>
<?php if ($block->getIsBottom()): ?>
<?= $block->getPagerHtml() ?>
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/limiter.phtml')) ?>
<?php else: ?>
<?php if ($block->isExpanded()): ?>
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
<?php endif ?>
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/amount.phtml')) ?>
<?php if ($block->isExpanded()): ?>
<?= $block->fetchView($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>
<?php endif ?>
<?php endif ?>
</div>
<?php endif ?>
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
namespace Magento\Catalog\Controller;

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Category\Attribute\LayoutUpdateManager;
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
use Magento\Catalog\Model\ResourceModel\Category\Collection;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
use Magento\Catalog\Model\Session;
use Magento\Framework\App\Http\Context;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\LayoutInterface;
use Magento\Store\Model\Store;
use Magento\TestFramework\Catalog\Model\CategoryLayoutUpdateManager;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\AbstractController;
Expand Down Expand Up @@ -53,6 +57,11 @@ class CategoryTest extends AbstractController
*/
private $httpContext;

/**
* @var CollectionFactory
*/
private $categoryCollectionFactory;

/**
* @inheritdoc
*/
Expand All @@ -64,6 +73,8 @@ protected function setUp(): void
$this->objectManager->configure([
'preferences' => [LayoutUpdateManager::class => CategoryLayoutUpdateManager::class]
]);

$this->categoryCollectionFactory = $this->objectManager->create(CollectionFactory::class);
$this->registry = $this->objectManager->get(Registry::class);
$this->layout = $this->objectManager->get(LayoutInterface::class);
$this->session = $this->objectManager->get(Session::class);
Expand Down Expand Up @@ -233,4 +244,50 @@ public function testViewWithRememberPaginationAndPreviousValue(): void
$this->assertEquals($newPaginationValue, $this->session->getData(ToolbarModel::LIMIT_PARAM_NAME));
$this->assertEquals($newPaginationValue, $this->httpContext->getValue(ToolbarModel::LIMIT_PARAM_NAME));
}

/**
* Test to generate category page without duplicate html element ids
*
* @magentoDataFixture Magento/Catalog/_files/category_with_three_products.php
* @magentoDataFixture Magento/Catalog/_files/catalog_category_product_reindex_all.php
* @magentoDataFixture Magento/Catalog/_files/catalog_product_category_reindex_all.php
* @magentoDbIsolation disabled
*/
public function testViewWithoutDuplicateHmlElementIds(): void
{
$category = $this->loadCategory('Category 999', Store::DEFAULT_STORE_ID);
$this->dispatch('catalog/category/view/id/' . $category->getId());

$responseHtml = $this->getResponse()->getBody();
$htmlElementIds = ['modes-label', 'mode-list', 'toolbar-amount', 'sorter', 'limiter'];
foreach ($htmlElementIds as $elementId) {
$matches = [];
$idAttribute = "id=\"$elementId\"";
preg_match_all("/$idAttribute/mx", $responseHtml, $matches);
$this->assertCount(1, $matches[0]);
$this->assertEquals($idAttribute, $matches[0][0]);
}
}

/**
* Loads category by id
*
* @param string $categoryName
* @param int $storeId
* @return CategoryInterface
*/
private function loadCategory(string $categoryName, int $storeId): CategoryInterface
{
/** @var Collection $categoryCollection */
$categoryCollection = $this->categoryCollectionFactory->create();
/** @var CategoryInterface $category */
$category = $categoryCollection->setStoreId($storeId)
->addAttributeToSelect('display_mode', 'left')
->addAttributeToFilter(CategoryInterface::KEY_NAME, $categoryName)
->setPageSize(1)
->getFirstItem();
$category->setStoreId($storeId);

return $category;
}
}

0 comments on commit 76222ea

Please sign in to comment.