mirror of
https://github.com/e107inc/e107.git
synced 2025-08-15 11:04:18 +02:00
Replaced e_date::strptime() with eShims::strptime()
- NEW: Added \e107\Shims\Internal\StrptimeTrait, which implements PHP internal function strptime(). On not-Windows, the built-in function is called. If that function fails or if the operating system is Windows, the alternative pure PHP implementation is attempted. The first successful call is returned, or false if none are successful. - MOD: Deprecated e_date::strptime() in favor of eShims::strptime() - FIX: License misatributed for e_date::strptime() (now eShims::strptime()). The library used was public domain, not CC BY-NC-SA 2.0 FR by Lionel Sauron. - MOD: Removed STRPTIME_COMPAT constant now that eShims::strptime() exists - MOD: Removed support for calling e_date::strptime() with: - a localized full month name - a localized abbreviated month name - AM or PM - am or pm because these features were only implemented in Windows mode (STRPTIME_COMPAT). - MOD: php_compatibility_handler.php now defines global strptime() using the eShims::strptime() implementation - NEW: Test all(?) the possibilities of eShims::strptime()
This commit is contained in:
94
e107_tests/tests/unit/e107/Shims/StrptimeTest.php
Normal file
94
e107_tests/tests/unit/e107/Shims/StrptimeTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace e107\Shims;
|
||||
|
||||
class StrptimeTest extends \Codeception\Test\Unit
|
||||
{
|
||||
public function testStrptimeDefault()
|
||||
{
|
||||
$this->testStrptimeImplementation([\e107\Shims\InternalShims::class, 'strptime']);
|
||||
}
|
||||
|
||||
public function testStrptimeDefaultLegacy()
|
||||
{
|
||||
$this->testStrptimeImplementation([\eShims::class, 'strptime']);
|
||||
}
|
||||
|
||||
public function testStrptimeAlt()
|
||||
{
|
||||
$this->testStrptimeImplementation([\e107\Shims\InternalShims::class, 'strptime_alt']);
|
||||
}
|
||||
|
||||
protected function testStrptimeImplementation($implementation)
|
||||
{
|
||||
$this->testStrptimeDateOnly($implementation);
|
||||
$this->testStrptimeDateTime($implementation);
|
||||
$this->testStrptimeUnparsed($implementation);
|
||||
$this->testStrptimeInvalid($implementation);
|
||||
}
|
||||
|
||||
protected function testStrptimeDateOnly($implementation)
|
||||
{
|
||||
$actual = call_user_func($implementation, '2018/05/13', '%Y/%m/%d');
|
||||
$expected = array(
|
||||
'tm_year' => 118,
|
||||
'tm_mon' => 4,
|
||||
'tm_mday' => 13,
|
||||
'tm_sec' => 0,
|
||||
'tm_min' => 0,
|
||||
'tm_hour' => 0,
|
||||
'unparsed' => '',
|
||||
'tm_wday' => 0,
|
||||
'tm_yday' => 132,
|
||||
);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
protected function testStrptimeDateTime($implementation)
|
||||
{
|
||||
$actual = call_user_func($implementation, '2018/05/13 20:10', '%Y/%m/%d %H:%M');
|
||||
$expected = array(
|
||||
'tm_year' => 118,
|
||||
'tm_mon' => 4,
|
||||
'tm_mday' => 13,
|
||||
'tm_hour' => 20,
|
||||
'tm_min' => 10,
|
||||
'tm_sec' => 0,
|
||||
'unparsed' => '',
|
||||
'tm_wday' => 0,
|
||||
'tm_yday' => 132,
|
||||
);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
protected function testStrptimeUnparsed($implementation)
|
||||
{
|
||||
$actual = call_user_func($implementation, '1607-09-04 08:10 PM', '%Y-%m-%d %l:%M %P');
|
||||
$expected = array(
|
||||
'tm_year' => 1707,
|
||||
'tm_mon' => 8,
|
||||
'tm_mday' => 4,
|
||||
'tm_hour' => 0,
|
||||
'tm_min' => 10,
|
||||
'tm_sec' => 0,
|
||||
'unparsed' => '08 PM ',
|
||||
'tm_wday' => 2,
|
||||
'tm_yday' => 246,
|
||||
);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
protected function testStrptimeInvalid($implementation)
|
||||
{
|
||||
$actual = call_user_func($implementation, 'garbage', '%Y-%m-%d');
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user