-
Notifications
You must be signed in to change notification settings - Fork 9
#4 add Tests for Product and Page. Fix issue in Page and Product plug… #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
84083ac
#4 add Tests for Product and Page. Fix issue in Page and Product plug…
f235deb
remove test-output
1036a0d
bump version to 1.1.0
fafb5a6
Add changelog and Testing info in Readme
72eca03
#4 Refactor Tests
11dfc07
Remove registration.php from code coverage report
bccf67e
Second try excluding registration.php from coverage
74f7956
#4 Change tests/Util to tests/src
5f1c054
#4 remove obsolete `->id()` checks
5f34946
#4 Reveal mystery guests
e7ed0f7
Undo committing test layout file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## 1.0.0 - 2020-04-27 | ||
### Added | ||
- Plugins for category, product and page layouts that allow custom layout files to be loaded with a global identifier | ||
(`0`). E.g. `catalog_category_view_selectable_0_.xml` for Categories. | ||
|
||
## 1.1.0 - 2020-05-02 | ||
### Added | ||
- Adds frontend test coverage for global custom layout updates | ||
- Fixes [#7](https://github.com/integer-net/magento2-global-custom-layout/issues/7) where layout handles were not merged in Product and Page Plugins' `afterFetchAvailableFiles()` method. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace IntegerNet\GlobalCustomLayout\Test\Integration; | ||
|
||
use IntegerNet\GlobalCustomLayout\Test\Util\CustomLayoutManager; | ||
use IntegerNet\GlobalCustomLayout\Test\Util\PageLayoutUpdateManager; | ||
use Magento\Cms\Api\Data\PageInterface; | ||
use Magento\Cms\Model\Page as PageModel; | ||
use Magento\Cms\Model\Page\CustomLayoutRepositoryInterface; | ||
use Magento\Cms\Model\PageFactory as PageModelFactory; | ||
use Magento\Cms\Model\ResourceModel\Page as PageResourceModel; | ||
use Magento\Framework\Exception\AlreadyExistsException; | ||
|
||
class PageFrontendControllerTest extends AbstractFrontendControllerTest | ||
{ | ||
/** @var CustomLayoutManager */ | ||
protected $layoutManager; | ||
|
||
/** @var PageModel */ | ||
protected $page; | ||
|
||
/** @var PageResourceModel */ | ||
protected $pageResource; | ||
|
||
/** @var pageFactory $pageFactory */ | ||
protected $pageFactory; | ||
|
||
protected function getPage(int $storeId, string $pageIdentifier): pageModel | ||
{ | ||
/** @var CustomLayoutManager $layoutManager */ | ||
$layoutManager = $this->getLayoutManager(); | ||
|
||
/** @var PageResourceModel $pageResource */ | ||
$pageResource = $this->getPageResource(); | ||
|
||
/** @var CustomLayoutRepositoryInterface $layoutRepo */ | ||
$layoutRepo = $this->objectManager->create( | ||
CustomLayoutRepositoryInterface::class, | ||
['manager' => $layoutManager] | ||
); | ||
|
||
/** @var PageModelFactory $pageFactory */ | ||
$pageFactory = $this->objectManager->get(PageModelFactory::class); | ||
|
||
/** @var PageModel $page */ | ||
$page = $pageFactory->create(['customLayoutRepository' => $layoutRepo]); | ||
|
||
$page->setStoreId($storeId); | ||
$pageResource->load($page, $pageIdentifier, PageInterface::IDENTIFIER); | ||
|
||
return $page; | ||
} | ||
|
||
/** | ||
* Check that custom handles are applied when rendering a page. | ||
* | ||
* @return void | ||
* @throws AlreadyExistsException | ||
* @magentoDataFixture Magento/Cms/_files/pages.php | ||
*/ | ||
public function testViewWithGlobalCustomUpdate(): void | ||
{ | ||
$file = 'test-file'; | ||
$pageIdentifier = 'page100'; | ||
$storeId = 0; | ||
|
||
/** @var pageModel $page */ | ||
$page = $this->getPage($storeId, $pageIdentifier); | ||
/** @var CustomLayoutManager $layoutManager */ | ||
$layoutManager = $this->getLayoutManager(); | ||
|
||
/** @var PageResourceModel $pageResource */ | ||
$pageResource = $this->getPageResource(); | ||
|
||
$pageId = $page->getId(); | ||
$layoutManager->fakeAvailableFiles(0, [$file]); | ||
|
||
//Updating the custom attribute. | ||
$page->setData('layout_update_selected', $file); | ||
$pageResource->save($page); | ||
wigman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$this->dispatch('/cms/page/view/page_id/' . $pageId); | ||
|
||
$handles = $this->layoutInterface->getUpdate()->getHandles(); | ||
$this->assertContains("cms_page_view_selectable_0_{$file}", $handles); | ||
} | ||
|
||
/** | ||
* @return PageResourceModel | ||
*/ | ||
protected function getPageResource(): PageResourceModel | ||
{ | ||
if (!$this->pageResource) { | ||
$this->pageResource = $this->objectManager->get(PageResourceModel::class); | ||
} | ||
return $this->pageResource; | ||
} | ||
|
||
/** | ||
* @return CustomLayoutManager | ||
*/ | ||
protected function getLayoutManager(): CustomLayoutManager | ||
{ | ||
if (!$this->layoutManager) { | ||
$this->layoutManager = $this->objectManager->get(CustomLayoutManager::class); | ||
} | ||
return $this->layoutManager; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace IntegerNet\GlobalCustomLayout\Test\Integration; | ||
|
||
use IntegerNet\GlobalCustomLayout\Test\Util\ProductLayoutUpdateManager; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Framework\Exception\InputException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Exception\StateException; | ||
|
||
class ProductFrontendControllerTest extends AbstractFrontendControllerTest | ||
{ | ||
/** | ||
* Check that Global Custom Layout Update files work for Product views. | ||
* | ||
* @magentoDataFixture Magento/Catalog/controllers/_files/products.php | ||
* @return void | ||
* @throws CouldNotSaveException | ||
* @throws InputException | ||
* @throws NoSuchEntityException | ||
* @throws StateException | ||
*/ | ||
public function testViewWithGlobalCustomUpdate(): void | ||
{ | ||
//Setting a fake file for the product. | ||
$file = 'test-file'; | ||
|
||
/** @var ProductRepositoryInterface $repository */ | ||
$repository = $this->objectManager->create(ProductRepositoryInterface::class); | ||
$sku = 'simple_product_1'; | ||
$product = $repository->get($sku); | ||
$productId = $product->getId(); | ||
|
||
/** @var ProductLayoutUpdateManager $layoutManager */ | ||
$layoutManager = $this->objectManager->get(ProductLayoutUpdateManager::class); | ||
$layoutManager->setFakeFiles(0, [$file]); | ||
|
||
//Updating the custom attribute. | ||
$product->setCustomAttribute('custom_layout_update_file', $file); | ||
$repository->save($product); | ||
|
||
//Viewing the product | ||
$this->dispatch("catalog/product/view/id/$productId"); | ||
|
||
//Layout handles must contain the file. | ||
$handles = $this->layoutInterface | ||
->getUpdate() | ||
->getHandles(); | ||
$this->assertContains("catalog_product_view_selectable_0_{$file}", $handles); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace IntegerNet\GlobalCustomLayout\Test\Util; | ||
wigman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use Magento\Cms\Api\Data\PageInterface; | ||
|
||
/** | ||
* Manager allowing to fake available files. | ||
*/ | ||
class CustomLayoutManager extends \Magento\TestFramework\Cms\Model\CustomLayoutManager | ||
{ | ||
/** | ||
* @var string[][] | ||
*/ | ||
private $files = []; | ||
|
||
/** | ||
* Fake available files for given page. | ||
* | ||
* Pass null to unassign fake files. | ||
* | ||
* @param int $forPageId | ||
* @param string[]|null $files | ||
* @return void | ||
*/ | ||
public function fakeAvailableFiles(int $forPageId, ?array $files): void | ||
{ | ||
if ($files === null) { | ||
unset($this->files[$forPageId]); | ||
} else { | ||
$this->files[$forPageId] = $files; | ||
} | ||
} | ||
|
||
/** | ||
* Fetches fake/mock files added through $this->fakeAvailableFiles() | ||
* | ||
* @param PageInterface $page | ||
* @return array | ||
*/ | ||
public function fetchAvailableFiles(PageInterface $page): array | ||
{ | ||
if (array_key_exists(0, $this->files)) { | ||
return $this->files[0]; | ||
} | ||
|
||
return parent::fetchAvailableFiles($page); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.