-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMessageDismisserTest.php
68 lines (58 loc) · 1.83 KB
/
MessageDismisserTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Yoast\WHIP\Tests\Unit;
use Yoast\WHIP\Tests\Unit\Doubles\DismissStorageMock;
use Yoast\WHIPv2\MessageDismisser;
/**
* Message Dismisser unit tests.
*/
final class MessageDismisserTest extends TestCase {
/**
* Tests if MessageDismisser correctly updates DismissStorage.
*
* @covers \Yoast\WHIPv2\MessageDismisser::__construct
* @covers \Yoast\WHIPv2\MessageDismisser::dismiss
*
* @return void
*/
public function testDismiss() {
$currentTime = \time();
$storage = new DismissStorageMock();
$dismisser = new MessageDismisser( $currentTime, ( \WEEK_IN_SECONDS * 4 ), $storage );
$this->assertSame( 0, $storage->get() );
$dismisser->dismiss();
$this->assertSame( $currentTime, $storage->get() );
}
/**
* Tests if isDismissed correctly sets the version.
*
* @dataProvider versionNumbersProvider
*
* @covers \Yoast\WHIPv2\MessageDismisser::__construct
* @covers \Yoast\WHIPv2\MessageDismisser::isDismissed
*
* @param int $savedTime The saved time.
* @param int $currentTime The current time.
* @param bool $expected The expected value.
*
* @return void
*/
public function testIsDismissibleWithVersions( $savedTime, $currentTime, $expected ) {
$storage = new DismissStorageMock();
$storage->set( $savedTime );
$dismisser = new MessageDismisser( $currentTime, ( \WEEK_IN_SECONDS * 4 ), $storage );
$this->assertSame( $expected, $dismisser->isDismissed() );
}
/**
* Provides array with test values.
*
* @return array<string, array<int|bool>>
*/
public static function versionNumbersProvider() {
return array(
'-2weeks' => array( \strtotime( '-2weeks' ), \time(), true ),
'-4weeks' => array( \strtotime( '-4weeks' ), \time(), true ),
'-6weeks' => array( \strtotime( '-6weeks' ), \time(), false ),
'time()' => array( \time(), \time(), true ),
);
}
}