Skip to content

Commit

Permalink
OXDEV-46 Clean up & small refactorings for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbbbauer committed Sep 28, 2017
1 parent 90c7fd0 commit f314120
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
8 changes: 2 additions & 6 deletions library/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,8 @@ protected function assertViewNotExists($tableName)

protected function existsView($tableName)
{
$generator = oxNew(\OxidEsales\Eshop\Core\TableViewNameGenerator::class);
$tableNameView = $generator->getViewName($tableName, 0);
$sql = "SHOW TABLES LIKE '$tableNameView'";

$results = DatabaseProvider::getDb()->getAll($sql);
$databaseHelper = new oxDatabaseHelper(DatabaseProvider::getDb());

return $tableNameView === $results[0][0];
return $databaseHelper->existsView($tableName);
}
}
12 changes: 12 additions & 0 deletions library/helpers/oxDatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* @copyright (C) OXID eSales AG 2003-2017
*/

use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\EshopCommunity\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\TestingLibrary\Services\Library\DatabaseHandler;

class oxDatabaseHelper
{
Expand Down Expand Up @@ -88,4 +90,14 @@ public function adjustTemplateBlocksOxModuleColumn()

$this->database->execute($sql);
}

public function getDataBaseTables()
{
$shopConfigFile = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\ConfigFile::class);
$databaseHandler = new DatabaseHandler($shopConfigFile);

$sql = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . $databaseHandler->getDbName() . "'";

return DatabaseProvider::getDb()->getAll($sql);
}
}
51 changes: 37 additions & 14 deletions tests/Integration/Services/ShopInstaller/ShopInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@

class ShopInstallerTest extends \OxidEsales\TestingLibrary\UnitTestCase
{
public function testShopInstaller()
const DEFAULT_OXMODULE_COLUMN_MAX_LENGTH = 32;
const CHANGED_OXMODULE_COLUMN_MAX_LENGTH = 100;

public function testShopInstallerCallsMigrationsAndRegeneratesViews()
{
$this->checkBeforeInstall();

// to be able to assert afterwards, that the views generation was called, we delete one view here
$this->dropOxDiscountView();
$this->assertViewNotExists('oxdiscount');

try {
$serviceCaller = new ServiceCaller(new TestConfig());
Expand All @@ -46,27 +49,28 @@ public function testShopInstaller()
$this->checkAfterInstall();
}

/**
* To be able to assure, that the ShopInstall service call worked correct, we check before, if everything is well.
*/
protected function checkBeforeInstall()
{
$shopConfig = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\ConfigFile::class);
$dbHandler = new DatabaseHandler($shopConfig);

$databaseHelper = new oxDatabaseHelper(DatabaseProvider::getDb());
$databaseHelper->adjustTemplateBlocksOxModuleColumn();

$sql = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . $dbHandler->getDbName() . "'";
$result = DatabaseProvider::getDb()->getOne($sql);

$this->assertNotEmpty($result);

$this->assertOxModuleColumnHasMaxLength(32);
$this->assertViewExists('oxdiscount');
$this->assertThereExistsAtLeastOneDatabaseTable();
$this->assertOxModuleColumnHasMaxLength(self::DEFAULT_OXMODULE_COLUMN_MAX_LENGTH);
$this->assureGenerateViewsWasCalled();
}

/**
* To assure, that the ShopInstall service call worked correct, we check, that
* - the views are regenerated
* - the migrations where called
*/
protected function checkAfterInstall()
{
$this->assertOxModuleColumnHasMaxLength(100);
$this->assertViewExists('oxdiscount');
$this->assureMigrationWasCalled();
$this->assureGenerateViewsWasCalled();
}

/**
Expand All @@ -86,5 +90,24 @@ protected function dropOxDiscountView()
$databaseHelper = new oxDatabaseHelper(DatabaseProvider::getDb());

$databaseHelper->dropView('oxdiscount');

$this->assertViewNotExists('oxdiscount');
}

private function assureMigrationWasCalled(): void
{
$this->assertOxModuleColumnHasMaxLength(self::CHANGED_OXMODULE_COLUMN_MAX_LENGTH);
}

protected function assureGenerateViewsWasCalled(): void
{
$this->assertViewExists('oxdiscount');
}

protected function assertThereExistsAtLeastOneDatabaseTable()
{
$databaseHelper = new oxDatabaseHelper(DatabaseProvider::getDb());

$this->assertNotEmpty($databaseHelper->getDataBaseTables());
}
}

0 comments on commit f314120

Please sign in to comment.