|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Miliooo\Messaging\Tests\Helpers\FlashMessages; |
|
12
|
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Helpers\FlashMessages\FlashMessageProvider; |
|
14
|
|
|
use Miliooo\Messaging\Helpers\FlashMessages\FlashMessageProviderInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Test file for the flash message provider. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Michiel Boeckaert <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class FlashMessageProviderTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var FlashMessageProvider |
|
25
|
|
|
*/ |
|
26
|
|
|
private $flashProvider; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
30
|
|
|
*/ |
|
31
|
|
|
private $flashBag; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
35
|
|
|
*/ |
|
36
|
|
|
private $translator; |
|
37
|
|
|
|
|
38
|
|
|
const SUCCESS_KEY = 'success'; |
|
39
|
|
|
|
|
40
|
|
|
const ERROR_KEY = 'failure'; |
|
41
|
|
|
|
|
42
|
|
|
const TRANSLATE_KEY = 'translate_key'; |
|
43
|
|
|
|
|
44
|
|
|
const TRANSLATED_STRING = 'translated_string'; |
|
45
|
|
|
|
|
46
|
|
|
public function setUp() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->flashBag = $this->getMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
|
49
|
|
|
$this->translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface'); |
|
50
|
|
|
$this->flashProvider = new FlashMessageProvider( |
|
51
|
|
|
$this->flashBag, |
|
52
|
|
|
$this->translator, |
|
53
|
|
|
self::SUCCESS_KEY, |
|
54
|
|
|
self::ERROR_KEY |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testInterface() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->assertInstanceOf( |
|
61
|
|
|
'Miliooo\Messaging\Helpers\FlashMessages\FlashMessageProviderInterface', |
|
62
|
|
|
$this->flashProvider |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testAddFlashWithTypeSuccess() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->expectsTranslatorTranslates(); |
|
69
|
|
|
|
|
70
|
|
|
$this->flashBag->expects($this->once()) |
|
71
|
|
|
->method('add') |
|
72
|
|
|
->with(self::SUCCESS_KEY, self::TRANSLATED_STRING); |
|
73
|
|
|
|
|
74
|
|
|
$this->flashProvider->addFlash( |
|
75
|
|
|
FlashMessageProviderInterface::TYPE_SUCCESS, |
|
76
|
|
|
self::TRANSLATE_KEY, |
|
77
|
|
|
[] |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testAddFlashWithTypeFailure() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->expectsTranslatorTranslates(); |
|
84
|
|
|
|
|
85
|
|
|
$this->flashBag->expects($this->once()) |
|
86
|
|
|
->method('add') |
|
87
|
|
|
->with(self::ERROR_KEY, self::TRANSLATED_STRING); |
|
88
|
|
|
|
|
89
|
|
|
$this->flashProvider->addFlash( |
|
90
|
|
|
FlashMessageProviderInterface::TYPE_ERROR, |
|
91
|
|
|
self::TRANSLATE_KEY, |
|
92
|
|
|
[] |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function expectsTranslatorTranslates() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->translator->expects($this->once()) |
|
99
|
|
|
->method('trans') |
|
100
|
|
|
->with(self::TRANSLATE_KEY, [], 'MilioooMessagingBundle') |
|
101
|
|
|
->will($this->returnValue(self::TRANSLATED_STRING)); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|