]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/LocationTest.php
Faster inboxnoticestream.php by XRevan86
[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($location, $result->location_id);
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 = empty($location)?null:$location->getName($language);
79         $this->assertEquals($name, $result);
80     }
81
82     static public function nameOfLocation()
83     {
84         $loc = Location::fromName('Montreal', 'en');
85         return array(array($loc, 'en', null), //'Montreal'),
86                      array($loc, 'fr', null));//'MontrĂ©al'));
87     }
88 }
89