Compare commits

...

37 commits

Author SHA1 Message Date
Alexander Dietrich e156d1fc35 Add URL workaround for multi-domain firmware 2019-03-15 22:16:52 +01:00
Alexander Dietrich a5eab032fd Change Gl.iNet name mangling, because OpenWrt is awesome at naming 2019-02-15 21:57:02 +01:00
Alexander Dietrich 95cde2e10f Add UBNT naming, sort models alphabetically 2018-10-15 22:51:46 +02:00
Alexander Dietrich b40f2878b7 Add "filter" argument 2017-12-04 21:56:43 +01:00
Alexander Dietrich a66ba3a361 Add "domain" and "branch" arguments 2017-11-17 21:37:10 +01:00
Leo Krueger ffc5ca3583 show hint if there is no factory image for certain routers 2017-10-16 21:20:14 +02:00
4ndr3 3cf7961709 Aktualisiert für firmware 0.8.2 2017-04-21 20:11:35 +02:00
root 6fff11b78a updates URL auf https umgestellt 2017-01-03 16:07:53 +01:00
4ndr3 119b2d9edb Neue Geräte hinzugefügt
Cisco Meraki & 8devices
2016-05-07 22:44:43 +02:00
4ndr3 e277c23097 Neue Geräte hinzugefügt
Onion-Omega, ALFA & Western Digital
2016-05-07 14:57:00 +02:00
Martin Schütte 741b5c721f only test for latest WP version
WP version 3.8 was _really_ outdated
2016-03-11 15:27:35 +01:00
Martin Schütte 9eb14ecfc5 fix test 2016-03-11 15:15:38 +01:00
root 7c3ef2775d Loco aus bullet genommen, da es dafür jetzt 'eigene' firmware gibt 2015-11-06 23:30:13 +01:00
Martin Schütte 39d45818f0 update travis-ci to docker infrastructure
http://docs.travis-ci.com/user/migrating-from-legacy/
2015-09-25 10:27:48 +02:00
Martin Schütte d810b983d8 fix tests
broken since af55ec2
2015-09-25 10:16:39 +02:00
root 026d4aafe1 .bin & .tar werden für netgear bei factory durch .img ersetzt 2015-07-15 21:02:09 +02:00
root 2d0e184f81 Netgear, ALLNET & Gl.iNet hinzugefügt 2015-05-31 17:40:57 +02:00
root af55ec2a69 alle strings verschönert 2015-01-18 23:15:39 +01:00
root 1499e14370 Buffalo strings schöner gemacht 2015-01-18 22:55:17 +01:00
4ndr3 e233ea1530 Buffalo hinzugefügt 2015-01-18 22:25:35 +01:00
4ndr3 10316f59ee manifest Datei in stable.manifest geändert
Wird jetzt als stable.manifest beim firmware bauen erzeugt
2014-12-17 16:38:44 +01:00
Martin Schütte 21fce8e59a add linksys string replacements 2014-08-07 16:57:21 +02:00
Martin Schuette 7ed0325a9a apply WP coding style 2014-06-29 18:22:12 +00:00
Martin Schuette 765dce0720 update 2014-06-29 18:02:34 +00:00
Martin Schuette 766b9a4d1e add simple testing 2014-06-29 17:59:02 +00:00
Martin Schuette 18495dbbc3 extra function ff_hh_beautify_hw_name 2014-06-29 17:58:01 +00:00
Martin Schütte f36d4f843f bump version 2014-06-26 09:16:42 +00:00
Martin Schütte 755bf74c7b fix reference passing, add simple d-link support 2014-06-26 09:16:09 +00:00
Martin Schuette d84e4b0e38 bugfix 2014-05-25 20:33:39 +00:00
Martin Schuette 0e2bd72e1c bump version 2014-05-25 20:10:38 +00:00
Martin Schuette fd520fc502 new update server name 2014-05-25 20:10:12 +00:00
Martin Schuette c5b3ccf3eb add grep argument for multiple tables 2014-05-25 20:06:18 +00:00
Martin Schütte b3101f0dd5 Merge pull request #1 from mschuett/workaround-ubiquity-name
move Hamburg specific changes into master
2014-05-25 21:27:45 +02:00
info@mschuette.name f8f17ebdfa yet another hack for Nanostation Loco 2014-05-20 16:36:45 +00:00
Martin Schütte 07b1f9c3af fix to M2 2014-04-28 22:45:19 +02:00
Martin Schütte 7ff07b6c57 bump version 2014-04-11 22:40:19 +02:00
Martin Schütte b78d7a931e workaround: "ubiquity ... m" devices are actually "ubiquity ... m1" 2014-04-11 22:39:21 +02:00
7 changed files with 414 additions and 81 deletions

18
.travis.yml Normal file
View file

@ -0,0 +1,18 @@
language: php
sudo: false
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
env:
- WP_VERSION=latest
before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
- fgrep wp_version /tmp/wordpress/wp-includes/version.php
script: phpunit

View file

@ -1,12 +1,45 @@
freifunk-versions freifunk-versions
================= =================
[![Build Status](https://travis-ci.org/freifunkhamburg/freifunk-versions.svg?branch=master)](https://travis-ci.org/freifunkhamburg/freifunk-versions)
Wordpress plugin to render latest (Hamburg-flavoured) Wordpress plugin to render latest (Hamburg-flavoured)
[gluon firmware](https://github.com/freifunkhamburg/gluon) version table. [gluon firmware](https://github.com/freifunkhamburg/gluon) version table.
Provides shortcode `[ff_hh_versions]` to display table. Provides shortcode `[ff_hh_versions]` to display table.
Input data is read from http://gw09.hamburg.freifunk.net/stable/sysupgrade/manifest Input data is read from i.e.
https://updates.hamburg.freifunk.net/ffhh/stable/sysupgrade/stable.manifest
Output looks like this: Output looks like this:
![shortcode output example](http://mschuette.name/wp/wp-upload/freifunk_versions.png) ![shortcode output example](http://mschuette.name/wp/wp-upload/freifunk_versions.png)
Arguments
---------
The optional argument `domain` (default: `ffhh`) allows you to choose the
firmware's domain.
Example:
```
Hamburg-Süd Firmware: [ff_hh_versions domain="ffhh-sued"]
```
The optional argument `branch` (default: `stable`) allows you to choose the
firmware's branch.
Example:
```
Experimental Firmware: [ff_hh_versions branch="experimental"]
```
The optional argument `grep` allows you show a subset of hardware versions.
Example:
```
TP-Link Firmware: [ff_hh_versions grep="tp-link"]
Ubiquiti Firmware: [ff_hh_versions grep="ubiquiti"]
```

79
bin/install-wp-tests.sh Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
exit 1
fi
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
WP_CORE_DIR=/tmp/wordpress/
set -ex
install_wp() {
mkdir -p $WP_CORE_DIR
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
wget -nv -O /tmp/wordpress.tar.gz http://wordpress.org/${ARCHIVE_NAME}.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
}
install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi
# set up testing suite
mkdir -p $WP_TESTS_DIR
cd $WP_TESTS_DIR
svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
}
install_db() {
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}
install_wp
install_test_suite
install_db

View file

@ -3,114 +3,264 @@
Plugin Name: Freifunk Hamburg Firmware List Shortcode Plugin Name: Freifunk Hamburg Firmware List Shortcode
Plugin URI: http://mschuette.name/ Plugin URI: http://mschuette.name/
Description: Defines shortcodes to display Freifunk Hamburg Firmware versions Description: Defines shortcodes to display Freifunk Hamburg Firmware versions
Version: 0.2 Version: 0.5dev
Author: Martin Schuette Author: Martin Schuette
Author URI: http://mschuette.name/ Author URI: http://mschuette.name/
Licence: 2-clause BSD Licence: 2-clause BSD
*/ */
define('FF_HH_STABLE_BASEDIR', 'http://gw09.hamburg.freifunk.net/stable/'); define( 'FF_HH_UPDATES_URL', 'https://updates.hamburg.freifunk.net/' );
define('FF_HH_CACHETIME', 15); define( 'FF_HH_CACHETIME', 1 );
/* gets metadata from URL, handles caching */ /* gets metadata from URL, handles caching */
function ff_hh_getmanifest ($basedir) { function ff_hh_getmanifest( $branch_url, $domain, $branch ) {
// Caching // Caching
if ( false === ( $manifest = get_transient( "ff_hh_manifest" ) ) ) { $cache_key = 'ff_hh_manifest_' . $domain . '_' . $branch;
$manifest = array(); if ( WP_DEBUG || ( false === ( $manifest = get_transient( $cache_key ) ) ) ) {
$input = wp_remote_retrieve_body( wp_remote_get($basedir . 'sysupgrade/manifest') ); $manifest = array();
foreach ( explode("\n", $input) as $line ) { $url = $branch_url . '/sysupgrade/' . $branch . '.manifest';
$ret = sscanf($line, '%s %s %s %s', $hw, $sw_ver, $hash, $filename); $http_response = wp_remote_get( $url ); // TODO: error handling
if ($ret === 4) { $input = wp_remote_retrieve_body( $http_response );
if (preg_match('/^(.*)-v(\d+)$/', $hw, $matches)) { foreach ( explode( "\n", $input ) as $line ) {
$hw = $matches[1]; $ret = sscanf( $line, '%s %s %s %s', $hw, $sw_ver, $hash, $filename );
$hw_ver = $matches[2]; if ( $ret === 4 ) {
} else { if ( preg_match( '/^(.*)-v(\d+)$/', $hw, $matches ) ) {
$hw_ver = '1'; $hw = $matches[1];
} $hw_ver = $matches[2];
$manifest[$hw][$hw_ver] = $filename; } else {
} $hw_ver = '1';
} }
$manifest[$hw][$hw_ver] = $filename;
}
}
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS; $cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
set_transient( "ff_hh_manifest", $manifest, $cachetime ); set_transient( $cache_key, $manifest, $cachetime );
} }
return $manifest; return $manifest;
} }
/* gets latest version from first manifest line */ /* gets latest version from first manifest line */
function ff_hh_getlatest ($basedir) { function ff_hh_getlatest( $branch_url, $domain, $branch ) {
// Caching // Caching
if ( false === ( $sw_ver = get_transient( "ff_hh_latestversion" ) ) ) { $cache_key = 'ff_hh_latestversion_' . $domain . '_' . $branch;
$sw_ver = 'unknown'; if ( false === ( $sw_ver = get_transient( $cache_key ) ) ) {
$input = wp_remote_retrieve_body( wp_remote_get($basedir . 'sysupgrade/manifest') ); $sw_ver = 'unknown';
foreach ( explode("\n", $input) as $line ) { $url = $branch_url . '/sysupgrade/' . $branch . '.manifest';
$ret = sscanf($line, '%s %s %s %s', $hw, $sw_ver, $hash, $filename); $input = wp_remote_retrieve_body( wp_remote_get( $url ) );
if ($ret === 4) { foreach ( explode( "\n", $input ) as $line ) {
// break processing on first matching line $ret = sscanf( $line, '%s %s %s %s', $hw, $sw_ver, $hash, $filename );
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS; if ( $ret === 4 ) {
set_transient( "ff_hh_latestversion", $sw_ver, $cachetime ); // break processing on first matching line
break; $cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
} set_transient( $cache_key, $sw_ver, $cachetime );
} break;
} }
return $sw_ver; }
}
return $sw_ver;
} }
if ( ! shortcode_exists( 'ff_hh_latestversion' ) ) { if ( ! shortcode_exists( 'ff_hh_latestversion' ) ) {
add_shortcode( 'ff_hh_latestversion', 'ff_hh_shortcode_latestversion'); add_shortcode( 'ff_hh_latestversion', 'ff_hh_shortcode_latestversion' );
} }
// Example: // Example:
// [ff_hh_latestversion] // [ff_hh_latestversion]
// [ff_hh_latestversion domain="ffhh-sued" branch="experimental"]
function ff_hh_shortcode_latestversion( $atts, $content, $name ) { function ff_hh_shortcode_latestversion( $atts, $content, $name ) {
$sw_ver = ff_hh_getlatest(FF_HH_STABLE_BASEDIR); $domain = 'ffhh';
$outstr = "<span class=\"ff $name\">$sw_ver</span>"; $branch = 'stable';
return $outstr; if ( is_array( $atts ) ) {
if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
$domain = $atts['domain'];
}
if ( array_key_exists( 'branch', $atts ) && ! empty( $atts['branch'] ) ) {
$branch = $atts['branch'];
}
}
$branch_url = FF_HH_UPDATES_URL . $domain . '/' . $branch;
if ( $domain === 'multi' ) { $branch_url = $branch_url . '/images'; }
$sw_ver = ff_hh_getlatest( $branch_url, $domain, $branch );
$outstr = "<span class=\"ff $name\">$sw_ver</span>";
return $outstr;
} }
if ( ! shortcode_exists( 'ff_hh_versions' ) ) { if ( ! shortcode_exists( 'ff_hh_versions' ) ) {
add_shortcode( 'ff_hh_versions', 'ff_hh_shortcode_versions'); add_shortcode( 'ff_hh_versions', 'ff_hh_shortcode_versions' );
} }
// Example: // Example:
// [ff_hh_versions] // [ff_hh_versions]
// [ff_hh_versions domain="ffhh-sued" branch="experimental" grep="ubiquiti"]
function ff_hh_shortcode_versions( $atts, $content, $name ) { function ff_hh_shortcode_versions( $atts, $content, $name ) {
$manifest = ff_hh_getmanifest(FF_HH_STABLE_BASEDIR); $domain = 'ffhh';
$branch = 'stable';
$grep = false;
$filter = false;
if ( is_array( $atts ) ) {
if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
$domain = $atts['domain'];
}
if ( array_key_exists( 'branch', $atts ) && ! empty( $atts['branch'] ) ) {
$branch = $atts['branch'];
}
if ( array_key_exists( 'grep', $atts ) && ! empty( $atts['grep'] ) ) {
$grep = $atts['grep'];
}
if ( array_key_exists( 'filter', $atts ) && ! empty( $atts['filter'] ) ) {
$filter = explode ( ',', $atts['filter'] );
}
}
$outstr = "<div class=\"ff $name\">"; $branch_url = FF_HH_UPDATES_URL . $domain . '/' . $branch;
$outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>'; if ( $domain === 'multi' ) { $branch_url = $branch_url . '/images'; }
$manifest = ff_hh_getmanifest( $branch_url, $domain, $branch );
foreach ($manifest as $hw => $versions) { $outstr = "<div class=\"ff $name\">";
// beautify HW model names $outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>';
if (!strncmp($hw, 'tp-link', 7)) {
$hw = strtoupper($hw);
$hw = str_replace('-', ' ', $hw);
$hw = str_replace('TP LINK TL ', 'TP-Link TL-', $hw);
} elseif (!strncmp($hw, 'ubiquiti', 8)) {
$hw = str_replace('-', ' ', $hw);
$hw = ucwords($hw);
}
$outstr .= sprintf('<tr><td>%s</td>', $hw);
// factory versions ksort($manifest);
$hw_ver_links = array(); foreach ( $manifest as $hw => $versions ) {
foreach ($versions as $hw_ver => $filename) { // select some models
$filename = str_replace('-sysupgrade', '', $filename); if ( $grep && ( false === strpos( $hw, $grep ) ) ) {
$hw_ver_links[] = sprintf('<a href="%s%s">%s.x</a>', continue;
FF_HH_STABLE_BASEDIR.'factory/', $filename, $hw_ver); }
} // filter others
$outstr .= '<td>Hardware Version ' . join(', ', $hw_ver_links) . '</td>'; if ( $filter ) {
$filtered = false;
foreach ( $filter as $flt ) {
if ( strpos ( $hw, $flt ) !== false ) {
$filtered = true;
break;
}
}
if ( $filtered ) {
continue;
}
}
// sysupgrade versions $hw = ff_hh_beautify_hw_name( $hw, $grep );
$hw_ver_links = array(); $outstr .= sprintf( "\n<tr><td>%s</td>", $hw );
foreach ($versions as $hw_ver => $filename) {
$hw_ver_links[] = sprintf('<a href="%s%s">%s.x</a>',
FF_HH_STABLE_BASEDIR.'sysupgrade/', $filename, $hw_ver);
}
$outstr .= '<td>Hardware Version ' . join(', ', $hw_ver_links) . '</td>';
$outstr .= '</tr>'; // factory versions
} $hw_ver_links = array();
foreach ( $versions as $hw_ver => $filename ) {
if ( strpos( $hw, 'Unifi Ac Pro' ) || strpos( $hw, 'Unifi Ac Lite' ) ) {
continue;
}
$outstr .= '</table>'; $filename = str_replace( '-sysupgrade', '', $filename );
$outstr .= '</div>'; if (strpos($filename,'netgear') !== false) {
// $outstr .= '<pre>'.print_r($manifest, true).'</pre>'; $filename = str_replace( '.bin', '.img', $filename );
return $outstr; $filename = str_replace( '.tar', '.img', $filename );
}
$hw_ver_links[] = sprintf(
'<a href="%s%s">%s.x</a>',
$branch_url . '/factory/',
$filename,
$hw_ver
);
}
if ( count($hw_ver_links) > 0) {
$outstr .= '<td>Hardware Ver. ' . join( ', ', $hw_ver_links ) . '</td>';
} else {
$outstr .= '<td><i>Benutze das Image</br>zur Aktualisierung</i></td>';
}
// sysupgrade versions
$hw_ver_links = array();
foreach ( $versions as $hw_ver => $filename ) {
$hw_ver_links[] = sprintf(
'<a href="%s%s">%s.x</a>',
$branch_url . '/sysupgrade/',
$filename,
$hw_ver
);
}
$outstr .= '<td>Hardware Ver. ' . join( ', ', $hw_ver_links ) . '</td>';
$outstr .= '</tr>';
}
$outstr .= '</table>';
$outstr .= '</div>';
// $outstr .= '<pre>'.print_r( $manifest, true ).'</pre>';
return $outstr;
}
// some crude rules to add capitalization and whitespace to the
// hardware model name.
// set $discard_vendor to strip the vendor name
// (used for single-vendor lists, e.g. $discard_vendor = 'tp-link' )
function ff_hh_beautify_hw_name( $hw, $discard_vendor = '' ) {
if ( ! strncmp( $hw, 'tp-link', 7 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', ' ', $hw );
$hw = str_replace( ' TL ', ' TL-', $hw );
} elseif ( ! strncmp( $hw, 'ubiquiti', 8 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = str_replace( 'bullet-m', 'bullet-m', $hw );
$hw = str_replace( '-', ' ', $hw );
$hw = ucwords( $hw );
} elseif ( ! strncmp( $hw, 'ubnt', 4 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = str_replace( 'erx', 'ER-X', $hw );
$hw = str_replace( 'sfp', 'SFP', $hw );
$hw = trim( $hw, ' -' );
$hw = ucwords( $hw );
} elseif ( ! strncmp( $hw, 'd-link', 6 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', ' ', $hw );
$hw = str_replace( ' DIR ', ' DIR-', $hw );
} elseif ( ! strncmp( $hw, 'linksys', 7 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', ' ', $hw );
$hw = str_replace( ' WRT', ' WRT-', $hw );
} elseif ( ! strncmp( $hw, 'buffalo', 7 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( 'HP-AG300H-WZR-600DHP', 'HP-AG300H & WZR-600DHP', $hw );
$hw = str_replace( '-WZR', 'WZR', $hw );
} elseif ( ! strncmp( $hw, 'netgear', 7 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, 'allnet', 6 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, 'gl-', 3 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, 'onion-omega', 11 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
} elseif ( ! strncmp( $hw, 'alfa', 4 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, 'wd', 2 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, '8devices', 8 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( 'CARAMBOLA2-BOARD', 'Carambola 2', $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, 'meraki', 6 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( 'meraki', '', $hw );
$hw = str_replace( '-', '', $hw );
} elseif ( ! strncmp( $hw, 'openmesh', 8 ) ) {
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
$hw = strtoupper( $hw );
$hw = str_replace( 'openmesh', '', $hw );
$hw = str_replace( '-', '', $hw );
}
return $hw;
} }

15
phpunit.xml Normal file
View file

@ -0,0 +1,15 @@
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

15
tests/bootstrap.php Normal file
View file

@ -0,0 +1,15 @@
<?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__ ) . '/../freifunk-versions.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
require $_tests_dir . '/includes/bootstrap.php';

23
tests/test-simple.php Normal file
View file

@ -0,0 +1,23 @@
<?php
class SimpleTests extends WP_UnitTestCase {
function test_beautify() {
$cmplist = array( // examples with and without grep param
array( 'tp-link-tl-wr740n-nd', '', 'TP-Link TL-WR740N ND' ),
array( 'tp-link-tl-wr740n-nd', 'tp-link', 'TL-WR740N ND' ),
array( 'tp-link-tl-wdr4300', '', 'TP-Link TL-WDR4300' ),
array( 'tp-link-tl-wdr4300', 'tp-link', 'TL-WDR4300' ),
array( 'ubiquiti-unifi', '', 'Ubiquiti Unifi' ),
array( 'ubiquiti-unifi', 'ubiquiti', 'Unifi' ),
array( 'ubiquiti-bullet-m', '', 'Ubiquiti Bullet M2' ),
array( 'ubiquiti-bullet-m', 'ubiquiti', 'Bullet M2' ),
array( 'd-link-dir-615-rev-e1', '', 'D-Link DIR-615 REV E1' ),
array( 'd-link-dir-615-rev-e1', 'd-link', 'DIR-615 REV E1' ),
);
foreach ( $cmplist as $item ) {
$expect = $item[2];
$result = ff_hh_beautify_hw_name( $item[0], $item[1] );
$this->assertEquals( $expect, trim( $result ) );
}
}
}