From e3aa0a40fe29adcf71996405c212836c8d9a9024 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Wed, 8 Oct 2014 12:12:53 +0300 Subject: [PATCH] tests improvements --- .gitignore | 3 +-- tests/Espo/Core/Utils/ConfigTest.php | 9 ++++++- tests/Espo/Core/Utils/LanguageTest.php | 24 ++++++++++++------- .../Utils/Config/{cache => }/config.php | 0 4 files changed, 25 insertions(+), 11 deletions(-) rename tests/testData/Utils/Config/{cache => }/config.php (100%) diff --git a/.gitignore b/.gitignore index 844d3378f2..deefd2c21a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ /client /test.php /main.html -/tests/testData/Utils/Config/config.php -/tests/testData/*/cache/* +/tests/testData/cache/* composer.phar vendor/ diff --git a/tests/Espo/Core/Utils/ConfigTest.php b/tests/Espo/Core/Utils/ConfigTest.php index cf306e07dc..bda1831b5d 100644 --- a/tests/Espo/Core/Utils/ConfigTest.php +++ b/tests/Espo/Core/Utils/ConfigTest.php @@ -11,7 +11,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase protected $objects; - protected $configPath = 'tests/testData/Utils/Config/cache/config.php'; + protected $defaultTestConfig = 'tests/testData/Utils/Config/config.php'; + + protected $configPath = 'tests/testData/cache/config.php'; protected $systemConfigPath = 'tests/testData/Utils/Config/systemConfig.php'; @@ -19,6 +21,11 @@ class ConfigTest extends \PHPUnit_Framework_TestCase { $this->objects['fileManager'] = new \Espo\Core\Utils\File\Manager(); + /*copy defaultTestConfig file to cache*/ + if (!file_exists($this->configPath)) { + copy($this->defaultTestConfig, $this->configPath); + } + $this->object = new \Espo\Core\Utils\Config($this->objects['fileManager']); $this->reflection = new ReflectionHelper($this->object); diff --git a/tests/Espo/Core/Utils/LanguageTest.php b/tests/Espo/Core/Utils/LanguageTest.php index 0e6018e01c..5f6ca4346e 100644 --- a/tests/Espo/Core/Utils/LanguageTest.php +++ b/tests/Espo/Core/Utils/LanguageTest.php @@ -13,6 +13,14 @@ class LanguageTest extends \PHPUnit_Framework_TestCase protected $reflection; + protected $cacheFile = 'tests/testData/cache/application/languages/{*}.php'; + + protected $paths = array( + 'corePath' => 'tests/testData/Utils/I18n/Espo/Resources/i18n', + 'modulePath' => 'tests/testData/Utils/I18n/Espo/Modules/{*}/Resources/i18n', + 'customPath' => 'tests/testData/Utils/I18n/Espo/Custom/Resources/i18n', + ); + protected function setUp() { $this->objects['fileManager'] = new \Espo\Core\Utils\File\Manager(); @@ -30,12 +38,8 @@ class LanguageTest extends \PHPUnit_Framework_TestCase $this->object = new \Espo\Core\Utils\Language($this->objects['fileManager'], $this->objects['config'], $this->objects['preferences']); $this->reflection = new ReflectionHelper($this->object); - $this->reflection->setProperty('cacheFile', 'tests/testData/Utils/I18n/cache/application/languages/{*}.php'); - $this->reflection->setProperty('paths', array( - 'corePath' => 'tests/testData/Utils/I18n/Espo/Resources/i18n', - 'modulePath' => 'tests/testData/Utils/I18n/Espo/Modules/{*}/Resources/i18n', - 'customPath' => 'tests/testData/Utils/I18n/Espo/Custom/Resources/i18n', - ) ); + $this->reflection->setProperty('cacheFile', $this->cacheFile); + $this->reflection->setProperty('paths', $this->paths); $this->reflection->setProperty('currentLanguage', 'en_US'); } @@ -59,11 +63,15 @@ class LanguageTest extends \PHPUnit_Framework_TestCase public function testGetLangCacheFile() { - $this->assertEquals('tests/testData/Utils/I18n/cache/application/languages/en_US.php', $this->reflection->invokeMethod('getLangCacheFile', array()) ); + $cacheFile = $this->cacheFile; + + $result = str_replace('{*}', 'en_US', $cacheFile); + $this->assertEquals($result, $this->reflection->invokeMethod('getLangCacheFile')); $originalLang = $this->object->getLanguage(); $this->object->setLanguage('lang_TEST'); - $this->assertEquals('tests/testData/Utils/I18n/cache/application/languages/lang_TEST.php', $this->reflection->invokeMethod('getLangCacheFile', array()) ); + $result = str_replace('{*}', 'lang_TEST', $cacheFile); + $this->assertEquals($result, $this->reflection->invokeMethod('getLangCacheFile')); $this->object->setLanguage($originalLang); } diff --git a/tests/testData/Utils/Config/cache/config.php b/tests/testData/Utils/Config/config.php similarity index 100% rename from tests/testData/Utils/Config/cache/config.php rename to tests/testData/Utils/Config/config.php