]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/LocationTest.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[quix0rs-gnu-social.git] / tests / LocationTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true);  // compatibility
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 // Make sure this is loaded
15 // XXX: how to test other plugins...?
16
17 addPlugin('Geonames');
18
19 class LocationTest extends PHPUnit_Framework_TestCase
20 {
21
22     /**
23      * @dataProvider locationNames
24      */
25
26     public function testLocationFromName($name, $language, $location)
27     {
28         $result = Location::fromName($name, $language);
29         $this->assertEquals($result, $location);
30     }
31
32     static public function locationNames()
33     {
34         return array(array('Montreal', 'en', null),
35                      array('San Francisco, CA', 'en', null),
36                      array('Paris, France', 'en', null),
37                      array('Paris, Texas', 'en', null));
38     }
39
40     /**
41      * @dataProvider locationIds
42      */
43
44     public function testLocationFromId($id, $ns, $language, $location)
45     {
46         $result = Location::fromId($id, $ns, $language);
47         $this->assertEquals($result, $location);
48     }
49
50     static public function locationIds()
51     {
52         return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
53                      array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
54     }
55
56     /**
57      * @dataProvider locationLatLons
58      */
59
60     public function testLocationFromLatLon($lat, $lon, $language, $location)
61     {
62         $result = Location::fromLatLon($lat, $lon, $language);
63         $this->assertEquals($result, $location);
64     }
65
66     static public function locationLatLons()
67     {
68         return array(array(37.77493, -122.41942, 'en', null),
69                      array(45.509, -73.588, 'en', null));
70     }
71
72     /**
73      * @dataProvider nameOfLocation
74      */
75
76     public function testLocationGetName($location, $language, $name)
77     {
78         $result = $location->getName($language);
79         $this->assertEquals($result, $name);
80     }
81
82     static public function nameOfLocation()
83     {
84         return array(array(new Location(), 'en', 'Montreal'),
85                      array(new Location(), 'fr', 'MontrĂ©al'));
86     }
87 }
88