|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace IntegerNet\GlobalCustomLayout\Test\Integration; |
|
5
|
|
|
|
|
6
|
|
|
use IntegerNet\GlobalCustomLayout\Test\Util\CategoryLayoutUpdateManager; |
|
7
|
|
|
use Magento\Catalog\Api\CategoryRepositoryInterface; |
|
8
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
|
9
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Tests whether global layout handles are correctly saved on categories |
|
13
|
|
|
* and retrieved on the frontend on Category views |
|
14
|
|
|
*/ |
|
15
|
|
|
class CategoryFrontendControllerTest extends AbstractFrontendControllerTest |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Check that Global Custom Layout Update files work for Category views. |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
* @throws CouldNotSaveException |
|
22
|
|
|
* @throws NoSuchEntityException |
|
23
|
|
|
* |
|
24
|
|
|
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_product_ids.php |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testViewWithGlobalCustomUpdate(): void |
|
27
|
|
|
{ |
|
28
|
|
|
//Setting a fake file for the category. |
|
29
|
|
|
$file = 'test-file'; |
|
30
|
|
|
$categoryId = 5; |
|
31
|
|
|
|
|
32
|
|
|
/** @var CategoryLayoutUpdateManager $layoutManager */ |
|
33
|
|
|
$layoutManager = $this->objectManager->get(CategoryLayoutUpdateManager::class); |
|
34
|
|
|
$layoutManager->setCategoryFakeFiles(0, [$file]); |
|
35
|
|
|
|
|
36
|
|
|
/** @var CategoryRepositoryInterface $categoryRepo */ |
|
37
|
|
|
$categoryRepo = $this->objectManager->create(CategoryRepositoryInterface::class); |
|
38
|
|
|
$category = $categoryRepo->get($categoryId); |
|
39
|
|
|
|
|
40
|
|
|
//Updating the custom attribute. |
|
41
|
|
|
$category->setCustomAttribute('custom_layout_update_file', $file); |
|
42
|
|
|
$categoryRepo->save($category); |
|
43
|
|
|
|
|
44
|
|
|
//Viewing the category |
|
45
|
|
|
$this->dispatch("catalog/category/view/id/$categoryId"); |
|
46
|
|
|
|
|
47
|
|
|
//Layout handles must contain the file. |
|
48
|
|
|
$handles = $this->layoutInterface |
|
49
|
|
|
->getUpdate() |
|
50
|
|
|
->getHandles(); |
|
51
|
|
|
$this->assertContains("catalog_category_view_selectable_0_{$file}", $handles); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|