forked from mschuett/freifunkmeta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-LowLevelTests.php
178 lines (154 loc) · 6.59 KB
/
test-LowLevelTests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
# low level test of PHP functions & methods w/o WP integration
class LowLevelTests extends PHPUnit_Framework_TestCase {
function setUp() {
$this->FFM = new FF_Meta(new MockDataService());
$this->FFM->reinit_external_data_service(new MockDataService());
}
/* some very basic things */
function test_basic_json_parsing() {
$json = file_get_contents(__DIR__.'/example_ffhh.json');
$data = json_decode($json, $assoc = true);
$this->assertArrayHasKey('name', $data);
$this->assertArrayHasKey('state', $data);
$this->assertArrayHasKey('location', $data);
$this->assertArrayHasKey('services', $data);
}
function test_externaldata_mock() {
$ed = new MockDataService();
$url_dir = 'https://raw.githubusercontent.com/freifunk/directory.api.freifunk.net/master/directory.json';
$url_ff = 'http://meta.hamburg.freifunk.net/ffhh.json';
$url_inv = 'http://meta.hamburg.freifunk.net/invalid.txt';
// verify that $ed->get does not read the URLs above, but local example_*.json files
$data_ff = $ed->get($url_ff);
$this->assertArrayHasKey('name', $data_ff);
$this->assertArrayHasKey('state', $data_ff);
$this->assertArrayHasKey('location', $data_ff);
$this->assertArrayHasKey('services', $data_ff);
$data_dir = $ed->get($url_dir);
$this->assertArrayHasKey('hamburg', $data_dir);
$this->assertEquals(2, count($data_dir));
$data_inv = $ed->get($url_inv);
$this->assertEquals(0, count($data_inv));
}
/* the aux. classes */
function test_ff_directory() {
$dir = new FF_Directory(new MockDataService());
$valid = $dir->get_url_by_city('hamburg');
$invalid = $dir->get_url_by_city('jena');
$this->assertTrue(!!$valid);
$this->assertTrue(!$invalid);
}
/**
* @expectedException PHPUnit_Framework_Error
*/
function test_ff_community_invalid() {
$data = array();
$comm = new FF_Community($data);
}
function test_ff_community_empty() {
$data = array('location' => array());
$comm = new FF_Community($data);
$this->assertEmpty($comm->street);
$this->assertEmpty($comm->name);
$string = $comm->format_address();
$this->assertEquals('', $string);
}
function test_ff_community_filled() {
$data = array('location' => array(
'address' => array(
'Name' => 'some_name',
'Street' => 'some_street',
'Zipcode' => 'some_zip'
),
'city' => 'some_city',
'lon' => 'some_lon',
'lat' => 'some_lat',
));
$comm = new FF_Community($data);
$this->assertEquals('some_name', $comm->name);
$this->assertEquals('some_street', $comm->street);
$this->assertEquals('some_zip', $comm->zip);
$this->assertEquals('some_city', $comm->city);
$this->assertEquals('some_lon', $comm->lon);
$this->assertEquals('some_lat', $comm->lat);
$string = $comm->format_address();
$this->assertEquals('<p>some_name<br/>some_street<br/>some_zip some_city</p>', $string);
}
function test_ff_community_make_from_city() {
$comm = FF_Community::make_from_city('hamburg', new MockDataService());
$this->assertEquals('Chaos Computer Club Hansestadt Hamburg', $comm->name);
$this->assertEquals('Humboldtstr. 53', $comm->street);
$this->assertEquals('22083', $comm->zip);
$this->assertEquals('Hamburg', $comm->city);
$this->assertEquals(10.024418, $comm->lon);
$this->assertEquals(53.574267, $comm->lat);
}
/* the output methods */
function test_output_ff_state_null() {
$data = array("state" => array("nodes" => null));
$ret = $this->FFM->output_ff_state($data);
$this->assertEmpty($ret);
}
function test_output_ff_state() {
$data = array("state" => array("nodes" => 429));
$ret = $this->FFM->output_ff_state($data);
$this->assertRegExp('/429/', $ret);
}
function test_output_ff_services_null() {
$data = array();
$ret = $this->FFM->output_ff_services($data);
$this->assertEmpty($ret);
$this->assertEquals('', $ret);
}
function test_output_ff_services() {
$data = array(
'services' => array(array(
'serviceName' => 'jabber',
'serviceDescription' => 'chat',
'internalUri' => 'xmpp://jabber.local',
'externalUri' => 'xmpp://jabber.example.org',
)));
$ret = $this->FFM->output_ff_services($data);
$this->assertEquals('<table><th>Dienst</th><th>Beschreibung</th><th>Freifunk URI</th><th>Internet URI</th>'.
'<tr><td>jabber</td><td>chat</td><td><a href="xmpp://jabber.local">xmpp://jabber.local</a></td>'.
'<td><a href="xmpp://jabber.example.org">xmpp://jabber.example.org</a></td></tr>'.
'</table>', $ret);
}
function test_output_ff_contact_null() {
$data = array();
$ret = $this->FFM->output_ff_contact($data);
$this->assertEquals('', $ret);
}
function test_output_ff_contact_filled() {
$data = array('contact' => array(
'email' => '[email protected]',
'jabber' => '[email protected]'
));
$ret = $this->FFM->output_ff_contact($data);
$this->assertRegExp('/E-Mail/', $ret);
$this->assertRegExp('/mailto:mail@example\.com/', $ret);
$this->assertRegExp('/XMPP/', $ret);
$this->assertRegExp('/xmpp:example/', $ret);
$data = array('contact' => array(
'twitter' => 'http://twitter.com/freifunk'
));
$ret = $this->FFM->output_ff_contact($data);
$this->assertRegExp('/twitter\.com\/freifunk/', $ret);
$data = array('contact' => array(
'twitter' => '@freifunk'
));
$ret = $this->FFM->output_ff_contact($data);
$this->assertRegExp('/Twitter/', $ret);
$this->assertRegExp('/twitter\.com\/freifunk/', $ret);
$data = array('contact' => array(
'ml' => '[email protected]',
'irc' => 'irc://irc.hackint.net/example',
'facebook' => 'freifunk',
));
$ret = $this->FFM->output_ff_contact($data);
$this->assertRegExp('/mailto:mail@example\.com/', $ret);
$this->assertRegExp('/irc\.hackint\.net\/example/', $ret);
$this->assertRegExp('/Facebook:/', $ret);
}
}