Timezone fixes for php 8.1 (#490)
* Added simple test for TimeZoneHelper #461 * TimeZone offset: don't use float values for columns that could be array keys #461
This commit is contained in:
@ -41,6 +41,7 @@ There's a change in flash messages handling, please see #391
|
|||||||
- Enh: added `AdminController` REST controller (MatteoF96)
|
- Enh: added `AdminController` REST controller (MatteoF96)
|
||||||
- Enh: added method `setUser` for LoginForm model (liviuk2)
|
- Enh: added method `setUser` for LoginForm model (liviuk2)
|
||||||
- Enh: user model emailTrim validator only if not empty #486 (liviuk2)
|
- Enh: user model emailTrim validator only if not empty #486 (liviuk2)
|
||||||
|
- Fix #461: TimeZoneHelper: don't use floats for columns that could be array keys (maxxer)
|
||||||
|
|
||||||
## 1.5.1 April 5, 2020
|
## 1.5.1 April 5, 2020
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,8 @@ class TimezoneHelper
|
|||||||
$timeZones[] = [
|
$timeZones[] = [
|
||||||
'timezone' => $timeZone,
|
'timezone' => $timeZone,
|
||||||
'name' => "{$timeZone} (UTC " . ($offset > 0 ? '+' : '') . "{$offset})",
|
'name' => "{$timeZone} (UTC " . ($offset > 0 ? '+' : '') . "{$offset})",
|
||||||
'offset' => $offset,
|
// As of PHP 8.1 array keys cannot be float. Offset is used for sorting only
|
||||||
|
'offset' => $offset * 100,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
namespace Da\User\Validator;
|
namespace Da\User\Validator;
|
||||||
|
|
||||||
use Da\User\Contracts\ValidatorInterface;
|
use Da\User\Contracts\ValidatorInterface;
|
||||||
|
use DateTimeZone;
|
||||||
|
|
||||||
class TimeZoneValidator implements ValidatorInterface
|
class TimeZoneValidator implements ValidatorInterface
|
||||||
{
|
{
|
||||||
@ -24,6 +25,6 @@ class TimeZoneValidator implements ValidatorInterface
|
|||||||
|
|
||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
return in_array($this->timezone, timezone_identifiers_list(), false);
|
return in_array($this->timezone, DateTimeZone::listIdentifiers(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
tests/unit/TimeZoneTest.php
Normal file
26
tests/unit/TimeZoneTest.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Da\User\Helper\TimezoneHelper;
|
||||||
|
use Da\User\Validator\TimeZoneValidator;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing the Timezone generator functions
|
||||||
|
*/
|
||||||
|
class TimeZoneTest extends \Codeception\Test\Unit
|
||||||
|
{
|
||||||
|
// Basic test to check the function works
|
||||||
|
public function testTimezoneHelper()
|
||||||
|
{
|
||||||
|
$alltz = (new TimezoneHelper)->getAll();
|
||||||
|
$this->assertTrue(in_array("Europe/Rome", ArrayHelper::getColumn($alltz, "timezone")));
|
||||||
|
$this->assertTrue(in_array("0100", ArrayHelper::getColumn($alltz, "offset")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with minPasswordRequirements equal to an empty array (= password without requirements)
|
||||||
|
public function testTimeZoneValidator()
|
||||||
|
{
|
||||||
|
$v = Yii::createObject(TimeZoneValidator::class, ["Europe/Rome"]);
|
||||||
|
$this->assertTrue($v->validate());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user