Skip to content

Commit

Permalink
Merge pull request #62 from tddwizard/theme-fixture
Browse files Browse the repository at this point in the history
Theme fixture
  • Loading branch information
schmengler authored Dec 27, 2020
2 parents b559d60 + b2f88bc commit 6d8f19b
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ before_install:
- sudo service elasticsearch restart
before_script:
- |
[[ $COVERAGE == "true" ]] || phpenv config-rm xdebug.ini
if [[ $COVERAGE == "true" ]]; then \
pecl install -f xdebug-2.9.8 #see https://github.com/magento/magento2/issues/28961 \
else
phpenv config-rm xdebug.ini
fi
./.travis/before_script.sh
script: phpunit -c magento2/dev/tests/$TEST_SUITE `[[ $COVERAGE == "true" ]] && echo "--coverage-text --coverage-clover=/tmp/coverage.clover"`
after_script:
Expand Down
7 changes: 5 additions & 2 deletions .travis/before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > ~/.phpenv/versions/$(phpenv
echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
phpenv rehash;

composer selfupdate
composer selfupdate --1

# clone main magento github repository
git clone --branch $MAGENTO_VERSION --depth=1 https://github.com/magento/magento2
Expand Down Expand Up @@ -49,8 +49,11 @@ case $TEST_SUITE in
SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION;
CREATE DATABASE magento_integration_tests;
'
cp etc/install-config-mysql.travis.php.dist etc/install-config-mysql.php
cp etc/install-config-mysql.php.dist etc/install-config-mysql.php
# Remove AMQP configuration
sed -i '/amqp/d' etc/install-config-mysql.php
# Remove default root password
sed -i 's/123123q//' etc/install-config-mysql.php

cd ../../..
echo "Wait for ElasticSearch on port 9200..."
Expand Down
37 changes: 37 additions & 0 deletions src/Theme/ThemeFixture.php
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);
}
}
13 changes: 3 additions & 10 deletions tests/Catalog/IndexerErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class IndexerErrorsTest extends TestCase
private static $indexIsScheduledOrig;

/**
* @deprecated the test should be removed in next release, but we should still keep the exception in case this
* happens again
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
*/
public function testHelpfulErrorMessageForFulltextIndexSchedule()
{
$this->onlyRunFromMagento('2.3.0');
$this->markTestSkipped('Since Magento 2.3.6 / 2.4.1 these transaction exceptions do not occur anymore');
$this->expectException(\Exception::class);

try {
Expand Down Expand Up @@ -58,13 +60,4 @@ public static function disableReindexScheduleRollback()
$model = Bootstrap::getObjectManager()->get(IndexerRegistry::class)->get('catalogsearch_fulltext');
$model->setScheduled(self::$indexIsScheduledOrig);
}

private function onlyRunFromMagento($magentoVersion): void
{
/** @var ProductMetadataInterface $productMetadata */
$productMetadata = Bootstrap::getObjectManager()->get(ProductMetadataInterface::class);
if (version_compare($productMetadata->getVersion(), $magentoVersion, '<')) {
$this->markTestSkipped('Only relevant for Magento >= ' . $magentoVersion . '');
}
}
}
35 changes: 35 additions & 0 deletions tests/Theme/ThemeFixtureTest.php
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 tests/Theme/_files/design/frontend/Custom/default/registration.php
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 tests/Theme/_files/design/frontend/Custom/default/theme.xml
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>

0 comments on commit 6d8f19b

Please sign in to comment.