diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index 5b670ce664..c8f389bd4b 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -447,7 +447,7 @@ class Util public static function getClassName($filePath) { $className = preg_replace('/\.php$/i', '', $filePath); - $className = preg_replace('/^(application|custom)\//i', '', $className); + $className = preg_replace('/^(application|custom)(\/|\\\)/i', '', $className); $className = '\\'.static::toFormat($className, '\\'); return $className; diff --git a/tests/unit/Espo/Core/Utils/UtilTest.php b/tests/unit/Espo/Core/Utils/UtilTest.php index 45a9b05dcc..6ff40da1b0 100644 --- a/tests/unit/Espo/Core/Utils/UtilTest.php +++ b/tests/unit/Espo/Core/Utils/UtilTest.php @@ -1150,15 +1150,28 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals($testResult, Util::replaceInArray('{0}', 'DONE', $testArray, true)); } - - public function testGetClassName() + /** + * @dataProvider dp_classNames + */ + public function testGetClassName($path, $expectedClassName = '\Espo\EntryPoints\Donwload') { - $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('application/Espo/EntryPoints/Donwload.php')); + $this->assertEquals($expectedClassName, Util::getClassName($path)); $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('custom/Espo/EntryPoints/Donwload.php')); $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('Espo/EntryPoints/Donwload.php')); $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('application/Espo/EntryPoints/Donwload')); } + public function dp_classNames() + { + return [ + "application/Espo/EntryPoints/Donwload.php" => ['application/Espo/EntryPoints/Donwload.php'], + "custom/Espo/EntryPoints/Donwload.php" => ['custom/Espo/EntryPoints/Donwload.php'], + "Espo/EntryPoints/Donwload.php" => ['Espo/EntryPoints/Donwload.php'], + "application/Espo/EntryPoints/Donwload" => ['application/Espo/EntryPoints/Donwload'], + "\application\Espo\EntryPoints\Donwload" => ['application\Espo\EntryPoints\Donwload'], + ]; + } + public function testUnsetInArrayNotSingle() { $input = array(