Completed
Push — master ( 59ef79...0173b4 )
by mw
10s
created

testParseWithNolocation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
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="{&quot;foo&quot;:&quot;bar&quot;}">',
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
		$parserOutput->expects( $this->atLeastOnce() )
61
			->method( 'addHeadItem' );
62
63
		$parser = $this->getMockBuilder( '\Parser' )
64
			->disableOriginalConstructor()
65
			->getMock();
66
67
		$parser->expects( $this->any() )
68
			->method( 'getOutput' )
69
			->will( $this->returnValue( $parserOutput ) );
70
71
		$instance = new NearbyParserFunction(
72
			$parser
73
		);
74
75
		$this->assertContains(
76
			'<div class="whats-nearby" data-parameters="{&quot;foo&quot;:&quot;bar&quot;,&quot;maps&quot;:&quot;googlemaps&quot;}">',
77
			$instance->parse( array( 'foo=bar', 'no-parameter', 'maps=googlemaps' ) )
78
		);
79
	}
80
81
	public function testParseWithOpenLayersParameters() {
82
83
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
84
			->disableOriginalConstructor()
85
			->getMock();
86
87
		$parserOutput->expects( $this->atLeastOnce() )
88
			->method( 'addJsConfigVars' );
89
90
		$parser = $this->getMockBuilder( '\Parser' )
91
			->disableOriginalConstructor()
92
			->getMock();
93
94
		$parser->expects( $this->any() )
95
			->method( 'getOutput' )
96
			->will( $this->returnValue( $parserOutput ) );
97
98
		$instance = new NearbyParserFunction(
99
			$parser
100
		);
101
102
		$this->assertContains(
103
			'<div class="whats-nearby" data-parameters="{&quot;foo&quot;:&quot;bar&quot;,&quot;maps&quot;:&quot;openlayers&quot;}">',
104
			$instance->parse( array( 'foo=bar', 'no-parameter', 'maps=openlayers' ) )
105
		);
106
	}
107
108
	public function testParseWithLeafletParameters() {
109
110
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
111
			->disableOriginalConstructor()
112
			->getMock();
113
114
		$parser = $this->getMockBuilder( '\Parser' )
115
			->disableOriginalConstructor()
116
			->getMock();
117
118
		$parser->expects( $this->any() )
119
			->method( 'getOutput' )
120
			->will( $this->returnValue( $parserOutput ) );
121
122
		$instance = new NearbyParserFunction(
123
			$parser
124
		);
125
126
		$this->assertContains(
127
			'<div class="whats-nearby" data-parameters="{&quot;foo&quot;:&quot;bar&quot;,&quot;format&quot;:&quot;leaftlet&quot;,&quot;pr-3&quot;:&quot;?Has coordinates&quot;}">',
128
			$instance->parse( array( 'foo=bar', 'no-parameter', 'format=leaftlet', '?Has coordinates' ) )
129
		);
130
	}
131
132
	public function testParseWithNolocation() {
133
134
		$parserOutput = $this->getMockBuilder( '\ParserOutput' )
135
			->disableOriginalConstructor()
136
			->getMock();
137
138
		$parserOutput->expects( $this->once() )
139
			->method( 'setExtensionData' )
140
			->with(
141
				$this->equalTo( 'wnby-geoip' ),
142
				$this->equalTo( false ) );
143
144
		$parser = $this->getMockBuilder( '\Parser' )
145
			->disableOriginalConstructor()
146
			->getMock();
147
148
		$parser->expects( $this->any() )
149
			->method( 'getOutput' )
150
			->will( $this->returnValue( $parserOutput ) );
151
152
		$instance = new NearbyParserFunction(
153
			$parser
154
		);
155
156
		$this->assertContains(
157
			'<div class="whats-nearby" data-parameters="{&quot;foo&quot;:&quot;bar&quot;,&quot;nolocation&quot;:&quot;true&quot;}">',
158
			$instance->parse( array( 'foo=bar', 'nolocation=true' ) )
159
		);
160
	}
161
162
}
163