Commit 239abcc7 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Add some unit tests

parent b9cd1516
Pipeline #4981 passed with stages
in 4 minutes and 3 seconds
......@@ -193,7 +193,7 @@ The following `escape` & `action` types are available:
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| S | Stop replace. If the replaced value contains nested variables, they won't be replaced. |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| t | Returns the central european timezone (CET / CEST) depending on the given date. If the TZ is not GMT+1 or GMT+2, returns GMT+x |
| t | Returns the central european timezone ``CET`` / ``CEST`` depending on the given date. If the TZ is not GMT+1 or 2, returns GMT+x |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| w | wipe out current key/value pair from SIP store :ref:`variable-escape-wipe-key<variable-escape-wipe-key>` |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
......
......@@ -272,7 +272,6 @@ class Evaluate {
public function getEuropeanTimezone($dateStr = '') {
$ts = ($dateStr == '') ? time() : strtotime($dateStr);
$offset = date("Z", $ts);
$offset = date("Z", $ts) / 3600;
switch ($offset) {
case 1:
......
......@@ -607,14 +607,31 @@ class EvaluateTest extends AbstractDatabaseTest {
* @throws \UserReportException
*/
public function testGetEuropeanTimezone() {
$eval = new Evaluate($this->store, $this->dbArray[DB_INDEX_DEFAULT]);
// It seems in phpunit there is no default time zone set - set it manually.
date_default_timezone_set('Europe/Berlin');
$this->assertEquals('CET', $eval->getEuropeanTimezone('02.02.2020'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('02.06.2020'));
$this->assertEquals('CET', $eval->getEuropeanTimezone('02.12.2020'));
# Check 2020 incl. hour
$this->assertEquals('CET', $eval->getEuropeanTimezone('29.03.2020 01:00'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('29.03.2020 03:00'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('25.10.2020 01:00'));
$this->assertEquals('CET', $eval->getEuropeanTimezone('25.10.2020 03:00'));
# Check 2021 incl. hour
$this->assertEquals('CET', $eval->getEuropeanTimezone('28.03.2021 01:00'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('28.03.2021 03:00'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('31.10.2021 01:00'));
$this->assertEquals('CET', $eval->getEuropeanTimezone('31.10.2021 03:00'));
# Check 2021 only date
$this->assertEquals('CET', $eval->getEuropeanTimezone('28.03.2021'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('29.03.2021'));
$this->assertContains($eval->getEuropeanTimezone(''), ['CET', 'CEST']);
# Check if action parameter 't' is recognized.
$this->store->setVar('start', '02.06.2020', STORE_FORM, true);
$this->assertEquals('CEST', $eval->substitute('start:F:all:t', $foundInStore));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment