-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from tddwizard/theme-fixture
Theme fixture
- Loading branch information
Showing
7 changed files
with
108 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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,37 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TddWizard\Fixtures\Theme; | ||
|
||
use Magento\Framework\View\DesignInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Theme\Model\Theme\Registration; | ||
|
||
/** | ||
* A fixture to test theme features, e.g. with with test themes in `@magentoComponentsDir` | ||
*/ | ||
class ThemeFixture | ||
{ | ||
|
||
/** | ||
* Register new themes from the `@magentoComponentsDir` fixture in the database | ||
*/ | ||
public static function registerTestThemes(): void | ||
{ | ||
/** @var Registration $registration */ | ||
$registration = Bootstrap::getObjectManager()->get(Registration::class); | ||
$registration->register(); | ||
} | ||
|
||
/** | ||
* Set the current theme | ||
* | ||
* @param string $themePath a theme identifier without the area, e.g. Magento/luma | ||
*/ | ||
public static function setCurrentTheme(string $themePath): void | ||
{ | ||
/** @var DesignInterface $design */ | ||
$design = Bootstrap::getObjectManager()->get(DesignInterface::class); | ||
$design->setDesignTheme($themePath); | ||
} | ||
} |
This file contains 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 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,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TddWizard\Fixtures\Theme; | ||
|
||
use Magento\Framework\View\DesignInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @magentoAppIsolation enabled | ||
* @magentoAppArea frontend | ||
* @magentoComponentsDir ../../../../vendor/tddwizard/magento2-fixtures/tests/Theme/_files/design | ||
*/ | ||
class ThemeFixtureTest extends TestCase | ||
{ | ||
public function testSetCurrentFrontendTheme() | ||
{ | ||
ThemeFixture::setCurrentTheme('Magento/blank'); | ||
/** @var DesignInterface $design */ | ||
$design = Bootstrap::getObjectManager()->get(DesignInterface::class); | ||
$this->assertEquals('Magento/blank', $design->getDesignTheme()->getCode()); | ||
} | ||
|
||
public function testCanUseTestThemeAfterRegistering() | ||
{ | ||
ThemeFixture::registerTestThemes(); | ||
ThemeFixture::setCurrentTheme('Custom/default'); | ||
/** @var DesignInterface $design */ | ||
$design = Bootstrap::getObjectManager()->get(DesignInterface::class); | ||
$this->assertEquals('Custom/default', $design->getDesignTheme()->getCode()); | ||
$this->assertGreaterThan(0, $design->getDesignTheme()->getId()); | ||
$this->assertEquals('Magento/blank', $design->getDesignTheme()->getParentTheme()->getCode()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Theme/_files/design/frontend/Custom/default/registration.php
This file contains 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,11 @@ | ||
<?php | ||
/** | ||
* Hyvä Themes - https://hyva.io | ||
* Copyright © Hyvä Themes 2020-present. All rights reserved. | ||
* This product is licensed per Magento install | ||
* See https://hyva.io/license | ||
*/ | ||
|
||
use \Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Custom/default', __DIR__); |
12 changes: 12 additions & 0 deletions
12
tests/Theme/_files/design/frontend/Custom/default/theme.xml
This file contains 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,12 @@ | ||
<!-- | ||
/** | ||
* Hyvä Themes - https://hyva.io | ||
* Copyright © Hyvä Themes 2020-present. All rights reserved. | ||
* This product is licensed per Magento install | ||
* See https://hyva.io/license | ||
*/ | ||
--> | ||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd"> | ||
<title>Test theme</title> | ||
<parent>Magento/blank</parent> | ||
</theme> |