Skip to content

Commit

Permalink
OXDEV-7248 Update module to work with shop 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Jan 22, 2025
1 parent 4715833 commit 39c5a1d
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 42 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-v10.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](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
Expand Down
2 changes: 2 additions & 0 deletions tests/Codeception/Acceptance.suite.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# suite config
actor: AcceptanceTester
path: Acceptance
bootstrap: _bootstrap.php

modules:
enabled:
- Asserts
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,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');
151 changes: 122 additions & 29 deletions tests/Codeception/Config/CodeceptionParametersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
1 change: 0 additions & 1 deletion tests/Integration/EnterpriseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());

Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/Infrastructure/RefreshTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
38 changes: 34 additions & 4 deletions tests/Integration/Infrastructure/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
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;
use OxidEsales\GraphQL\Base\Infrastructure\Model\Token as TokenModel;
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';

Expand All @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -379,4 +400,13 @@ private function getTokenMock(

return $token;
}

private function cleanUp(): void
{
ContainerFacade::get(ConnectionFactoryInterface::class)
->create()
->executeQuery(
'truncate table `oegraphqltoken`'
);
}
}
1 change: 1 addition & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
processIsolation="true"
>
<testsuites>
<testsuite name="Unit">
Expand Down

0 comments on commit 39c5a1d

Please sign in to comment.