|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace IntegerNet\GlobalCustomLayout\Test\Integration; |
|
5
|
|
|
|
|
6
|
|
|
use IntegerNet\GlobalCustomLayout\Test\src\PageLayoutUpdateManager; |
|
7
|
|
|
use Magento\Cms\Model\Page; |
|
8
|
|
|
use Magento\Cms\Model\Page\CustomLayoutRepositoryInterface; |
|
9
|
|
|
use Magento\Cms\Model\PageFactory; |
|
|
|
|
|
|
10
|
|
|
use Magento\Cms\Model\ResourceModel\Page as PageResourceModel; |
|
11
|
|
|
|
|
12
|
|
|
class PageFrontendControllerTest extends AbstractFrontendControllerTest |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
const PAGE_ID_FROM_FIXTURE = 'page100'; |
|
16
|
|
|
|
|
17
|
|
|
/** @var PageLayoutUpdateManager */ |
|
18
|
|
|
protected $layoutManager; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Page */ |
|
21
|
|
|
protected $page; |
|
22
|
|
|
|
|
23
|
|
|
/** @var PageResourceModel $pageResource */ |
|
24
|
|
|
protected $pageResource; |
|
25
|
|
|
|
|
26
|
|
|
/** @var pageFactory $pageFactory */ |
|
27
|
|
|
protected $pageFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** @var CustomLayoutRepositoryInterface $repository */ |
|
30
|
|
|
protected $repository; |
|
31
|
|
|
|
|
32
|
|
|
protected function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::setUp(); |
|
35
|
|
|
|
|
36
|
|
|
$this->layoutManager = $this->objectManager->get(PageLayoutUpdateManager::class); |
|
37
|
|
|
$this->pageResource = $this->objectManager->get(PageResourceModel::class); |
|
38
|
|
|
$this->pageFactory = $this->objectManager->get(PageFactory::class); |
|
39
|
|
|
$this->repository = $this->objectManager->create( |
|
40
|
|
|
CustomLayoutRepositoryInterface::class, |
|
41
|
|
|
['manager' => $this->layoutManager] |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Check that custom handles are applied when rendering a page. |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
* @magentoDataFixture Magento/Cms/_files/pages.php |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testViewWithGlobalCustomUpdate(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->givenGlobalCustomUpdateSelected(); |
|
54
|
|
|
$this->whenPageViewed(); |
|
55
|
|
|
$this->thenContainsGlobalUpdateHandle(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Check that custom handles are applied when rendering a page. |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
* @magentoDataFixture Magento/Cms/_files/pages.php |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testViewWithDefaultCustomUpdate(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$this->givenDefaultCustomUpdateSelected(); |
|
67
|
|
|
$this->whenPageViewed(); |
|
68
|
|
|
$this->thenContainsDefaultUpdateHandle(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function givenGlobalCustomUpdateSelected() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->setCustomUpdate(self::GLOBAL_IDENTIFIER); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
protected function givenDefaultCustomUpdateSelected() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->setCustomUpdate($this->getPageId()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Viewing the product |
|
83
|
|
|
* |
|
84
|
|
|
* @param int|null $pageId |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function whenPageViewed(?int $pageId = null): void |
|
87
|
|
|
{ |
|
88
|
|
|
if (!$pageId) { |
|
|
|
|
|
|
89
|
|
|
$pageId = $this->getPageId(); |
|
90
|
|
|
} |
|
91
|
|
|
$this->dispatch("/cms/page/view/page_id/{$pageId}"); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
protected function thenContainsGlobalUpdateHandle() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->containsUpdateHandle(self::GLOBAL_IDENTIFIER); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
protected function thenContainsDefaultUpdateHandle() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->containsUpdateHandle(self::PAGE_ID_FROM_FIXTURE); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Layout handles must contain the file. |
|
106
|
|
|
* |
|
107
|
|
|
* @param int|string $identifier |
|
108
|
|
|
* @param string $fileName |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function containsUpdateHandle( |
|
111
|
|
|
$identifier = self::GLOBAL_IDENTIFIER, |
|
112
|
|
|
string $fileName = self::TEST_FILE) |
|
113
|
|
|
{ |
|
114
|
|
|
$expectedHandle = "cms_page_view_selectable_{$identifier}_{$fileName}"; |
|
115
|
|
|
|
|
116
|
|
|
$handles = $this->layoutInterface->getUpdate()->getHandles(); |
|
117
|
|
|
$this->assertContains($expectedHandle, $handles); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
protected function setCustomUpdate(int $forPageId, string $fileName = self::TEST_FILE) |
|
121
|
|
|
{ |
|
122
|
|
|
$page = $this->getPage(); |
|
123
|
|
|
|
|
124
|
|
|
$this->layoutManager->setFakeFiles($forPageId, [$fileName]); |
|
125
|
|
|
|
|
126
|
|
|
$page->setData('layout_update_selected', $fileName); |
|
127
|
|
|
$this->pageResource->save($page); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param string $pageIdentifier |
|
132
|
|
|
* @return Page |
|
133
|
|
|
*/ |
|
134
|
|
|
protected function createPage(?string $pageIdentifier = self::PAGE_ID_FROM_FIXTURE): Page |
|
135
|
|
|
{ |
|
136
|
|
|
$page = $this->pageFactory->create(['customLayoutRepository' => $this->repository]); |
|
137
|
|
|
$page->setStoreId(self::STORE_ID); |
|
138
|
|
|
$page->load($pageIdentifier, Page::IDENTIFIER); |
|
139
|
|
|
|
|
140
|
|
|
return $page; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return Page |
|
145
|
|
|
*/ |
|
146
|
|
|
protected function getPage(): Page |
|
147
|
|
|
{ |
|
148
|
|
|
if (!$this->page || !$this->page->getId()) { |
|
149
|
|
|
$this->page = $this->createPage(); |
|
150
|
|
|
} |
|
151
|
|
|
return $this->page; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return int |
|
156
|
|
|
*/ |
|
157
|
|
|
private function getPageId(): int |
|
158
|
|
|
{ |
|
159
|
|
|
return (int)$this->getPage()->getId(); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths