From fb33f82cbfd57a76f50f2d05f5c9b7cb3c39bc74 Mon Sep 17 00:00:00 2001 From: jocelyn fournier Date: Fri, 29 Jun 2018 11:49:53 +0200 Subject: [PATCH] fix generate index --- classes/PrestaShopAutoload.php | 9 ++++++ classes/Tools.php | 6 ---- tests/Unit/Classes/PrestaShopAutoloadTest.php | 31 +++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/classes/PrestaShopAutoload.php b/classes/PrestaShopAutoload.php index 6f0d779888c45..dc540e9ed53bc 100644 --- a/classes/PrestaShopAutoload.php +++ b/classes/PrestaShopAutoload.php @@ -166,6 +166,15 @@ public function load($className) */ public function generateIndex() { + if (defined('_PS_CREATION_DATE_')) { + $creationDate = _PS_CREATION_DATE_; + if (!empty($creationDate) && Configuration::get('PS_DISABLE_OVERRIDES')) { + $this->_include_override_path = false; + } else { + $this->_include_override_path = true; + } + } + $coreClasses = $this->getClassesFromDir('classes/'); $classes = array_merge( diff --git a/classes/Tools.php b/classes/Tools.php index e9c9cb72bdc79..b6912b5d90da7 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -2656,12 +2656,6 @@ public static function getRobotsContent() public static function generateIndex() { - if (defined('_PS_CREATION_DATE_')) { - $creationDate = _PS_CREATION_DATE_; - if (!empty($creationDate) && Configuration::get('PS_DISABLE_OVERRIDES')) { - PrestaShopAutoload::getInstance()->_include_override_path = false; - } - } PrestaShopAutoload::getInstance()->generateIndex(); } diff --git a/tests/Unit/Classes/PrestaShopAutoloadTest.php b/tests/Unit/Classes/PrestaShopAutoloadTest.php index 194ad0942175e..b81f3c2dcdf45 100644 --- a/tests/Unit/Classes/PrestaShopAutoloadTest.php +++ b/tests/Unit/Classes/PrestaShopAutoloadTest.php @@ -28,6 +28,7 @@ use PHPUnit\Framework\TestCase; use PrestaShopAutoload; +use Configuration; class PrestaShopAutoloadTest extends TestCase { @@ -55,10 +56,40 @@ public function testLoad() $this->assertTrue(class_exists('RequestSql', false)); } + /** + * Given PS_DISABLE_OVERRIDES is enabled + * When the class index is regenerated and we have override + * Then the override shouldn't be include in the class index + */ + public function testGenerateIndexWithoutOverride() + { + Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', 1); + @mkdir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'override/classes/', 0777, true); + define('_PS_HOST_MODE_', 1); + file_put_contents(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'override/classes/Connection.php', + 'generateIndex(); + $this->assertTrue(file_exists($this->file_index)); + $data = include($this->file_index); + $this->assertEquals($data['OrderControllerCore']['path'], 'controllers/front/OrderController.php'); + $this->assertEquals($data['Connection']['override'], false); + Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', 0); + PrestaShopAutoload::getInstance()->generateIndex(); + $data = include($this->file_index); + $this->assertEquals($data['Connection']['override'], true); + } + public function testClassFromCoreDirShouldntBeLoaded() { PrestaShopAutoload::getInstance()->load('\\PrestaShop\\PrestaShop\\Core\\Payment\\PaymentOption'); $this->assertFalse(class_exists('\\PrestaShop\\PrestaShop\\Core\\Payment\\PaymentOption', false)); } + + public static function tearDownAfterClass() + { + @unlink(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'override/classes/Connection.php'); + } }