Skip to content

Commit

Permalink
OXDEV-9043 Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liulka-oxid committed Jan 14, 2025
1 parent 8d634be commit c76a5bf
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 69 deletions.
10 changes: 1 addition & 9 deletions tests/Integration/Event/AdminModeSwitch/RendererSwitchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,11 @@ public function setUp(): void
parent::setUp();

$this->initFixtures(__DIR__);
$this->setShopSourceFixture();
$this->setThemeFixture('testTheme');
$this->reloadTestContainer();
Registry::getConfig()->setAdminMode(true);
}

public function tearDown(): void
{
parent::tearDown();

Registry::getConfig()->setAdminMode(false);
$this->eventFiredCount = 0;
}

public function testSendSentNowMailWillSwitchToAppropriateTemplate(): void
{
$email = new EmailStub();
Expand Down
23 changes: 20 additions & 3 deletions tests/Integration/TestingFixturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trait TestingFixturesTrait
use ContainerTrait;

private string $fixtureRoot = __DIR__;
private string $currentTheme = 'default';

public function initFixtures(string $fixtureRoot): void
{
Expand All @@ -32,31 +33,42 @@ public function setupModuleFixture(string $moduleId): void
{
$this->installModuleFixture($moduleId);
$this->activateModuleFixture($moduleId);
$this->destroyTestContainer();
}

public function uninstallModuleFixture(string $moduleId): void
{
$this->get(ModuleInstallerInterface::class)
->uninstall($this->getPackageFixture($moduleId));
$this->destroyTestContainer();
}

public function deactivateModuleFixture(string $moduleId): void
{
$this->get(ModuleActivationBridgeInterface::class)
->deactivate($moduleId, $this->get(BasicContextInterface::class)->getDefaultShopId());
$this->destroyTestContainer();
}

public function setShopSourceFixture(): void
{
$this->createContainer();
$this->container->setParameter('oxid_esales.shop_source_directory', "{$this->getFixturesDirectory()}/shop/source/");
$this->compileContainer();
$this->setParameter(
'oxid_esales.shop_source_directory',
"{$this->getFixturesDirectory()}/shop/source/"
);
}

public function reloadTestContainer(): void
{
$this->setShopSourceFixture();
$this->setThemeFixture($this->currentTheme);
$this->attachContainerToContainerFactory();
}

public function setThemeFixture(string $themeId): void
{
Registry::getConfig()->setConfigParam('sTheme', $themeId);
$this->currentTheme = $themeId;
}

public function setChildThemeFixture(string $themeId): void
Expand Down Expand Up @@ -90,4 +102,9 @@ private function getPackageFixture(string $moduleId): OxidEshopPackage
{
return new OxidEshopPackage("{$this->getFixturesDirectory()}/$moduleId/");
}

private function destroyTestContainer(): void
{
$this->container = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
use OxidEsales\Eshop\Core\ShopControl;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\Twig\Tests\Integration\TestingFixturesTrait;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\LoggerInterface;

#[RunTestsInSeparateProcesses]
final class ModuleControllerRenderTest extends TestCase
{
use ContainerTrait;
Expand All @@ -32,23 +30,19 @@ final class ModuleControllerRenderTest extends TestCase
private const THEME = 'testTheme';

private int $shopID = 1;
private ShopControl $shopControl;
private ShopControl $shopControl;

protected function setUp(): void
protected function setUp(): void
{
parent::setUp();

$_GET['searchparam'] = '';
$_GET['page'] = '';
$_GET['tpl'] = '';

$this->initFixtures(__DIR__);
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->setFixtureBaseLanguage(0);
$this->autoloadFixtures();
$this->stubRequestData();
$this->reloadTestContainer();

$this->shopControl = new ShopControl();
}
Expand All @@ -59,20 +53,16 @@ protected function tearDown(): void
$this->uninstallModuleFixture($moduleId);
}

unset($_GET['searchparam']);
unset($_GET['page']);
unset($_GET['tpl']);

parent::tearDown();
}

public function testRenderWithExistingTemplate(): void
{
ob_start();
$this->shopControl->start('module1_controller', '');
$output = ob_get_clean();
$this->shopControl->start('module1_controller', '');
$output = ob_get_clean();

$this->assertStringContainsString('Module 1 Header', $output);
$this->assertStringContainsString('Module 1 Header', $output);
$this->assertStringContainsString((new \DateTime())->format('Y-m-d'), $output);
}

Expand Down Expand Up @@ -122,16 +112,16 @@ public function testRenderWithMissingTemplateWillLogMessage(): void

private function stubRequestData(): void
{
$_SERVER["REQUEST_METHOD"] = 'GET';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_URI'] = '';
}

private function switchDebugMode(bool $enable): void
{
$this->destroyTestContainer();
$this->createContainer();
$this->container->setParameter('oxid_esales.debug_mode', $enable);
$this->container->compile();
$this->attachContainerToContainerFactory();
$this->reloadTestContainer();
}

private function autoloadFixtures(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PHPUnit\Framework\TestCase;
use Twig\Error\LoaderError;

/** @runTestsInSeparateProcesses */
final class ModulesTemplateChainTest extends TestCase
{
use ContainerTrait;
Expand Down Expand Up @@ -45,8 +44,8 @@ protected function setUp(): void
parent::setUp();

$this->initFixtures(__DIR__);
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();
}

protected function tearDown(): void
Expand Down Expand Up @@ -77,6 +76,7 @@ public function testRenderWithShopsSingeTemplate(): void
public function testRenderWithModulesSingeTemplate(): void
{
$this->setupModuleFixture('module1');
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render('@module1/' . self::TEMPLATE_NO_EXTENDS);

Expand All @@ -86,8 +86,7 @@ public function testRenderWithModulesSingeTemplate(): void
public function testRenderWithActiveModuleExtendingShop(): void
{
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_EXTENDS);

Expand All @@ -98,8 +97,7 @@ public function testRenderWithActiveModuleExtendingShop(): void
public function testRenderWithActiveModuleExtendingShopAndNonHtmlTemplate(): void
{
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_NON_HTML_FILE);

Expand All @@ -110,8 +108,8 @@ public function testRenderWithActiveModuleExtendingShopAndNonHtmlTemplate(): voi
public function testRenderWithActiveModuleAndMissingThemeTemplateWillUseTemplateFromDefaultTheme(): void
{
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME_2);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_EXTENDS);

Expand All @@ -123,8 +121,7 @@ public function testRenderWithInactiveModule(): void
{
$this->setupModuleFixture('module1');
$this->deactivateModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_EXTENDS);

Expand All @@ -136,8 +133,7 @@ public function testRenderWith2ActiveModules(): void
{
$this->setupModuleFixture('module1');
$this->setupModuleFixture('module2');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_EXTENDS);

Expand All @@ -151,8 +147,7 @@ public function testRenderWith3ActiveModules(): void
$this->setupModuleFixture('module1');
$this->setupModuleFixture('module2');
$this->setupModuleFixture('module3');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_EXTENDS);

Expand All @@ -168,8 +163,7 @@ public function testRenderWith3ModulesAndDeactivation(): void
$this->setupModuleFixture('module2');
$this->setupModuleFixture('module3');
$this->deactivateModuleFixture('module2');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_EXTENDS);

Expand Down Expand Up @@ -198,8 +192,7 @@ public function testRenderWithArrayExtends(): void
public function testRenderWithIncludeAndModuleWillRenderModuleTemplate(): void
{
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_INCLUDE);

Expand All @@ -212,8 +205,7 @@ public function testRenderWithIncludeAndModuleWillRenderModuleTemplate(): void
public function testRenderWithIncludeDynamicAndModuleWillRenderModuleTemplate(): void
{
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$actual = $this->get(TemplateEngineInterface::class)->render(self::TEMPLATE_WITH_INCLUDE_DYNAMIC);

Expand All @@ -234,8 +226,7 @@ public function testRenderWithIncludedNonTemplateFileWillRenderWithoutErrors():
public function testRenderWithInvalidExtendsValue(): void
{
$this->setupModuleFixture('module1');
$this->setShopSourceFixture();
$this->setThemeFixture(self::THEME);
$this->reloadTestContainer();

$this->expectException(LoaderError::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

namespace OxidEsales\Twig\Tests\Integration\TwigEngine\TemplateChainSorting;

use org\bovigo\vfs\vfsStream;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateEngineInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use OxidEsales\Twig\Tests\Integration\TestingFixturesTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @runTestsInSeparateProcesses */
final class ModulesTemplateChainSortingTest extends TestCase
final class ModulesTemplateChainSortingTest extends IntegrationTestCase
{
use ContainerTrait;
use TestingFixturesTrait;
Expand All @@ -34,7 +32,7 @@ final class ModulesTemplateChainSortingTest extends TestCase

private BasicContextInterface $context;

protected function setUp(): void
public function setUp(): void
{
parent::setUp();

Expand All @@ -43,11 +41,11 @@ protected function setUp(): void
foreach (self::MODULE_IDS as $moduleId) {
$this->setupModuleFixture($moduleId);
}
$this->setShopSourceFixture();
$this->setThemeFixture(self::FIXTURE_THEME);
$this->reloadTestContainer();
}

protected function tearDown(): void
public function tearDown(): void
{
foreach (self::MODULE_IDS as $moduleId) {
$this->uninstallModuleFixture($moduleId);
Expand Down Expand Up @@ -260,13 +258,17 @@ public static function renderWithModuleTemplateAndFaultySortingConfigDataProvide

private function addTemplateExtensionsSortingToShopConfiguration(string $sorting, string $template): void
{
$templateExtensions = sprintf(
$sorting,
$template
);
file_put_contents(
vfsStream::url("configuration/shops/{$this->context->getDefaultShopId()}/template_extension_chain.yaml"),
$templateExtensions
$this->get(BasicContextInterface::class)->getShopConfigurationDirectory(
$this->get(BasicContextInterface::class)->getDefaultShopId()
) .
'/template_extension_chain.yaml',
\sprintf(
$sorting,
$template
)
);
$this->destroyTestContainer();
$this->reloadTestContainer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
use OxidEsales\Twig\Tests\Integration\TestingFixturesTrait;
use PHPUnit\Framework\TestCase;

/**
* @runTestsInSeparateProcesses
*/
final class ShopTemplateDirectoryResolvingTest extends TestCase
{
use ContainerTrait;
Expand All @@ -33,8 +30,8 @@ protected function setUp(): void
parent::setUp();

$this->initFixtures(__DIR__);
$this->setShopSourceFixture();
$this->setThemeFixture(self::PARENT_THEME);
$this->reloadTestContainer();
}

public function testRenderWithParentThemeAndParentTemplate(): void
Expand Down

0 comments on commit c76a5bf

Please sign in to comment.