Passed
Pull Request — master (#6)
by Willem
03:00
created

ProductFrontendControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 15
c 1
b 0
f 1
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testViewWithGlobalCustomUpdate() 0 27 1
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\GlobalCustomLayout\Test\Integration;
5
6
use IntegerNet\GlobalCustomLayout\Test\Util\ProductLayoutUpdateManager;
7
use Magento\Catalog\Api\ProductRepositoryInterface;
8
use Magento\Framework\Exception\CouldNotSaveException;
9
use Magento\Framework\Exception\InputException;
10
use Magento\Framework\Exception\NoSuchEntityException;
11
use Magento\Framework\Exception\StateException;
12
13
class ProductFrontendControllerTest extends AbstractFrontendControllerTest
14
{
15
    /**
16
     * Check that Global Custom Layout Update files work for Product views.
17
     *
18
     * @magentoDataFixture Magento/Catalog/controllers/_files/products.php
19
     * @return void
20
     * @throws CouldNotSaveException
21
     * @throws InputException
22
     * @throws NoSuchEntityException
23
     * @throws StateException
24
     */
25
    public function testViewWithGlobalCustomUpdate(): void
26
    {
27
        //Setting a fake file for the product.
28
        $file = 'test-file';
29
30
        /** @var ProductRepositoryInterface $repository */
31
        $repository = $this->objectManager->create(ProductRepositoryInterface::class);
32
        $sku = 'simple_product_1';
33
        $product = $repository->get($sku);
34
        $productId = $product->getId();
35
36
        /** @var ProductLayoutUpdateManager $layoutManager */
37
        $layoutManager = $this->objectManager->get(ProductLayoutUpdateManager::class);
38
        $layoutManager->setFakeFiles(0, [$file]);
39
40
        //Updating the custom attribute.
41
        $product->setCustomAttribute('custom_layout_update_file', $file);
42
        $repository->save($product);
43
44
        //Viewing the product
45
        $this->dispatch("catalog/product/view/id/$productId");
46
47
        //Layout handles must contain the file.
48
        $handles = $this->layoutInterface
49
            ->getUpdate()
50
            ->getHandles();
51
        $this->assertContains("catalog_product_view_selectable_0_{$file}", $handles);
52
    }
53
}
54