1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WNBY\Tests; |
4
|
|
|
|
5
|
|
|
use WNBY\NearbyParserFunction; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \WNBY\NearbyParserFunction |
9
|
|
|
* @group whats-nearby |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class NearbyParserFunctionTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
21
|
|
|
->disableOriginalConstructor() |
22
|
|
|
->getMock(); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf( |
25
|
|
|
'\WNBY\NearbyParserFunction', |
26
|
|
|
new NearbyParserFunction( $parser ) |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testParseWithoutMaps() { |
31
|
|
|
|
32
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
|
40
|
|
|
$parser->expects( $this->any() ) |
41
|
|
|
->method( 'getOutput' ) |
42
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
43
|
|
|
|
44
|
|
|
$instance = new NearbyParserFunction( |
45
|
|
|
$parser |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertContains( |
49
|
|
|
'<div class="whats-nearby" data-parameters="{"foo":"bar"}">', |
50
|
|
|
$instance->parse( array( 'foo=bar', 'no-parameter' ) ) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testParseWithGoogleMapsParameters() { |
55
|
|
|
|
56
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
57
|
|
|
->disableOriginalConstructor() |
58
|
|
|
->getMock(); |
59
|
|
|
|
60
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
61
|
|
|
->disableOriginalConstructor() |
62
|
|
|
->getMock(); |
63
|
|
|
|
64
|
|
|
$parser->expects( $this->atLeastOnce() ) |
65
|
|
|
->method( 'getOutput' ) |
66
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
67
|
|
|
|
68
|
|
|
$instance = new NearbyParserFunction( |
69
|
|
|
$parser |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->assertContains( |
73
|
|
|
'<div class="whats-nearby" data-parameters="{"foo":"bar","maps":"googlemaps"}">', |
74
|
|
|
$instance->parse( array( 'foo=bar', 'no-parameter', 'maps=googlemaps' ) ) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testParseWithOpenLayersParameters() { |
79
|
|
|
|
80
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
81
|
|
|
->disableOriginalConstructor() |
82
|
|
|
->getMock(); |
83
|
|
|
|
84
|
|
|
$parserOutput->expects( $this->atLeastOnce() ) |
85
|
|
|
->method( 'addJsConfigVars' ); |
86
|
|
|
|
87
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
88
|
|
|
->disableOriginalConstructor() |
89
|
|
|
->getMock(); |
90
|
|
|
|
91
|
|
|
$parser->expects( $this->any() ) |
92
|
|
|
->method( 'getOutput' ) |
93
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
94
|
|
|
|
95
|
|
|
$instance = new NearbyParserFunction( |
96
|
|
|
$parser |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->assertContains( |
100
|
|
|
'<div class="whats-nearby" data-parameters="{"foo":"bar","maps":"openlayers"}">', |
101
|
|
|
$instance->parse( array( 'foo=bar', 'no-parameter', 'maps=openlayers' ) ) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testParseWithLeafletParameters() { |
106
|
|
|
|
107
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
108
|
|
|
->disableOriginalConstructor() |
109
|
|
|
->getMock(); |
110
|
|
|
|
111
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
112
|
|
|
->disableOriginalConstructor() |
113
|
|
|
->getMock(); |
114
|
|
|
|
115
|
|
|
$parser->expects( $this->any() ) |
116
|
|
|
->method( 'getOutput' ) |
117
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
118
|
|
|
|
119
|
|
|
$instance = new NearbyParserFunction( |
120
|
|
|
$parser |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$this->assertContains( |
124
|
|
|
'<div class="whats-nearby" data-parameters="{"foo":"bar","format":"leaftlet","pr-3":"?Has coordinates"}">', |
125
|
|
|
$instance->parse( array( 'foo=bar', 'no-parameter', 'format=leaftlet', '?Has coordinates' ) ) |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testParseWithNolocation() { |
130
|
|
|
|
131
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
132
|
|
|
->disableOriginalConstructor() |
133
|
|
|
->getMock(); |
134
|
|
|
|
135
|
|
|
$parserOutput->expects( $this->once() ) |
136
|
|
|
->method( 'setExtensionData' ) |
137
|
|
|
->with( |
138
|
|
|
$this->equalTo( 'wnby-geoip' ), |
139
|
|
|
$this->equalTo( false ) ); |
140
|
|
|
|
141
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
142
|
|
|
->disableOriginalConstructor() |
143
|
|
|
->getMock(); |
144
|
|
|
|
145
|
|
|
$parser->expects( $this->any() ) |
146
|
|
|
->method( 'getOutput' ) |
147
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
148
|
|
|
|
149
|
|
|
$instance = new NearbyParserFunction( |
150
|
|
|
$parser |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$this->assertContains( |
154
|
|
|
'<div class="whats-nearby" data-parameters="{"foo":"bar","nolocation":"true"}">', |
155
|
|
|
$instance->parse( array( 'foo=bar', 'nolocation=true' ) ) |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
|