]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/Core/LocationTest.php
[CORE] Make tests great gain
[quix0rs-gnu-social.git] / tests / Core / LocationTest.php
1 <?php
2 // This file is part of GNU social - https://www.gnu.org/software/social
3 //
4 // GNU social is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // GNU social is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
16
17 namespace Tests\Unit;
18
19 if (!defined('INSTALLDIR')) {
20     define('INSTALLDIR', dirname(dirname(__DIR__)));
21 }
22 if (!defined('GNUSOCIAL')) {
23     define('GNUSOCIAL', true);
24 }
25 if (!defined('STATUSNET')) { // Compatibility
26     define('STATUSNET', true);
27 }
28
29 use GeonamesPlugin;
30 use Location;
31 use PHPUnit\Framework\TestCase;
32
33 require_once INSTALLDIR . '/lib/common.php';
34
35 // Make sure this is loaded
36 // XXX: how to test other plugins...?
37
38 addPlugin('Geonames');
39
40 final class LocationTest extends TestCase
41 {
42
43     /**
44      * @dataProvider locationNames
45      * @param $name
46      * @param $language
47      * @param $location
48      */
49
50     public function testLocationFromName($name, $language, $location)
51     {
52         $result = Location::fromName($name, $language);
53         $this->assertEquals($result, $location);
54     }
55
56     static public function locationNames()
57     {
58         return array(array('Montreal', 'en', null),
59             array('San Francisco, CA', 'en', null),
60             array('Paris, France', 'en', null),
61             array('Paris, Texas', 'en', null));
62     }
63
64     /**
65      * @dataProvider locationIds
66      * @param $id
67      * @param $ns
68      * @param $language
69      * @param $location
70      */
71
72     public function testLocationFromId($id, $ns, $language, $location)
73     {
74         $result = Location::fromId($id, $ns, $language);
75         $this->assertEquals($result, $location);
76     }
77
78     static public function locationIds()
79     {
80         return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null),
81             array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null));
82     }
83
84     /**
85      * @dataProvider locationLatLons
86      * @param $lat
87      * @param $lon
88      * @param $language
89      * @param $location
90      */
91
92     public function testLocationFromLatLon($lat, $lon, $language, $location)
93     {
94         $result = Location::fromLatLon($lat, $lon, $language);
95         $this->assertEquals($location, $result->location_id);
96     }
97
98     static public function locationLatLons()
99     {
100         return array(array(37.77493, -122.41942, 'en', null),
101             array(45.509, -73.588, 'en', null));
102     }
103
104     /**
105      * @dataProvider nameOfLocation
106      * @param $location
107      * @param $language
108      * @param $name
109      */
110
111     public function testLocationGetName($location, $language, $name)
112     {
113         $result = empty($location) ? null : $location->getName($language);
114         $this->assertEquals($name, $result);
115     }
116
117     static public function nameOfLocation()
118     {
119         $loc = Location::fromName('Montreal', 'en');
120         return array(array($loc, 'en', null), //'Montreal'),
121             array($loc, 'fr', null));//'MontrĂ©al'));
122     }
123 }
124