diff --git a/CommonLogic/Contexts/Scopes/SessionContextScope.php b/CommonLogic/Contexts/Scopes/SessionContextScope.php index e4b44ba36..169e01030 100644 --- a/CommonLogic/Contexts/Scopes/SessionContextScope.php +++ b/CommonLogic/Contexts/Scopes/SessionContextScope.php @@ -219,12 +219,10 @@ protected function sessionClose() */ protected function sessionIsOpen() { - if (php_sapi_name() !== 'cli') { - if (version_compare(phpversion(), '5.4.0', '>=')) { - return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE; - } else { - return session_id() === '' ? FALSE : TRUE; - } + if (version_compare(phpversion(), '5.4.0', '>=')) { + return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE; + } else { + return session_id() === '' ? FALSE : TRUE; } return FALSE; } @@ -236,7 +234,11 @@ protected function sessionIsOpen() */ protected function getSessionContextData() { - return $_SESSION['exface']['contexts']; + if (isset($_SESSION['exface']) && isset($_SESSION['exface']['contexts'])) { + return $_SESSION['exface']['contexts']; + } else { + return null; + } } /** @@ -259,7 +261,12 @@ protected function setSessionContextData($key, $value) */ protected function getSessionData(string $key) { - return $_SESSION['exface'][$key]; + + if (isset($_SESSION['exface']) && isset($_SESSION['exface'][$key])) { + return $_SESSION['exface'][$key]; + } else { + return null; + } } /** diff --git a/CommonLogic/Filemanager.php b/CommonLogic/Filemanager.php index bfb34e3fe..842292925 100644 --- a/CommonLogic/Filemanager.php +++ b/CommonLogic/Filemanager.php @@ -33,6 +33,8 @@ class Filemanager extends Filesystem implements WorkbenchDependantInterface private $path_to_config_folder = null; + private $path_to_translations_folder = null; + private $path_to_user_data_folder = null; private $path_to_backup_folder = null; diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 000000000..4d7027a97 --- /dev/null +++ b/codeception.yml @@ -0,0 +1,12 @@ +paths: + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs +actor_suffix: Tester +extensions: + enabled: + - Codeception\Extension\RunFailed +settings: + bootstrap: _bootstrap.php diff --git a/composer.json b/composer.json index 81577e38b..e4db5e0ff 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,9 @@ "kabachello/fileroute": "~0.2", "guzzlehttp/guzzle": "^6.2.2" }, + "require-dev": { + "codeception/codeception": "^2.3" + }, "suggest": { "npm-asset/workbox-sw": "Allows templates to use the tools from the AbstractServiceWorkerTemplate" }, diff --git a/tests/_data/.gitkeep b/tests/_data/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/_output/.gitignore b/tests/_output/.gitignore new file mode 100644 index 000000000..c96a04f00 --- /dev/null +++ b/tests/_output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php new file mode 100644 index 000000000..4c7dcbb6d --- /dev/null +++ b/tests/_support/AcceptanceTester.php @@ -0,0 +1,26 @@ +date = new Date(new FormulaSelector($exface, 'exface.Core.Date')); + } + + protected function _after() + { + $this->date = null; + } + + public function testFormatDate() + { + $formattedDate = $this->date->formatDate(self::TEST_DATE, self::TEST_FORMAT); + $this->assertEquals('11.01.2018', $formattedDate); + } + + public function testFormatDateFromEmptyFormat() + { + $formattedDate = $this->date->formatDate(self::TEST_DATE, ''); + $this->assertEquals('11.01.2018', $formattedDate); + + $formattedDate = $this->date->formatDate(self::TEST_DATE, null); + $this->assertEquals('11.01.2018', $formattedDate); + } + + public function testFormatDateFromEmptyDate() + { + $formattedDate = $this->date->formatDate('', self::TEST_FORMAT); + $this->assertEquals((new DateTime())->format(self::TEST_FORMAT), $formattedDate); + + $formattedDate = $this->date->formatDate(null, self::TEST_FORMAT); + $this->assertEquals((new DateTime())->format(self::TEST_FORMAT), $formattedDate); + } + + public function testFormatDateFromInvalidDate() + { + $formattedDate = $this->date->formatDate('2018-13-12', self::TEST_FORMAT); + $this->assertEquals('2018-13-12', $formattedDate); + } + + public function testRun() + { + $formattedDate = $this->date->run(self::TEST_DATE, self::TEST_FORMAT); + $this->assertEquals('11.01.2018', $formattedDate); + } +} \ No newline at end of file diff --git a/tests/unit/_bootstrap.php b/tests/unit/_bootstrap.php new file mode 100644 index 000000000..975858741 --- /dev/null +++ b/tests/unit/_bootstrap.php @@ -0,0 +1,7 @@ +start(); +}