|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace IntegerNet\GlobalCustomLayout\Test\Integration; |
| 5 | + |
| 6 | +use IntegerNet\GlobalCustomLayout\Test\Util\CustomLayoutManager; |
| 7 | +use IntegerNet\GlobalCustomLayout\Test\Util\PageLayoutUpdateManager; |
| 8 | +use Magento\Cms\Api\Data\PageInterface; |
| 9 | +use Magento\Cms\Model\Page as PageModel; |
| 10 | +use Magento\Cms\Model\Page\CustomLayoutRepositoryInterface; |
| 11 | +use Magento\Cms\Model\PageFactory as PageModelFactory; |
| 12 | +use Magento\Cms\Model\ResourceModel\Page as PageResourceModel; |
| 13 | +use Magento\Framework\Exception\AlreadyExistsException; |
| 14 | + |
| 15 | +class PageFrontendControllerTest extends AbstractFrontendControllerTest |
| 16 | +{ |
| 17 | + /** @var CustomLayoutManager */ |
| 18 | + protected $layoutManager; |
| 19 | + |
| 20 | + /** @var PageModel */ |
| 21 | + protected $page; |
| 22 | + |
| 23 | + /** @var PageResourceModel */ |
| 24 | + protected $pageResource; |
| 25 | + |
| 26 | + /** @var pageFactory $pageFactory */ |
| 27 | + protected $pageFactory; |
| 28 | + |
| 29 | + protected function getPage(int $storeId, string $pageIdentifier): pageModel |
| 30 | + { |
| 31 | + /** @var CustomLayoutManager $layoutManager */ |
| 32 | + $layoutManager = $this->getLayoutManager(); |
| 33 | + |
| 34 | + /** @var PageResourceModel $pageResource */ |
| 35 | + $pageResource = $this->getPageResource(); |
| 36 | + |
| 37 | + /** @var CustomLayoutRepositoryInterface $layoutRepo */ |
| 38 | + $layoutRepo = $this->objectManager->create( |
| 39 | + CustomLayoutRepositoryInterface::class, |
| 40 | + ['manager' => $layoutManager] |
| 41 | + ); |
| 42 | + |
| 43 | + /** @var PageModelFactory $pageFactory */ |
| 44 | + $pageFactory = $this->objectManager->get(PageModelFactory::class); |
| 45 | + |
| 46 | + /** @var PageModel $page */ |
| 47 | + $page = $pageFactory->create(['customLayoutRepository' => $layoutRepo]); |
| 48 | + |
| 49 | + $page->setStoreId($storeId); |
| 50 | + $pageResource->load($page, $pageIdentifier, PageInterface::IDENTIFIER); |
| 51 | + |
| 52 | + return $page; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Check that custom handles are applied when rendering a page. |
| 57 | + * |
| 58 | + * @return void |
| 59 | + * @throws AlreadyExistsException |
| 60 | + * @magentoDataFixture Magento/Cms/_files/pages.php |
| 61 | + */ |
| 62 | + public function testViewWithGlobalCustomUpdate(): void |
| 63 | + { |
| 64 | + $file = 'test-file'; |
| 65 | + $pageIdentifier = 'page100'; |
| 66 | + $storeId = 0; |
| 67 | + |
| 68 | + /** @var pageModel $page */ |
| 69 | + $page = $this->getPage($storeId, $pageIdentifier); |
| 70 | + /** @var CustomLayoutManager $layoutManager */ |
| 71 | + $layoutManager = $this->getLayoutManager(); |
| 72 | + |
| 73 | + /** @var PageResourceModel $pageResource */ |
| 74 | + $pageResource = $this->getPageResource(); |
| 75 | + |
| 76 | + $pageId = $page->getId(); |
| 77 | + $layoutManager->fakeAvailableFiles(0, [$file]); |
| 78 | + |
| 79 | + //Updating the custom attribute. |
| 80 | + $page->setData('layout_update_selected', $file); |
| 81 | + $pageResource->save($page); |
| 82 | + |
| 83 | + $this->dispatch('/cms/page/view/page_id/' . $pageId); |
| 84 | + |
| 85 | + $handles = $this->layoutInterface->getUpdate()->getHandles(); |
| 86 | + $this->assertContains("cms_page_view_selectable_0_{$file}", $handles); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @return PageResourceModel |
| 91 | + */ |
| 92 | + protected function getPageResource(): PageResourceModel |
| 93 | + { |
| 94 | + if (!$this->pageResource) { |
| 95 | + $this->pageResource = $this->objectManager->get(PageResourceModel::class); |
| 96 | + } |
| 97 | + return $this->pageResource; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @return CustomLayoutManager |
| 102 | + */ |
| 103 | + protected function getLayoutManager(): CustomLayoutManager |
| 104 | + { |
| 105 | + if (!$this->layoutManager) { |
| 106 | + $this->layoutManager = $this->objectManager->get(CustomLayoutManager::class); |
| 107 | + } |
| 108 | + return $this->layoutManager; |
| 109 | + } |
| 110 | +} |
0 commit comments