Skip to content

Commit

Permalink
OXDEV-7248 Update tests to run with shop 8.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Dec 11, 2024
1 parent 29d9a38 commit 04f9323
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/oxid-esales/module-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
}
}
custom_script_container: |
vendor/bin/oe-console oe:database:reset --db-host=mysql --db-port=3306 --db-name=example --db-user=root --db-password=root --force
vendor/bin/oe-console oe:database:reset
vendor/bin/oe-console oe:module:install ./
vendor/bin/oe-eshop-doctrine_migration migrations:migrate
vendor/bin/oe-console oe:module:activate oe_moduletemplate
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dispatch_module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- 'PHP8.2/MariaDB11'
- 'PHP8.3/MySQL8.0'
- 'PHP8.3/MariaDB11'
default: 'PHP8.2/MySQL8.0'
default: 'PHP8.3/MySQL8.0'
description: 'Limit to one PHP/MySQL combination'
use_dev_version:
type: choice
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
;;
esac
# shellcheck disable=SC2088
TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}~/module-template.yaml"
TESTPLAN="~/defaults/8.0.x.yaml,${LIMIT}~/module-template.yaml"
echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}"
dispatch_stable:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Undecided] - Unreleased

### Changed
- Updated to work with OXID eShop 8.0.x.

## [v5.0.0] - Unreleased

### Changed
Expand Down
14 changes: 10 additions & 4 deletions tests/Codeception/Acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ modules:
license: '%license_key%'
- WebDriver:
url: '%SHOP_URL%'
host: '%SELENIUM_SERVER_HOST%'
browser: '%BROWSER_NAME%'
browser: '%BROWSER%'
port: '%SELENIUM_SERVER_PORT%'
window_size: 1920x1080
host: '%SELENIUM_SERVER_HOST%'
window_size: maximize
clear_cookies: true
restart: true
capabilities:
chromeOptions:
excludeSwitches: [ 'enable-automation' ]
prefs:
'credentials_enable_service': false
- Db:
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%;charset=utf8'
user: '%DB_USERNAME%'
Expand Down Expand Up @@ -48,7 +54,7 @@ modules:
- \OxidEsales\Codeception\Module\Database
- Db
- \OxidEsales\Codeception\Module\Translation\TranslationsModule:
shop_path: '%SHOP_SOURCE_PATH%'
shop_path: '%PROJECT_ROOT%/source'
paths:
- 'Application/views/apex'
- 'Application/views/admin_twig'
Expand Down
3 changes: 2 additions & 1 deletion tests/Codeception/Acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
declare(strict_types=1);

// This is acceptance bootstrap
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator;
use Symfony\Component\Filesystem\Path;

require_once Path::join((new \OxidEsales\Facts\Facts())->getShopRootPath(), 'source', 'bootstrap.php');
require_once Path::join((new ProjectRootLocator())->getProjectRoot(), 'source', 'bootstrap.php');

$helper = new \OxidEsales\Codeception\Module\FixturesHelper();
$helper->loadRuntimeFixtures(__DIR__ . '/../Support/Data/fixtures.php');
153 changes: 153 additions & 0 deletions tests/Codeception/Config/CodeceptionParametersProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\ModuleTemplate\Tests\Codeception\Config;


use OxidEsales\Codeception\Module\Database;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\DataObject\DatabaseConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\Edition\Edition;
use OxidEsales\EshopCommunity\Internal\Framework\Edition\EditionDirectoriesLocator;
use OxidEsales\EshopCommunity\Internal\Framework\Env\DotenvLoader;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\DirectoryNotExistentException;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectDirectoriesLocator;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator;
use Symfony\Component\Filesystem\Path;

class CodeceptionParametersProvider
{
private DatabaseConfiguration $dbConfig;

public function getParameters(): array
{
$this->loadEnvironmentVariables();

$this->dbConfig = (new DatabaseConfiguration(getenv('OXID_DB_URL')));
return [
'SHOP_URL' => getenv('OXID_SHOP_BASE_URL'),
'PROJECT_ROOT' => $this->getProjectRoot(),
'VENDOR_PATH' => (new ProjectDirectoriesLocator())->getVendorPath(),
'SOURCE_RELATIVE_PACKAGE_PATH' => $this->getSourceRelativePackagePath(),
'DB_NAME' => $this->getDbName(),
'DB_USERNAME' => $this->getDbUser(),
'DB_PASSWORD' => $this->getDbPass(),
'DB_HOST' => $this->getDbHost(),
'DB_PORT' => $this->getDbPort(),
'DUMP_PATH' => $this->getTestDataDumpFilePath(),
'MODULE_DUMP_PATH' => $this->getCodeceptionSpecificFixtureFilePath(),
'FIXTURES_PATH' => $this->getTestFixtureSqlFilePath(),
'OUT_DIRECTORY' => (new ProjectDirectoriesLocator())->getOutPath(),
'OUT_DIRECTORY_FIXTURES' => $this->getOutDirectoryFixturesPath(),
'MYSQL_CONFIG_PATH' => $this->generateMysqlStarUpConfigurationFile(),
'SELENIUM_SERVER_PORT' => getenv('SELENIUM_SERVER_PORT') ?: '4444',
'SELENIUM_SERVER_HOST' => getenv('SELENIUM_SERVER_HOST') ?: 'selenium',
'PHP_BIN' => (getenv('PHPBIN')) ?: 'php',
'SCREEN_SHOT_URL' => getenv('CC_SCREEN_SHOTS_URL') ?: '',
'BROWSER' => getenv('BROWSER_NAME') ?: 'chrome',
'THEME_ID' => getenv('THEME_ID') ?: 'apex',
'MAIL_HOST' => getenv('MAIL_HOST') ?: 'mailpit',
'MAIL_WEB_PORT' => getenv('MAIL_WEB_PORT') ?: '8025',
];
}

private function getSourceRelativePackagePath(): string
{
return(str_replace($this->getProjectRoot(), '..', __DIR__) . '/../../../');
}

private function getCodeceptionSpecificFixtureFilePath(): string
{
return Path::join(__DIR__, '../Support/Data', 'fixtures.sql');
}

private function getTestDataDumpFilePath(): string
{
return Path::join(
$this->getShopTestPath(),
'/Codeception/Support/_generated/shop-dump.sql'
);
}

private function getTestFixtureSqlFilePath(): string
{
return Path::join(
$this->getShopTestPath(),
'/Codeception/Support/Data/dump.sql',
);
}

private function getOutDirectoryFixturesPath(): string
{
return Path::join(
$this->getShopTestPath(),
'/Codeception/Support/Data/out',
);
}

private function getShopTestPath(): string
{
try {
$testsPath = Path::join(
(new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise),
'Tests'
);
} catch (DirectoryNotExistentException) {
$testsPath = Path::join(
$this->getProjectRoot(),
'tests'
);
}
return $testsPath;
}

private function generateMysqlStarUpConfigurationFile(): string
{
return Database::generateStartupOptionsFile(
$this->getDbUser(),
$this->getDbPass(),
$this->getDbHost(),
$this->getDbPort(),
);
}

private function getDbName(): string
{
return getenv('DB_NAME') ?: $this->dbConfig->getName();
}

private function getDbUser(): string
{
return getenv('DB_USERNAME') ?: $this->dbConfig->getUser();
}

private function getDbPass(): string
{
return getenv('DB_PASSWORD') ?: $this->dbConfig->getPass();
}

private function getDbHost(): string
{
return getenv('DB_HOST') ?: $this->dbConfig->getHost();
}

private function getDbPort(): int
{
return (int) getenv('DB_PORT') ?: $this->dbConfig->getPort();
}

private function loadEnvironmentVariables(): void
{
(new DotenvLoader($this->getProjectRoot()))->loadEnvironmentVariables();
}

private function getProjectRoot(): string
{
return (new ProjectRootLocator())->getProjectRoot();
}
}
60 changes: 2 additions & 58 deletions tests/Codeception/Config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,6 @@

declare(strict_types=1);

use OxidEsales\Codeception\Module\Database\DatabaseDefaultsFileGenerator;
use OxidEsales\Facts\Config\ConfigFile;
use OxidEsales\Facts\Facts;
use Symfony\Component\Filesystem\Path;
namespace OxidEsales\ModuleTemplate\Tests\Codeception\Config;

$facts = new Facts();

return [
'SHOP_URL' => $facts->getShopUrl(),
'SHOP_SOURCE_PATH' => $facts->getSourcePath(),
'SOURCE_RELATIVE_PACKAGE_PATH' => getSourceRelativePackagePath($facts),
'VENDOR_PATH' => $facts->getVendorPath(),
'DB_NAME' => $facts->getDatabaseName(),
'DB_USERNAME' => $facts->getDatabaseUserName(),
'DB_PASSWORD' => $facts->getDatabasePassword(),
'DB_HOST' => $facts->getDatabaseHost(),
'DB_PORT' => $facts->getDatabasePort(),
'DUMP_PATH' => getTemporaryDataDumpFilePath(),
'MODULE_DUMP_PATH' => getCodeceptionSpecificFixtureFilePath(),
'MYSQL_CONFIG_PATH' => getMysqlConfigPath(),
'FIXTURES_PATH' => getGenericFixtureSqlFilePath(),
'SELENIUM_SERVER_PORT' => getenv('SELENIUM_SERVER_PORT') ?: '4444',
'SELENIUM_SERVER_HOST' => getenv('SELENIUM_SERVER_HOST') ?: 'selenium',
'BROWSER_NAME' => getenv('BROWSER_NAME') ?: 'chrome',
'PHP_BIN' => getenv('PHPBIN') ?: 'php',
'SCREEN_SHOT_URL' => getenv('CC_SCREEN_SHOTS_PATH') ?: '',
'THEME_ID' => getenv('THEME_ID') ?: 'apex',
];

function getSourceRelativePackagePath(Facts $facts): string
{
return str_replace($facts->getShopRootPath(), '..', __DIR__) . '/../../../';
}

function getTemporaryDataDumpFilePath(): string
{
return Path::join(__DIR__, '../Support', '_generated', 'dump.sql');
}

function getCodeceptionSpecificFixtureFilePath(): string
{
return Path::join(__DIR__, '../Support/Data', 'fixtures.sql');
}

function getMysqlConfigPath(): string
{
$facts = new Facts();
$configFilePath = Path::join($facts->getSourcePath(), 'config.inc.php');
$configFile = new ConfigFile($configFilePath);
$generator = new DatabaseDefaultsFileGenerator($configFile);

return $generator->generate();
}

function getGenericFixtureSqlFilePath(): string
{
$facts = new Facts();
return Path::join(__DIR__, '/../../', 'Fixtures', 'testdata_' . strtolower($facts->getEdition()) . '.sql');
}
return (new CodeceptionParametersProvider())->getParameters();
5 changes: 1 addition & 4 deletions tests/Codeception/Support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OxidEsales\Codeception\Admin\AdminPanel;
use OxidEsales\Codeception\Page\Home;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\Facts\Facts;
use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface;

/**
Expand Down Expand Up @@ -88,9 +87,7 @@ public function resetGreetingTracker(): void

public function getShopUrl(): string
{
$facts = new Facts();

return $facts->getShopUrl();
return getenv('OXID_SHOP_BASE_URL');
}

public function openAdmin(): AdminLoginPage
Expand Down
7 changes: 1 addition & 6 deletions tests/Codeception/Support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@

namespace OxidEsales\ModuleTemplate\Tests\Codeception\Support\Helper;

use OxidEsales\Facts\Facts;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

final class Acceptance extends \Codeception\Module
{
public function _beforeSuite($settings = []): void
{
exec((new Facts())->getShopRootPath() . '/bin/oe-console oe:module:activate oe_moduletemplate');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OxidEsales\ModuleTemplate\Settings\Service\ModuleSettingsServiceInterface;
use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

/*
* Here we have full integration test cases for a what we call 'chain extended' shop class.
Expand Down Expand Up @@ -46,9 +47,7 @@ public function tearDown(): void
parent::tearDown();
}

/**
* @dataProvider providerCanUpdateOemtGreeting
*/
#[DataProvider('providerCanUpdateOemtGreeting')]
public function testCanUpdateOemtGreeting(bool $hasUser, string $mode, bool $expected): void
{
$moduleSettings = $this->get(ModuleSettingsServiceInterface::class);
Expand All @@ -64,10 +63,9 @@ public function testCanUpdateOemtGreeting(bool $hasUser, string $mode, bool $exp
}

/**
* @dataProvider providerGetOemtGreeting
*
* @param mixed $expect
*/
#[DataProvider('providerGetOemtGreeting')]
public function testGetOemtGreeting(bool $hasUser, string $mode, $expect): void
{
$moduleSettings = $this->get(ModuleSettingsServiceInterface::class);
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/Extension/Model/BasketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private function prepareTestData(): void
'oxvarcount' => null,
'oxstockflag' => null,
'oxshopid' => null,
'oxlowstockactive' => 0
]);
$product->save();
}
Expand Down
Loading

0 comments on commit 04f9323

Please sign in to comment.