From 39c5a1dcd27936ab22020577583044f0f48f01b2 Mon Sep 17 00:00:00 2001 From: hkreuter Date: Wed, 22 Jan 2025 10:11:16 +0100 Subject: [PATCH] OXDEV-7248 Update module to work with shop 8.0 --- CHANGELOG-v10.md | 5 + tests/Codeception/Acceptance.suite.yml | 2 + tests/Codeception/Acceptance/_bootstrap.php | 3 +- .../Config/CodeceptionParametersProvider.php | 151 ++++++++++++++---- tests/Integration/EnterpriseTestCase.php | 1 - .../GraphQLQueryHandlerFileUploadTest.php | 3 + .../RefreshTokenRepositoryTest.php | 14 +- .../Integration/Infrastructure/TokenTest.php | 38 ++++- tests/phpunit.xml | 1 + 9 files changed, 176 insertions(+), 42 deletions(-) diff --git a/CHANGELOG-v10.md b/CHANGELOG-v10.md index 8783b6c2..b77a609a 100644 --- a/CHANGELOG-v10.md +++ b/CHANGELOG-v10.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Undecided] - unreleased + +## Changed +- Update module to work with OXID eShop 8.0 + ## [10.1.0] - unreleased ## Changed diff --git a/tests/Codeception/Acceptance.suite.yml b/tests/Codeception/Acceptance.suite.yml index 82e18e36..f0cdafa8 100644 --- a/tests/Codeception/Acceptance.suite.yml +++ b/tests/Codeception/Acceptance.suite.yml @@ -1,6 +1,8 @@ # suite config actor: AcceptanceTester path: Acceptance +bootstrap: _bootstrap.php + modules: enabled: - Asserts diff --git a/tests/Codeception/Acceptance/_bootstrap.php b/tests/Codeception/Acceptance/_bootstrap.php index e6961e78..37110b4c 100644 --- a/tests/Codeception/Acceptance/_bootstrap.php +++ b/tests/Codeception/Acceptance/_bootstrap.php @@ -8,6 +8,7 @@ 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'); diff --git a/tests/Codeception/Config/CodeceptionParametersProvider.php b/tests/Codeception/Config/CodeceptionParametersProvider.php index 97c3ebd8..7bd45bd3 100644 --- a/tests/Codeception/Config/CodeceptionParametersProvider.php +++ b/tests/Codeception/Config/CodeceptionParametersProvider.php @@ -9,51 +9,144 @@ namespace OxidEsales\GraphQL\Base\Tests\Codeception\Config; -use OxidEsales\Codeception\Module\Database\DatabaseDefaultsFileGenerator; -use OxidEsales\Facts\Config\ConfigFile; -use OxidEsales\Facts\Facts; +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; -if ($shopRootPath = getenv('SHOP_ROOT_PATH')) { - require_once(Path::join($shopRootPath, 'source', 'bootstrap.php')); -} - -class CodeceptionParametersProvider { +class CodeceptionParametersProvider +{ + private DatabaseConfiguration $dbConfig; public function getParameters(): array { - $facts = new Facts(); - $php = (getenv('PHPBIN')) ?: 'php'; + $this->loadEnvironmentVariables(); + $this->dbConfig = (new DatabaseConfiguration(getenv('OXID_DB_URL'))); return [ - 'SHOP_URL' => $facts->getShopUrl(), - 'SHOP_SOURCE_PATH' => $facts->getSourcePath(), - 'VENDOR_PATH' => $facts->getVendorPath(), - 'DB_NAME' => $facts->getDatabaseName(), - 'DB_USERNAME' => $facts->getDatabaseUserName(), - 'DB_PASSWORD' => $facts->getDatabasePassword(), - 'DB_HOST' => $facts->getDatabaseHost(), - 'DB_PORT' => $facts->getDatabasePort(), - 'MODULE_DUMP_PATH' => $this->getModuleTestDataDumpFilePath(), - 'MYSQL_CONFIG_PATH' => $this->getMysqlConfigPath(), - 'PHP_BIN' => $php, + '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 getModuleTestDataDumpFilePath() + private function getSourceRelativePackagePath(): string { - return Path::join(__DIR__, '..', 'Support', 'Data', 'dump.sql'); + return(str_replace($this->getProjectRoot(), '..', __DIR__) . '/../../../'); } - private function getMysqlConfigPath() + private function getCodeceptionSpecificFixtureFilePath(): string { - $facts = new Facts(); - $configFile = new ConfigFile($facts->getSourcePath() . '/config.inc.php'); + return Path::join(__DIR__, '../Support/Data', 'dump.sql'); + } - $generator = new DatabaseDefaultsFileGenerator($configFile); + private function getTestDataDumpFilePath(): string + { + return Path::join( + $this->getShopTestPath(), + '/Codeception/Support/_generated/shop-dump.sql' + ); + } - return $generator->generate(); + 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(); + } +} diff --git a/tests/Integration/EnterpriseTestCase.php b/tests/Integration/EnterpriseTestCase.php index 3b91a20e..e80975c7 100644 --- a/tests/Integration/EnterpriseTestCase.php +++ b/tests/Integration/EnterpriseTestCase.php @@ -18,7 +18,6 @@ public function setUp(): void { if (!(new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise)) { $this->markTestSkipped('Skip EE related tests for CE/PE edition'); - return; } diff --git a/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php b/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php index 18b2aa0c..17988fbc 100644 --- a/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php +++ b/tests/Integration/Framework/GraphQLQueryHandlerFileUploadTest.php @@ -9,6 +9,7 @@ namespace OxidEsales\GraphQL\Base\Tests\Integration\Framework; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\BootstrapContainerFactory; use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Dao\ProjectYamlDao; use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ProjectYamlImportService; @@ -34,6 +35,8 @@ public static function tearDownAfterClass(): void public function testFileUpload(): void { + ContainerFactory::resetContainer(); + $expected = file_get_contents(self::UPLOAD_FILE); $result = $this->uploadFile(self::UPLOAD_FILE, $this->getMutationData()); diff --git a/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php b/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php index 7f205890..b063816f 100644 --- a/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php +++ b/tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php @@ -12,16 +12,16 @@ use DateTime; use DateTimeImmutable; use Doctrine\DBAL\Connection; -use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface; use OxidEsales\GraphQL\Base\DataType\UserInterface; use OxidEsales\GraphQL\Base\Exception\InvalidRefreshToken; use OxidEsales\GraphQL\Base\Infrastructure\RefreshTokenRepository; use OxidEsales\GraphQL\Base\Infrastructure\RefreshTokenRepositoryInterface; -use OxidEsales\GraphQL\Base\Tests\Integration\TestCase; +use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(RefreshTokenRepository::class)] -class RefreshTokenRepositoryTest extends TestCase +class RefreshTokenRepositoryTest extends IntegrationTestCase { public function testGetNewRefreshTokenGivesCorrectlyFilledDataType(): void { @@ -172,14 +172,14 @@ public function testInvalidateRefreshTokensWrongUserId(): void $this->assertTrue($sut->getTokenUser($token) instanceof UserInterface); } - private function getDbConnection(): Connection + public function getSut(): RefreshTokenRepositoryInterface { - return $this->get(ConnectionProviderInterface::class)->get(); + return $this->get(RefreshTokenRepositoryInterface::class); } - public function getSut(): RefreshTokenRepositoryInterface + public function getDbConnection(): Connection { - return $this->get(RefreshTokenRepositoryInterface::class); + return $this->get(ConnectionFactoryInterface::class)->create(); } private function checkRefreshTokenWithIdExists(string $oxid): bool diff --git a/tests/Integration/Infrastructure/TokenTest.php b/tests/Integration/Infrastructure/TokenTest.php index ffce3513..523544b3 100644 --- a/tests/Integration/Infrastructure/TokenTest.php +++ b/tests/Integration/Infrastructure/TokenTest.php @@ -13,7 +13,8 @@ use Lcobucci\JWT\Token\DataSet; use Lcobucci\JWT\UnencryptedToken; use OxidEsales\Eshop\Application\Model\User; -use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; +use OxidEsales\EshopCommunity\Core\Di\ContainerFacade; +use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionFactoryInterface; use OxidEsales\EshopCommunity\Tests\TestContainerFactory; use OxidEsales\GraphQL\Base\DataType\Token as TokenDataType; use OxidEsales\GraphQL\Base\DataType\User as UserDataType; @@ -21,8 +22,10 @@ use OxidEsales\GraphQL\Base\Infrastructure\Token as TokenInfrastructure; use OxidEsales\GraphQL\Base\Service\Token; use OxidEsales\GraphQL\Base\Service\Token as TokenService; +use OxidEsales\EshopCommunity\Tests\ContainerTrait; +use PHPUnit\Framework\TestCase; -class TokenTest extends IntegrationTestCase +class TokenTest extends TestCase { private const TEST_TOKEN_ID = '_my_test_token'; @@ -31,15 +34,33 @@ class TokenTest extends IntegrationTestCase /** @var TokenInfrastructure */ private $tokenInfrastructure; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $containerFactory = new TestContainerFactory(); $container = $containerFactory->create(); + + $container->setParameter( + 'oxid_esales.db.replicate', + false + ); + $container->setParameter( + 'oxid_esales.db.replicas', + [] + ); + $container->compile(); $this->tokenInfrastructure = $container->get(TokenInfrastructure::class); } + protected function tearDown(): void + { + $this->cleanUp(); + + parent::tearDown(); + } + + public function testRegisterToken(): void { $this->tokenInfrastructure->registerToken( @@ -311,7 +332,7 @@ public function testUserHasToken(): void public function testInvalidateTokenAfterDeleteUser(): void { $userModel = oxNew(User::class); - $userModel->setId('_testUser'); + $userModel->setId(self::TEST_USER_ID); $userModel->setPassword('_testPassword'); $userModel->assign(['oxusername' => '_testUsername']); $userModel->save(); @@ -379,4 +400,13 @@ private function getTokenMock( return $token; } + + private function cleanUp(): void + { + ContainerFacade::get(ConnectionFactoryInterface::class) + ->create() + ->executeQuery( + 'truncate table `oegraphqltoken`' + ); + } } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 375c3643..1e4d404f 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -8,6 +8,7 @@ displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" + processIsolation="true" >