Completed
Push — master ( d80aef...0536a3 )
by Willem
13s queued 12s
created

CategoryFrontendControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 14
c 2
b 0
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testViewWithGlobalCustomUpdate() 0 26 1
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