|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FlorianKoerner\ChimpDrill\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use FlorianKoerner\ChimpDrill\ChimpDrill; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Test placeholder merge tags |
|
9
|
|
|
*/ |
|
10
|
|
|
class PlaceholderTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return array |
|
14
|
|
|
*/ |
|
15
|
|
|
public function dataProvider() |
|
16
|
|
|
{ |
|
17
|
|
|
return array( |
|
18
|
|
|
array( |
|
19
|
|
|
'message' => 'Hello *|BEST_FRIEND|*', |
|
20
|
|
|
'placeholder' => array( |
|
21
|
|
|
'BEST_FRIEND' => 'John Doe' |
|
22
|
|
|
), |
|
23
|
|
|
'expected' => 'Hello John Doe' |
|
24
|
|
|
), |
|
25
|
|
|
array( |
|
26
|
|
|
'message' => 'Your name is *|YOUR_NAME|* & my name is *|MY_NAME|*.', |
|
27
|
|
|
'placeholder' => array( |
|
28
|
|
|
'MY_NAME' => 'John Doe', |
|
29
|
|
|
'YOUR_NAME' => 'Jane Doe' |
|
30
|
|
|
), |
|
31
|
|
|
'expected' => 'Your name is Jane Doe & my name is John Doe.' |
|
32
|
|
|
), |
|
33
|
|
|
array( |
|
34
|
|
|
'message' => 'You live in *|NYC|* *|AND|* I live in *|NYC|*. And we love *|FOOD|*.', |
|
35
|
|
|
'placeholder' => array( |
|
36
|
|
|
'NYC' => 'New York City', |
|
37
|
|
|
'FOOD' => 'fish and chips', |
|
38
|
|
|
'AND' => '&' |
|
39
|
|
|
), |
|
40
|
|
|
'expected' => 'You live in New York City & I live in New York City. And we love fish and chips.' |
|
41
|
|
|
), |
|
42
|
|
|
array( |
|
43
|
|
|
'message' => 'This is *|NOT:ALLOWED|*. And this *|PLACEHOLDER_NAME|* is missing, *|NAME|*.', |
|
44
|
|
|
'placeholder' => array( |
|
45
|
|
|
'NOT:ALLOWED' => 'Sure?', |
|
46
|
|
|
'NAME' => 'John' |
|
47
|
|
|
), |
|
48
|
|
|
'expected' => 'This is *|NOT:ALLOWED|*. And this *|PLACEHOLDER_NAME|* is missing, John.' |
|
49
|
|
|
), |
|
50
|
|
|
array( |
|
51
|
|
|
'message' => 'German umlauts: *|UMLAUTS|*', |
|
52
|
|
|
'placeholder' => array( |
|
53
|
|
|
'UMLAUTS' => 'äöü' |
|
54
|
|
|
), |
|
55
|
|
|
'expected' => 'German umlauts: äöü' |
|
56
|
|
|
) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $message |
|
62
|
|
|
* @param array $placeholder |
|
63
|
|
|
* @param string $expected |
|
64
|
|
|
* |
|
65
|
|
|
* @dataProvider dataProvider |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testMergeTags($message, array $placeholder, $expected) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertEquals($expected, (string) new ChimpDrill($message, $placeholder)); |
|
70
|
|
|
} |
|
71
|
|
|
} |