Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix generate index
  • Loading branch information
jocel1 committed Jun 29, 2018
1 parent 104200f commit fb33f82
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
9 changes: 9 additions & 0 deletions classes/PrestaShopAutoload.php
Expand Up @@ -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(
Expand Down
6 changes: 0 additions & 6 deletions classes/Tools.php
Expand Up @@ -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();
}

Expand Down
31 changes: 31 additions & 0 deletions tests/Unit/Classes/PrestaShopAutoloadTest.php
Expand Up @@ -28,6 +28,7 @@

use PHPUnit\Framework\TestCase;
use PrestaShopAutoload;
use Configuration;

class PrestaShopAutoloadTest extends TestCase
{
Expand Down Expand Up @@ -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',
'<?php
class Connection extends ConnectionCore {
}');
PrestaShopAutoload::getInstance()->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');
}
}

0 comments on commit fb33f82

Please sign in to comment.