|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Catalog\Block\Product\ProductList;
|
7 | 9 |
|
8 |
| -class ToolbarTest extends \PHPUnit\Framework\TestCase |
| 10 | +use Magento\Framework\ObjectManagerInterface; |
| 11 | +use Magento\Framework\View\Element\Text; |
| 12 | +use Magento\Framework\View\LayoutInterface; |
| 13 | +use Magento\TestFramework\Helper\Bootstrap; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Magento\TestFramework\Helper\Xpath; |
| 16 | + |
| 17 | +/** |
| 18 | + * Checks product list toolbar. |
| 19 | + * |
| 20 | + * @see \Magento\Catalog\Block\Product\ProductList\Toolbar |
| 21 | + * @magentoAppArea frontend |
| 22 | + * @magentoDbIsolation enabled |
| 23 | + */ |
| 24 | +class ToolbarTest extends TestCase |
9 | 25 | {
|
| 26 | + /** @var ObjectManagerInterface */ |
| 27 | + private $objectManager; |
| 28 | + |
| 29 | + /** @var LayoutInterface */ |
| 30 | + private $layout; |
| 31 | + |
| 32 | + /** |
| 33 | + * @inheritdoc |
| 34 | + */ |
| 35 | + protected function setUp(): void |
| 36 | + { |
| 37 | + parent::setUp(); |
| 38 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 39 | + $this->layout = $this->objectManager->get(LayoutInterface::class); |
| 40 | + } |
| 41 | + |
10 | 42 | public function testGetPagerHtml()
|
11 | 43 | {
|
12 |
| - /** @var $layout \Magento\Framework\View\Layout */ |
13 |
| - $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( |
14 |
| - \Magento\Framework\View\LayoutInterface::class |
15 |
| - ); |
16 |
| - /** @var $block \Magento\Catalog\Block\Product\ProductList\Toolbar */ |
17 |
| - $block = $layout->createBlock(\Magento\Catalog\Block\Product\ProductList\Toolbar::class, 'block'); |
18 |
| - /** @var $childBlock \Magento\Framework\View\Element\Text */ |
19 |
| - $childBlock = $layout->addBlock( |
20 |
| - \Magento\Framework\View\Element\Text::class, |
| 44 | + /** @var $block Toolbar */ |
| 45 | + $block = $this->layout->createBlock(Toolbar::class, 'block'); |
| 46 | + /** @var $childBlock Text */ |
| 47 | + $childBlock = $this->layout->addBlock( |
| 48 | + Text::class, |
21 | 49 | 'product_list_toolbar_pager',
|
22 | 50 | 'block'
|
23 | 51 | );
|
24 |
| - |
25 | 52 | $expectedHtml = '<b>Any text there</b>';
|
26 | 53 | $this->assertNotEquals($expectedHtml, $block->getPagerHtml());
|
27 | 54 | $childBlock->setText($expectedHtml);
|
28 | 55 | $this->assertEquals($expectedHtml, $block->getPagerHtml());
|
29 | 56 | }
|
| 57 | + |
| 58 | + /** |
| 59 | + * @magentoConfigFixture default_store catalog/frontend/list_mode grid |
| 60 | + */ |
| 61 | + public function testToHtmlGridOnly(): void |
| 62 | + { |
| 63 | + $block = $this->layout->createBlock(Toolbar::class, 'block'); |
| 64 | + $block->setTemplate('Magento_Catalog::product/list/toolbar/viewmode.phtml'); |
| 65 | + $this->assertEquals( |
| 66 | + 0, |
| 67 | + Xpath::getElementsCountForXpath( |
| 68 | + '//div[contains(@class, "modes")]/*[@data-value="grid"]', |
| 69 | + $block->toHtml() |
| 70 | + ) |
| 71 | + ); |
| 72 | + $this->assertEquals( |
| 73 | + 0, |
| 74 | + Xpath::getElementsCountForXpath( |
| 75 | + '//div[contains(@class, "modes")]/*[@data-value="list"]', |
| 76 | + $block->toHtml() |
| 77 | + ) |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @magentoConfigFixture default_store catalog/frontend/list_mode list |
| 83 | + */ |
| 84 | + public function testToHtmlListOnly(): void |
| 85 | + { |
| 86 | + $block = $this->layout->createBlock(Toolbar::class, 'block'); |
| 87 | + $block->setTemplate('Magento_Catalog::product/list/toolbar/viewmode.phtml'); |
| 88 | + $this->assertEquals( |
| 89 | + 0, |
| 90 | + Xpath::getElementsCountForXpath( |
| 91 | + '//div[contains(@class, "modes")]/*[@data-value="grid"]', |
| 92 | + $block->toHtml() |
| 93 | + ) |
| 94 | + ); |
| 95 | + $this->assertEquals( |
| 96 | + 0, |
| 97 | + Xpath::getElementsCountForXpath( |
| 98 | + '//div[contains(@class, "modes")]/*[@data-value="list"]', |
| 99 | + $block->toHtml() |
| 100 | + ) |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @magentoConfigFixture default_store catalog/frontend/list_mode grid-list |
| 106 | + */ |
| 107 | + public function testToHtmlGridList(): void |
| 108 | + { |
| 109 | + $block = $this->layout->createBlock(Toolbar::class, 'block'); |
| 110 | + $block->setTemplate('Magento_Catalog::product/list/toolbar/viewmode.phtml'); |
| 111 | + $this->assertEquals( |
| 112 | + 1, |
| 113 | + Xpath::getElementsCountForXpath( |
| 114 | + '//div[contains(@class, "modes")]/strong[@data-value="grid" and contains(@class, "active")]', |
| 115 | + $block->toHtml() |
| 116 | + ) |
| 117 | + ); |
| 118 | + $this->assertEquals( |
| 119 | + 1, |
| 120 | + Xpath::getElementsCountForXpath( |
| 121 | + '//div[contains(@class, "modes")]/a[@data-value="list"]', |
| 122 | + $block->toHtml() |
| 123 | + ) |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * @magentoConfigFixture default_store catalog/frontend/list_mode list-grid |
| 129 | + */ |
| 130 | + public function testToHtmlListGrid(): void |
| 131 | + { |
| 132 | + $block = $this->layout->createBlock(Toolbar::class, 'block'); |
| 133 | + $block->setTemplate('Magento_Catalog::product/list/toolbar/viewmode.phtml'); |
| 134 | + $this->assertEquals( |
| 135 | + 1, |
| 136 | + Xpath::getElementsCountForXpath( |
| 137 | + '//div[contains(@class, "modes")]/strong[@data-value="list" and contains(@class, "active")]', |
| 138 | + $block->toHtml() |
| 139 | + ) |
| 140 | + ); |
| 141 | + $this->assertEquals( |
| 142 | + 1, |
| 143 | + Xpath::getElementsCountForXpath( |
| 144 | + '//div[contains(@class, "modes")]/a[@data-value="grid"]', |
| 145 | + $block->toHtml() |
| 146 | + ) |
| 147 | + ); |
| 148 | + } |
30 | 149 | }
|
0 commit comments