1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Options\Factory; |
4
|
|
|
|
5
|
|
|
use JhFlexiTime\DateTime\DateTime; |
6
|
|
|
use JhFlexiTime\Options\Factory\NotificationOptionsFactory; |
7
|
|
|
use Zend\ServiceManager\ServiceManager; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class NotificationOptionsFactoryTest |
11
|
|
|
* @package JhFlexiTime\Options\OptionsTest\Factory |
12
|
|
|
* @author Aydin Hassan <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class NotificationOptionsFactoryTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Test options injects from config files |
18
|
|
|
*/ |
19
|
|
|
public function testFactoryReturnsInjectedOptions() |
20
|
|
|
{ |
21
|
|
|
$config = ['remind_start' => '3 days ago', 'remind_days' => '7 days']; |
22
|
|
|
|
23
|
|
|
$locator = new ServiceManager(); |
24
|
|
|
$locator->setService('Config', ['flexi' => ['notification_options' => $config]]); |
25
|
|
|
|
26
|
|
|
$factory = new NotificationOptionsFactory(); |
27
|
|
|
$this->assertEquals(new DateTime('3 days ago 00:00:00'), $factory->createService($locator)->getRemindStart()); |
28
|
|
|
$this->assertEquals('7 days', $factory->createService($locator)->getRemindDays()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Test options returns defaults when no config set |
33
|
|
|
*/ |
34
|
|
|
public function testFactoryReturnsDefaultOptionsWithEmptyConfig() |
35
|
|
|
{ |
36
|
|
|
$config = []; |
37
|
|
|
|
38
|
|
|
$locator = new ServiceManager(); |
39
|
|
|
$locator->setService('Config', ['flexi' => ['notification_options' => $config]]); |
40
|
|
|
|
41
|
|
|
$factory = new NotificationOptionsFactory(); |
42
|
|
|
$this->assertEquals(new DateTime('2 days ago 00:00:00'), $factory->createService($locator)->getRemindStart()); |
43
|
|
|
$this->assertEquals('7 days', $factory->createService($locator)->getRemindDays()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test options returns defaults when no global config |
48
|
|
|
*/ |
49
|
|
|
public function testFactoryReturnsDefaultOptionsWithNoConfig() |
50
|
|
|
{ |
51
|
|
|
$config = []; |
52
|
|
|
|
53
|
|
|
$locator = new ServiceManager(); |
54
|
|
|
$locator->setService('Config', $config); |
55
|
|
|
|
56
|
|
|
$factory = new NotificationOptionsFactory(); |
57
|
|
|
$this->assertEquals(new DateTime('2 days ago 00:00:00'), $factory->createService($locator)->getRemindStart()); |
58
|
|
|
$this->assertEquals('7 days', $factory->createService($locator)->getRemindDays()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|