-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #43 improve signature expiration support (jrushlow)
This PR was squashed before being merged into the master branch. Discussion ---------- improve signature expiration support This PR resolves the long standing issue of possibly invalid expiration values. It all adds support for translating when a signature expires out of the box. closes #39 Commits ------- e2e39ed improve signature expiration support
- Loading branch information
Showing
6 changed files
with
192 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file original="file.ext" source-language="en" datatype="plaintext"> | ||
<body> | ||
<trans-unit id="1"> | ||
<source>%count% year|%count% years</source> | ||
<target>%count% year|%count% years</target> | ||
</trans-unit> | ||
<trans-unit id="2"> | ||
<source>%count% month|%count% months</source> | ||
<target>%count% month|%count% months</target> | ||
</trans-unit> | ||
<trans-unit id="3"> | ||
<source>%count% day|%count% days</source> | ||
<target>%count% day|%count% days</target> | ||
</trans-unit> | ||
<trans-unit id="4"> | ||
<source>%count% hour|%count% hours</source> | ||
<target>%count% hour|%count% hours</target> | ||
</trans-unit> | ||
<trans-unit id="5"> | ||
<source>%count% minute|%count% minutes</source> | ||
<target>%count% minute|%count% minutes</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
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
63 changes: 63 additions & 0 deletions
63
tests/UnitTests/Model/VerifyEmailSignatureComponentsTest.php
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,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the SymfonyCasts VerifyEmailBundle package. | ||
* Copyright (c) SymfonyCasts <https://symfonycasts.com/> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SymfonyCasts\Bundle\VerifyEmail\Tests\UnitTests\Model; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SymfonyCasts\Bundle\VerifyEmail\Model\VerifyEmailSignatureComponents; | ||
|
||
/** | ||
* @author Jesse Rushlow <jr@rushlow.dev> | ||
*/ | ||
class VerifyEmailSignatureComponentsTest extends TestCase | ||
{ | ||
public function testGetExpiresAtInterval(): void | ||
{ | ||
$created = time(); | ||
|
||
$expire = \DateTimeImmutable::createFromFormat('U', (string) ($created + 3600)); | ||
|
||
$components = new VerifyEmailSignatureComponents($expire, 'some-uri', $created); | ||
|
||
self::assertSame(1, $components->getExpiresAtIntervalInstance()->h); | ||
} | ||
|
||
/** | ||
* @dataProvider translationIntervalDataProvider | ||
*/ | ||
public function testTranslations(int $lifetime, int $expectedInterval, string $unitOfMeasure): void | ||
{ | ||
$created = time(); | ||
|
||
$expire = \DateTimeImmutable::createFromFormat('U', (string) ($created + $lifetime)); | ||
|
||
$components = new VerifyEmailSignatureComponents($expire, 'some-uri', $created); | ||
|
||
self::assertSame( | ||
sprintf('%%count%% %s|%%count%% %ss', $unitOfMeasure, $unitOfMeasure), | ||
$components->getExpirationMessageKey() | ||
); | ||
|
||
self::assertSame(['%count%' => $expectedInterval], $components->getExpirationMessageData()); | ||
} | ||
|
||
public function translationIntervalDataProvider(): \Generator | ||
{ | ||
yield [60, 1, 'minute']; | ||
yield [900, 15, 'minute']; | ||
yield [3600, 1, 'hour']; | ||
yield [7200, 2, 'hour']; | ||
yield [43200, 12, 'hour']; | ||
yield [86400, 1, 'day']; | ||
yield [864000, 10, 'day']; | ||
yield [2678400, 1, 'month']; | ||
yield [5356800, 2, 'month']; | ||
yield [34819200, 1, 'year']; | ||
} | ||
} |