-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: timestamp getters for PostObjectInterface (#1283)
- Loading branch information
Showing
13 changed files
with
336 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace Municipio\Controller; | ||
|
||
use Municipio\Helper\WpService; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use WpService\Implementations\FakeWpService; | ||
|
||
class ArchiveTest extends TestCase | ||
{ | ||
/** | ||
* @testdox tryFormatDateToUnixTimestamp() returns a unix timestamp when given a valid date string | ||
* @dataProvider provideValidDateStrings | ||
*/ | ||
public function testTryFormatDateToUnixTimestampReturnsUnixTimestampFromString($dateString) | ||
{ | ||
WpService::set($this->getWpServiceWithTranslatedDateStrings()); | ||
$archive = $this->getArchiveWithoutConstructor(); | ||
$this->assertIsInt($archive->tryFormatDateToUnixTimestamp($dateString)); | ||
} | ||
|
||
/** | ||
* @testdox tryFormatDateToUnixTimestamp() returns the same int as provided | ||
*/ | ||
public function testTryFormatDateToUnixTimestampReturnsSameIntAsProvided() | ||
{ | ||
$archive = $this->getArchiveWithoutConstructor(); | ||
$this->assertEquals(1234567890, $archive->tryFormatDateToUnixTimestamp(1234567890)); | ||
} | ||
|
||
/** | ||
* @testdox tryFormatDateToUnixTimestamp() returns null on invalid date string | ||
*/ | ||
public function testTryFormatDateToUnixTimestampReturnsNullOnInvalidString() | ||
{ | ||
$archive = $this->getArchiveWithoutConstructor(); | ||
$this->assertNull($archive->tryFormatDateToUnixTimestamp('invalid date string')); | ||
} | ||
|
||
private function getWpServiceWithTranslatedDateStrings() | ||
{ | ||
return new FakeWpService(['__' => fn($string) => | ||
match ($string) { | ||
'January' => 'Januari', | ||
'February' => 'Februari', | ||
'March' => 'Mars', | ||
'April' => 'April', | ||
'May' => 'Maj', | ||
'June' => 'Juni', | ||
'July' => 'Juli', | ||
'August' => 'Augusti', | ||
'September' => 'September', | ||
'October' => 'Oktober', | ||
'November' => 'November', | ||
'December' => 'December', | ||
'Jan' => 'Jan', | ||
'Feb' => 'Feb', | ||
'Mar' => 'Mar', | ||
'Apr' => 'Apr', | ||
'May' => 'Maj', | ||
'Jun' => 'Jun', | ||
'Jul' => 'Jul', | ||
'Aug' => 'Aug', | ||
'Sep' => 'Sep', | ||
'Oct' => 'Okt', | ||
'Nov' => 'Nov', | ||
'Dec' => 'Dec', | ||
'Monday' => 'Måndag', | ||
'Tuesday' => 'Tisdag', | ||
'Wednesday' => 'Onsdag', | ||
'Thursday' => 'Torsdag', | ||
'Friday' => 'Fredag', | ||
'Saturday' => 'Lördag', | ||
'Sunday' => 'Söndag', | ||
'Mon' => 'Mån', | ||
'Tue' => 'Tis', | ||
'Wed' => 'Ons', | ||
'Thu' => 'Tor', | ||
'Fri' => 'Fre', | ||
'Sat' => 'Lör', | ||
'Sun' => 'Sön', | ||
} | ||
]); | ||
} | ||
|
||
public function provideValidDateStrings(): array | ||
{ | ||
return [ | ||
'2020-01-01' => ['2020-01-01'], | ||
'2020-01-01 00:00:00' => ['2020-01-01 00:00:00'], | ||
'2020-01-01 00:00:00.000' => ['2020-01-01 00:00:00.000'], | ||
'2020-01-01T00:00:00' => ['2020-01-01T00:00:00'], | ||
'2020-01-01T00:00:00.000' => ['2020-01-01T00:00:00.000'], | ||
'January 1, 2020' => ['January 1, 2020'], | ||
'Januari 1, 2020' => ['Januari 1, 2020'], | ||
'Okt 1, 2020' => ['Okt 1, 2020'], | ||
'Monday, January 1, 2020' => ['Monday, January 1, 2020'], | ||
'Tisdag, Januari 2, 2020' => ['Tisdag, Januari 2, 2020'], | ||
'Mon, January 1, 2020' => ['Mon, January 1, 2020'], | ||
'Mån, Januari 27, 2025' => ['Mån, Januari 27, 2025'], | ||
'mån, januari 27, 2025' => ['mån, januari 27, 2025'], | ||
]; | ||
} | ||
|
||
private function getArchiveWithoutConstructor(): Archive|MockObject | ||
{ | ||
return $this->getMockBuilder(Archive::class) | ||
->disableOriginalConstructor() | ||
->onlyMethods(['__construct']) | ||
->getMock(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.