diff --git a/tests/integration/Core/BaseTestCase.php b/tests/integration/Core/BaseTestCase.php index b08737481c..7c40aa5d61 100644 --- a/tests/integration/Core/BaseTestCase.php +++ b/tests/integration/Core/BaseTestCase.php @@ -63,13 +63,9 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase */ protected $password = null; - protected function createApplication($userName = null, $password = null) + protected function createApplication($userName = null, $password = null, $clearCache = true) { - if (isset($userName) && isset($password)) { - return $this->espoTester->getApplication(true, $userName, $password); - } - - return $this->espoTester->getApplication(true); + return $this->espoTester->getApplication(true, $userName, $password, $clearCache); } /** @@ -102,7 +98,10 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase $this->espoTester = new Tester($params); $this->espoTester->initialize(); + + $this->beforeStartApplication(); $this->espoApplication = $this->createApplication($this->userName, $this->password); + $this->afterStartApplication(); } protected function tearDown() @@ -111,4 +110,14 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase $this->espoTester = NULL; $this->espoApplication = NULL; } + + protected function beforeStartApplication() + { + + } + + protected function afterStartApplication() + { + + } } diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.php index 8bdcfdd72d..5b880ade30 100644 --- a/tests/integration/Core/Tester.php +++ b/tests/integration/Core/Tester.php @@ -39,6 +39,8 @@ class Tester protected $testDataPath = 'tests/integration/testData'; + protected $defaultUserPassword = '1'; + private $application; private $dataLoader; @@ -75,13 +77,19 @@ class Tester return $returns; } - public function getApplication($reload = false, $userName = null, $password = null) + public function getApplication($reload = false, $userName = null, $password = null, $clearCache = true) { if (!isset($this->application) || $reload) { + + if ($clearCache) { + $this->clearCache(); + } + $this->application = new \Espo\Core\Application(); $auth = new \Espo\Core\Utils\Auth($this->application->getContainer()); - if (isset($userName) && isset($password)) { + if (isset($userName)) { + $password = isset($password) ? $password : $this->defaultUserPassword; $auth->login($userName, $password); } else { $auth->useNoAuth(); @@ -155,4 +163,11 @@ class Tester $this->getDataLoader()->loadFiles($this->params['pathToFiles']); } } + + public function clearCache() + { + $fileManager = new \Espo\Core\Utils\File\Manager(); + + return $fileManager->removeInDir('data/cache'); + } } \ No newline at end of file