1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright Andreas Heigl<[email protected]> |
4
|
|
|
* |
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
6
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
7
|
|
|
* in the Software without restriction, including without limitation the rights |
8
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
10
|
|
|
* furnished to do so, subject to the following conditions: |
11
|
|
|
* |
12
|
|
|
* The above copyright notice and this permission notice shall be included in |
13
|
|
|
* all copies or substantial portions of the Software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIBILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21
|
|
|
* THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
* @author Andreas Heigl<[email protected]> |
24
|
|
|
* @copyright Andreas Heigl |
25
|
|
|
* @license http://www.opesource.org/licenses/mit-license.php MIT-License |
26
|
|
|
* @version 0.0 |
27
|
|
|
* @since 04.07.13 |
28
|
|
|
* @link https://github.com/heiglandreas/OrgHeiglGeolocation |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
namespace Org_Heigl\GeolocationTest\Validator; |
32
|
|
|
|
33
|
|
|
use Org_Heigl\Geolocation\Validator\IsGeolocation; |
34
|
|
|
use PHPUnit\Framework\TestCase; |
35
|
|
|
|
36
|
|
|
class IsGeolocationTest extends TestCase |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider geolocationProvider |
41
|
|
|
*/ |
42
|
|
|
public function testGeolocation($value, $expected) |
43
|
|
|
{ |
44
|
|
|
$validator = new IsGeolocation(); |
45
|
|
|
$this->assertEquals($expected, $validator->isValid($value)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function geolocationProvider() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
array('0,0', true), |
52
|
|
|
array('90,180', true), |
53
|
|
|
array('-90,1800', true), |
54
|
|
|
array('90,-180', true), |
55
|
|
|
array('90,-180', true), |
56
|
|
|
array('-90, 90', true), |
57
|
|
|
array('90.0,90.0', true), |
58
|
|
|
array('-90.000001,0', false), |
59
|
|
|
array('0, -180.00000001', false), |
60
|
|
|
array('90.00°, 180.00°', true), |
61
|
|
|
array('N50.443 E22.445', true), |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $teststring |
67
|
|
|
* @param $expectedError |
68
|
|
|
* @dataProvider errorMessagesProvider |
69
|
|
|
*/ |
70
|
|
|
public function testErrorMessages($teststring, $expectedError) |
71
|
|
|
{ |
72
|
|
|
$validator = new IsGeolocation(); |
73
|
|
|
$validator->isValid($teststring); |
74
|
|
|
|
75
|
|
|
$this->assertEquals(array($expectedError), array_keys($validator->getMessages())); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function errorMessagesProvider() |
79
|
|
|
{ |
80
|
|
|
return array( |
81
|
|
|
array('teststring', IsGeolocation::INVALID_FORMAT), |
82
|
|
|
array('91,180', IsGeolocation::LATITUDE_OUT_OF_RANGE), |
83
|
|
|
array('90,180.0000001', IsGeolocation::LONGITUDE_OUT_OF_RANGE), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|