1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\DataValues\Geo\Values; |
4
|
|
|
|
5
|
|
|
use DataValues\Geo\Values\GlobeCoordinateValue; |
6
|
|
|
use DataValues\Geo\Values\LatLongValue; |
7
|
|
|
use DataValues\IllegalValueException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \DataValues\Geo\Values\GlobeCoordinateValue |
11
|
|
|
* |
12
|
|
|
* @group DataValue |
13
|
|
|
* @group DataValueExtensions |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0-or-later |
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
17
|
|
|
*/ |
18
|
|
|
class GlobeCoordinateValueTest extends DataValueTest { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @see DataValueTest::getClass |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function getClass() { |
26
|
|
|
return GlobeCoordinateValue::class; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function validConstructorArgumentsProvider() { |
30
|
|
|
$argLists = []; |
31
|
|
|
|
32
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1 ]; |
33
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 42 ), 1 ]; |
34
|
|
|
$argLists[] = [ new LatLongValue( 42, 4.2 ), 0.1 ]; |
35
|
|
|
$argLists[] = [ new LatLongValue( 42, 42 ), 0.1 ]; |
36
|
|
|
$argLists[] = [ new LatLongValue( -4.2, -4.2 ), 0.1 ]; |
37
|
|
|
$argLists[] = [ new LatLongValue( 4.2, -42 ), 0.1 ]; |
38
|
|
|
$argLists[] = [ new LatLongValue( -42, 4.2 ), 10 ]; |
39
|
|
|
$argLists[] = [ new LatLongValue( 0, 0 ), 0.001 ]; |
40
|
|
|
$argLists[] = [ new LatLongValue( 0, 0 ), 360 ]; |
41
|
|
|
$argLists[] = [ new LatLongValue( 0, 0 ), -360 ]; |
42
|
|
|
|
43
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1, GlobeCoordinateValue::GLOBE_EARTH ]; |
44
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1, 'terminus' ]; |
45
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1, "Schar's World" ]; |
46
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1, 'coruscant' ]; |
47
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1, null ]; |
48
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), null ]; |
49
|
|
|
|
50
|
|
|
return $argLists; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function invalidConstructorArgumentsProvider() { |
54
|
|
|
$argLists = []; |
55
|
|
|
|
56
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 361 ]; |
57
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), -361 ]; |
58
|
|
|
$argLists[] = [ new LatLongValue( 4.2, 4.2 ), 1, '' ]; |
59
|
|
|
|
60
|
|
|
return $argLists; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @dataProvider instanceProvider |
65
|
|
|
*/ |
66
|
|
|
public function testGetLatitude( GlobeCoordinateValue $globeCoordinate, array $arguments ) { |
67
|
|
|
$actual = $globeCoordinate->getLatitude(); |
68
|
|
|
|
69
|
|
|
$this->assertInternalType( 'float', $actual ); |
70
|
|
|
$this->assertSame( $arguments[0]->getLatitude(), $actual ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @dataProvider instanceProvider |
75
|
|
|
*/ |
76
|
|
|
public function testGetLongitude( GlobeCoordinateValue $globeCoordinate, array $arguments ) { |
77
|
|
|
$actual = $globeCoordinate->getLongitude(); |
78
|
|
|
|
79
|
|
|
$this->assertInternalType( 'float', $actual ); |
80
|
|
|
$this->assertSame( $arguments[0]->getLongitude(), $actual ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @dataProvider instanceProvider |
85
|
|
|
*/ |
86
|
|
|
public function testGetPrecision( GlobeCoordinateValue $globeCoordinate, array $arguments ) { |
87
|
|
|
$actual = $globeCoordinate->getPrecision(); |
88
|
|
|
|
89
|
|
|
$this->assertTrue( |
90
|
|
|
is_float( $actual ) || is_int( $actual ) || $actual === null, |
91
|
|
|
'Precision is int or float or null' |
92
|
|
|
); |
93
|
|
|
$this->assertEquals( $arguments[1], $actual ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @dataProvider instanceProvider |
98
|
|
|
*/ |
99
|
|
|
public function testGetGlobe( GlobeCoordinateValue $globeCoordinate, array $arguments ) { |
100
|
|
|
$expected = isset( $arguments[2] ) |
101
|
|
|
? $arguments[2] |
102
|
|
|
: GlobeCoordinateValue::GLOBE_EARTH; |
103
|
|
|
|
104
|
|
|
$actual = $globeCoordinate->getGlobe(); |
105
|
|
|
|
106
|
|
|
$this->assertTrue( |
107
|
|
|
is_string( $actual ), |
108
|
|
|
'getGlobe should return a string' |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$this->assertSame( $expected, $actual ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function provideIllegalArrayValue() { |
115
|
|
|
return [ |
116
|
|
|
[ null ], |
117
|
|
|
[ '' ], |
118
|
|
|
[ [] ], |
119
|
|
|
[ [ 'latitude' => 0 ] ], |
120
|
|
|
[ [ 'longitude' => 0 ] ], |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @dataProvider provideIllegalArrayValue |
126
|
|
|
*/ |
127
|
|
|
public function testNewFromArrayErrorHandling( $data ) { |
128
|
|
|
$this->expectException( IllegalValueException::class ); |
129
|
|
|
GlobeCoordinateValue::newFromArray( $data ); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testArrayValueCompatibility() { |
133
|
|
|
// These serializations where generated using revision f91f65f989cc3ffacbe924012d8f5b574e0b710c |
134
|
|
|
// The strings are the result of calling getArrayValue on the objects and then feeding this to serialize. |
135
|
|
|
|
136
|
|
|
$serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;' |
137
|
|
|
. 's:9:"longitude";d:42;' |
138
|
|
|
. 's:8:"altitude";N;' |
139
|
|
|
. 's:9:"precision";d:0.01;' |
140
|
|
|
. 's:5:"globe";s:4:"mars";}'; |
141
|
|
|
|
142
|
|
|
$arrayForm = unserialize( $serialization ); |
143
|
|
|
$globeCoordinate = GlobeCoordinateValue::newFromArray( $arrayForm ); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$this->assertSame( -4.2, $globeCoordinate->getLatitude() ); |
146
|
|
|
$this->assertSame( 42.0, $globeCoordinate->getLongitude() ); |
147
|
|
|
$this->assertSame( 0.01, $globeCoordinate->getPrecision() ); |
148
|
|
|
$this->assertSame( 'mars', $globeCoordinate->getGlobe() ); |
149
|
|
|
|
150
|
|
|
$serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;' |
151
|
|
|
. 's:9:"longitude";d:-42;' |
152
|
|
|
. 's:8:"altitude";d:9001;' |
153
|
|
|
. 's:9:"precision";d:1;' |
154
|
|
|
. 's:5:"globe";s:33:"http://www.wikidata.org/entity/Q2";}'; |
155
|
|
|
|
156
|
|
|
$arrayForm = unserialize( $serialization ); |
157
|
|
|
$globeCoordinate = GlobeCoordinateValue::newFromArray( $arrayForm ); |
|
|
|
|
158
|
|
|
|
159
|
|
|
$this->assertSame( -4.2, $globeCoordinate->getLatitude() ); |
160
|
|
|
$this->assertSame( -42.0, $globeCoordinate->getLongitude() ); |
161
|
|
|
$this->assertSame( 1.0, $globeCoordinate->getPrecision() ); |
162
|
|
|
$this->assertSame( 'http://www.wikidata.org/entity/Q2', $globeCoordinate->getGlobe() ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function testSerializeCompatibility() { |
166
|
|
|
$globeCoordinate = unserialize( |
167
|
|
|
'C:42:"DataValues\Geo\Values\GlobeCoordinateValue":27:{[-4.2,-42,null,0.01,"mars"]}' |
168
|
|
|
); |
169
|
|
|
$this->assertInstanceOf( $this->getClass(), $globeCoordinate ); |
170
|
|
|
|
171
|
|
|
$this->assertSame( -4.2, $globeCoordinate->getLatitude() ); |
172
|
|
|
$this->assertSame( -42.0, $globeCoordinate->getLongitude() ); |
173
|
|
|
$this->assertSame( 0.01, $globeCoordinate->getPrecision() ); |
174
|
|
|
$this->assertSame( 'mars', $globeCoordinate->getGlobe() ); |
175
|
|
|
|
176
|
|
|
$globeCoordinate = unserialize( |
177
|
|
|
'C:42:"DataValues\Geo\Values\GlobeCoordinateValue":27:{[-4.2,-42,9001,0.01,"mars"]}' |
178
|
|
|
); |
179
|
|
|
$this->assertInstanceOf( $this->getClass(), $globeCoordinate ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function testHashIsConsistentAcrossDifferentRuntimeEnvironments() { |
183
|
|
|
$latLongValue = new LatLongValue( 12.2, 12.2 ); |
184
|
|
|
|
185
|
|
|
$globeCoordinateValue = new GlobeCoordinateValue( $latLongValue, 0.1, 'does not matter' ); |
186
|
|
|
|
187
|
|
|
$this->assertEquals( '08a33f1bbb4c8bd91b6531b5bffd91fd', $globeCoordinateValue->getHash() ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function testGetLatLong() { |
191
|
|
|
$latLong = new LatLongValue( 1, 2 ); |
192
|
|
|
|
193
|
|
|
$this->assertSame( |
194
|
|
|
$latLong, |
195
|
|
|
( new GlobeCoordinateValue( $latLong ) )->getLatLong() |
196
|
|
|
); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.