diff --git a/source/Application/Model/ShopViewValidator.php b/source/Application/Model/ShopViewValidator.php index d566ab2f39..d8d8775c42 100644 --- a/source/Application/Model/ShopViewValidator.php +++ b/source/Application/Model/ShopViewValidator.php @@ -158,7 +158,7 @@ public function getShopId() protected function _getAllViews() { if (empty($this->_aAllViews)) { - $this->_aAllViews = oxDb::getDb()->getCol("SHOW TABLES LIKE 'oxv_%'"); + $this->_aAllViews = oxDb::getDb()->getCol("SHOW TABLES LIKE 'oxv\_%'"); } return $this->_aAllViews; diff --git a/tests/Integration/Multilanguage/EscapeDropViewTest.php b/tests/Integration/Multilanguage/EscapeDropViewTest.php new file mode 100644 index 0000000000..1344851404 --- /dev/null +++ b/tests/Integration/Multilanguage/EscapeDropViewTest.php @@ -0,0 +1,131 @@ +. + * + * @link http://www.oxid-esales.com + * @copyright (C) OXID eSales AG 2003-2017 + * @version OXID eShop CE + */ +namespace OxidEsales\EshopCommunity\Tests\Integration\Multilanguage; + +use oxDb; +use OxidEsales\Eshop\Application\Model\Shop; +use OxidEsales\Eshop\Application\Model\ShopViewValidator; +use OxidEsales\Eshop\Core\DbMetaDataHandler; + +/** + * Regression tests for Shop class and ShopViewValidator class. + */ +class EscapeDropViewTest extends MultilanguageTestCase +{ + /** + * Testing Shop::_cleanInvalidViews(). + */ + public function testEscapeDropView() + { + $this->createView(); + + $sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME LIKE 'oxv_oxcountry_xx-2015'"; + $result = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getOne($sql); + $this->assertSame('oxv_oxcountry_xx-2015', $result); + + $shop = oxNew(Shop::class); + $shop->generateViews(); + + $sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME LIKE 'oxv_oxcountry_xx-2015'"; + $result = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getOne($sql); + $this->assertSame(false, $result); + } + + /** + * Testing ShopViewValidator::_getAllViews(). + */ + public function testShowViewTables() + { + $shopViewValidator = oxNew(ShopViewValidator::class); + + $invalidViews = $shopViewValidator->getInvalidViews(); + + $this->assertNotEmpty($invalidViews); + $this->assertNotContains('oxvouchers', $invalidViews); + } + + /** + * Create additional view. + * + * @param string $table + */ + protected function createView($table = 'oxcountry') + { + $langAddition = '_xx-2015'; + $queryStart = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW'; + $viewTable = "oxv_{$table}{$langAddition}"; + + $fields = $this->getViewSelectMultilang($table); + $join = $this->getViewJoinAll($table); + + $sql = "{$queryStart} `{$viewTable}` AS SELECT {$fields} FROM {$table}{$join}"; + + oxDb::getDb()->execute($sql); + } + + /** + * Returns all language table view JOIN section. + * + * @param string $table table name + * + * @return string + */ + protected function getViewJoinAll($table) + { + $join = ' '; + $metaData = oxNew(DbMetaDataHandler::class); + $tables = $metaData->getAllMultiTables($table); + if (count($tables)) { + foreach ($tables as $tableKey => $tableName) { + $join .= "LEFT JOIN {$tableName} USING (OXID) "; + } + } + + return $join; + } + + /** + * Returns table fields sql section for multiple language views. + * + * @param string $table table name + * + * @return string + */ + protected function getViewSelectMultilang($table) + { + $fields = array(); + + $metaData = oxNew(DbMetaDataHandler::class); + $tables = array_merge(array($table), $metaData->getAllMultiTables($table)); + foreach ($tables as $tableKey => $tableName) { + $tableFields = $metaData->getFields($tableName); + foreach ($tableFields as $coreField => $field) { + if (!isset($fields[$coreField])) { + $fields[$coreField] = $field; + } + } + } + + return implode(',', $fields); + } + +} diff --git a/tests/Integration/Multilanguage/MultilanguageTestCase.php b/tests/Integration/Multilanguage/MultilanguageTestCase.php index a441e3c555..cccdd4831d 100644 --- a/tests/Integration/Multilanguage/MultilanguageTestCase.php +++ b/tests/Integration/Multilanguage/MultilanguageTestCase.php @@ -19,7 +19,7 @@ * @copyright (C) OXID eSales AG 2003-2016 * @version OXID eShop CE */ -namespace Integration\Multilanguage; +namespace OxidEsales\EshopCommunity\Tests\Integration\Multilanguage; use oxRegistry;