Passed
Push — tests ( 40ec1d...1f48e4 )
by Willem
04:57
created

testViewWithGlobalCustomUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 26
rs 9.8333
cc 1
nc 1
nop 0
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
use Magento\TestFramework\Helper\Bootstrap;
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\Helper\Bootstrap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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