Skip to content

Commit

Permalink
Run with shop 8.0.x, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Dec 19, 2024
1 parent a6df45e commit 8f753dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 55 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"php": "^8.2",
"doctrine/dbal": "^v2.7",
"oxid-esales/graphql-base": "dev-b-8.0.x-compatibility-OXDEV-7248"
"oxid-esales/graphql-base": "dev-b-8.0.x-compatibility-OXDEV-7248 | dev-b-8.0.x-with-facts-OXDEV-7248"
},
"conflict": {
"oxid-esales/oxideshop-ce": "<7.2",
Expand Down
83 changes: 34 additions & 49 deletions tests/Codeception/Acceptance/MultishopBaseCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@

use Codeception\Scenario;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Model\ListModel;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Edition\Edition;
use OxidEsales\EshopCommunity\Internal\Framework\Edition\EditionDirectoriesLocator;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectDirectoriesLocator;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface;
use OxidEsales\EshopEnterprise\Application\Controller\Admin\ShopMain;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\EshopEnterprise\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationGeneratorBridgeInterface;
use OxidEsales\GraphQL\Storefront\Tests\Codeception\AcceptanceTester;
use Psr\Container\ContainerInterface;
use OxidEsales\EshopEnterprise\Application\Controller\Admin\ShopMain;

abstract class MultishopBaseCest extends BaseCest
{
protected const SUBSHOP_ID = 2;

public function _before(AcceptanceTester $I, Scenario $scenario): void
{
if (!(new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise)){
if (ContainerFacade::get(BasicContextInterface::class)->getEdition() !== Edition::Enterprise){
$scenario->skip('Skip EE related tests for CE/PE edition');

return;
Expand All @@ -48,30 +47,39 @@ public function _after(AcceptanceTester $I): void
{
parent::_after($I);

if ((new EditionDirectoriesLocator())->getEditionRootPath(Edition::Enterprise)){
if (ContainerFacade::get(BasicContextInterface::class)->getEdition() === Edition::Enterprise){
$I->updateInDatabase('oxconfig', ['oxvarvalue' => false], ['oxvarname' => 'blMallUsers']);
}
}

private function ensureSubshop(): void
{
$container = ContainerFactory::getInstance()->getContainer();
$shopConfiguration = $container->get(ShopConfigurationDaoBridgeInterface::class)->get();
Registry::getConfig()->setShopId(self::SUBSHOP_ID);
$container->get(ShopConfigurationDaoBridgeInterface::class)->save($shopConfiguration);
$container->get(ShopConfigurationGeneratorBridgeInterface::class)->generateForShop(self::SUBSHOP_ID);
ContainerFacade::get(ShopConfigurationGeneratorBridgeInterface::class)
->generateForShop(self::SUBSHOP_ID);

$shop = oxNew(Shop::class);
$shop->load(1);
$shop->assign(
[
'oxid' => self::SUBSHOP_ID
]
['oxid' => self::SUBSHOP_ID]
);
$shop->save();

#$this->copyConfig();
$this->copyContent();
$shopMain = oxNew(ShopMain::class);
$copyConfigVars = (new \ReflectionClass($shopMain))->getMethod('copyConfigVars');
$copyConfigVars->setAccessible(true);
$copyConfigVars->invokeArgs($shopMain, [$shop]);

$container = ContainerFactory::getInstance()->getContainer();
$shopConfiguration = $container->get(ShopConfigurationDaoBridgeInterface::class)->get();

Registry::getConfig()->setShopId(self::SUBSHOP_ID);
$container->get(ShopConfigurationDaoBridgeInterface::class)->save($shopConfiguration);





# $this->copyContent();
$this->regenerateDatabaseViews();
$this->activateModule($container);

Expand All @@ -80,7 +88,8 @@ private function ensureSubshop(): void

private function regenerateDatabaseViews(): void
{
exec((new ProjectDirectoriesLocator())->getVendorPath() . '/bin/oe-eshop-db_views_generate');
$vendorPath = (new ProjectDirectoriesLocator())->getVendorPath();
exec($vendorPath . '/bin/oe-eshop-db_views_generate');
}

private function activateModule(ContainerInterface $container)
Expand All @@ -96,44 +105,20 @@ private function activateModule(ContainerInterface $container)
private function copyContent()
{
//copy contents
$shopContentList = oxNew(ListModel::class);
$shopContentList = oxNew(\OxidEsales\Eshop\Core\Model\ListModel::class);
$shopContentList->init("oxi18n", 'oxcontents');
$shopContentList->getBaseObject()->setEnableMultilang(false);

$shopContentList->selectString("select * from oxcontents where oxshopid = '1'");
foreach ($shopContentList as $shopContent) {
$shopContent->oxcontents__oxshopid->setValue(self::SUBSHOP_ID);
$shopContent->setId();
$shopContent->save();
}
}

private function copyConfig(): void
{
$utilsObject = Registry::getUtilsObject();
$db = DatabaseProvider::getDb();

$selectShopConfigurationQuery =
"select oxvarname, oxvartype, oxvarvalue, oxmodule
from oxconfig where oxshopid = '1'";

$shopConfiguration = $db->select($selectShopConfigurationQuery);
if ($shopConfiguration != false && $shopConfiguration->count() > 0) {
while (!$shopConfiguration->EOF) {
$newId = $utilsObject->generateUID();
$insertNewConfigQuery =
"insert into oxconfig (oxid, oxshopid, oxvarname, oxvartype, oxvarvalue, oxmodule)
values (:oxid, :oxshopid, :oxvarname, :oxvartype, :value, :oxmodule)";
$db->execute($insertNewConfigQuery, [
':oxid' => $newId,
':oxshopid' => self::SUBSHOP_ID,
':oxvarname' => $shopConfiguration->fields[0],
':oxvartype' => $shopConfiguration->fields[1],
':value' => $shopConfiguration->fields[2],
':oxmodule' => $shopConfiguration->fields[3],
]);
try {
$shopContent->oxcontents__oxshopid->setValue(self::SUBSHOP_ID);
$shopContent->delete();
$shopContent->setId();
$shopContent->save();
} catch (DatabaseErrorException $e) {
// This happen on executing multiple tests
}
$shopConfiguration->fetchRow();
}
}
}
2 changes: 1 addition & 1 deletion tests/Codeception/Config/CodeceptionParametersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function getSourceRelativePackagePath(): string

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

private function getTestDataDumpFilePath(): string
Expand Down
2 changes: 1 addition & 1 deletion tests/Codeception/Config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

declare(strict_types=1);

namespace OxidEsales\Graphql\Base\Tests\Codeception\Config;
namespace OxidEsales\Graphql\Storefront\Tests\Codeception\Config;

return (new CodeceptionParametersProvider())->getParameters();
6 changes: 3 additions & 3 deletions tests/Integration/Controller/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace OxidEsales\GraphQL\Storefront\Tests\Integration\Controller;

use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\Facts\Facts;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\GraphQL\Storefront\Tests\Integration\BaseTestCase;

final class ContentTest extends BaseTestCase
Expand Down Expand Up @@ -222,8 +223,7 @@ public function testGetContentListWithExactFilter(): void
$expectedCount = 25;

// Due to demodata for EE been different
$facts = new Facts();
if ($facts->getEdition() == 'EE') {
if (ContainerFacade::get(BasicContextInterface::class)->getEdition() == Edition::Enterprise){
$expectedCount = 24;
}

Expand Down

0 comments on commit 8f753dd

Please sign in to comment.