add unit testing

This commit is contained in:
info@mschuette.name 2014-05-26 13:35:17 +00:00
commit ec84f3d91b
8 changed files with 324 additions and 0 deletions

14
tests/bootstrap.php Normal file
View file

@ -0,0 +1,14 @@
<?php
$_tests_dir = getenv('WP_TESTS_DIR');
if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
require_once $_tests_dir . '/includes/functions.php';
function _manually_load_plugin() {
require dirname( __FILE__ ) . '/../freifunkmeta.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
require $_tests_dir . '/includes/bootstrap.php';

41
tests/example_ffffm.json Normal file
View file

@ -0,0 +1,41 @@
{
"name": "Freifunk Frankfurt am Main - ffffm",
"url": "http://www.wifi-frankfurt.de/",
"state": {
"nodes": 4,
"lastchange": 0,
"message": "open for public"
},
"location": {
"city": "Frankfurt am Main",
"lat": 50.110556,
"lon": 8.682222
},
"contact": {
"email": "info@wifi-frankfurt.de",
"irc": "#freifunk on freenode",
"ml": "user@wifi-frankfurt.de",
"twitter": "https://twitter.com/FreiFunkFFM"
},
"techDetails": {
"stoererhaftung": "VPN",
"firmware": {
"url": "http://wiki.freifunk.net/Firmware_Flashen"
},
"networks": {
"ipv4": [
{
"netmask": 16,
"network": "10.126.0.0"
}
]
},
"routing": "BATMAN",
"splashpage": "none"
},
"state": {
"lastchange": 1391267102
},
"api": "0.1"
}

107
tests/example_ffhh.json Normal file
View file

@ -0,0 +1,107 @@
{
"name": "Freifunk Hamburg",
"api": "0.3.0",
"url": "https://hamburg.freifunk.net",
"techDetails": {
"updatemode": "autoupdater",
"bootstrap": "http://formular.hamburg.freifunk.net",
"splashpage": "none",
"firmware": {
"url": "https://hamburg.freifunk.net/anleitung",
"name": "gluon"
},
"routing": "batman-adv",
"tld": {
"nameserver": [
"10.112.1.1",
"10.112.14.1"
],
"domainname": "ffhh"
},
"vpn": "fastd",
"stoererhaftung": "VPN in die Niederlande",
"networks": {
"ipv4": [
{
"network": "10.112.0.0/18"
}
],
"ipv6": [
{
"network": "fd51:2bb2:fd0d::/48"
}
]
}
},
"state": {
"nodes": 429,
"lastchange": "2014-04-27T12:50:01.842182",
"message": "open for public"
},
"contact": {
"ml": "freifunk@hamburg.ccc.de",
"twitter": "@FreifunkHH",
"irc": "irc://irc.hackint.net/ffhh",
"facebook": "https://www.facebook.com/FreifunkHamburg",
"email": "kontakt@hamburg.freifunk.net"
},
"location": {
"lat": 53.574267,
"city": "Hamburg",
"lon": 10.024418,
"address": {
"Street": "Humboldtstr. 53",
"Name": "Chaos Computer Club Hansestadt Hamburg",
"Zipcode": "22083"
}
},
"services": [
{
"internalUri": "xmpp://jabber.ffhh",
"serviceName": "jabber",
"serviceDescription": "Chat"
},
{
"internalUri": "nntp://news.services.ffhh",
"serviceName": "news",
"serviceDescription": "Newsserver"
},
{
"internalUri": "http://radio.ffhh",
"serviceName": "radio",
"serviceDescription": "CC Musik und freisprech podcast"
}
],
"nodeMaps": [
{
"url": "http://knotenkarte.de",
"interval": "1 min",
"technicalType": "ffmap",
"mapType": "geographical"
},
{
"url": "http://knotengraph.de",
"interval": "1 min",
"technicalType": "ffmap",
"mapType": "structural"
},
{
"url": "http://graph.hamburg.freifunk.net/list.html",
"interval": "1 min",
"technicalType": "ffmap",
"mapType": "list/status"
}
],
"feeds": [
{
"category": "blog",
"url": "https://hamburg.freifunk.net/?feed=rss2",
"type": "rss"
},
{
"category": "others",
"url": "https://hamburg.freifunk.net/feed/freisprech-mp3/?feed=rss2",
"type": "rss"
}
]
}

43
tests/test-nonwp.php Normal file
View file

@ -0,0 +1,43 @@
<?php
# low level test of PHP functions & methods w/o WP integration
class LowLevelTest extends PHPUnit_Framework_TestCase {
function setUp() {
$this->FFM = new FF_Meta();
}
function test_output_ff_state() {
$ret = $this->FFM->output_ff_state(array("state" => array("nodes" => 429)));
$this->assertRegExp('/429/', $ret);
}
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() {
$json = file_get_contents(__DIR__.'/example_ffhh.json');
$stubdata = json_decode($json, $assoc = true);
$stub = $this->getMockBuilder('ff_meta_externaldata')
->disableOriginalConstructor()
->getMock();
$stub->expects($this->any())
->method('get')
->will($this->returnValue($stubdata));
$data = $stub->get('http://meta.hamburg.freifunk.net/ffhh.json');
$this->assertArrayHasKey('name', $data);
$this->assertArrayHasKey('state', $data);
$this->assertArrayHasKey('location', $data);
$this->assertArrayHasKey('services', $data);
}
}

8
tests/test-wpsample.php Normal file
View file

@ -0,0 +1,8 @@
<?php
# all tests with WP integration
class SampleTest extends WP_UnitTestCase {
function test_sample() {
$this->assertTrue(true);
}
}