/** * @covers WeatherMap::processString */ public function testProcessString() { global $weathermap_debugging; $this->assertEquals("", $this->object->processString("", $this->object, true, false)); $this->assertEquals("dog", $this->object->processString("dog", $this->object, true, false)); $this->assertEquals("[UNKNOWN]", $this->object->processString("{map:randomstring}", $this->object, true, false)); $this->assertEquals("[UNKNOWN]", $this->object->processString("{node:randomstring}", $this->object, true, false)); $this->assertEquals("[UNKNOWN]", $this->object->processString("{link:randomstring}", $this->object, true, false)); // load a config file, so there are map objects to talk about $this->object->ReadConfig(dirname(__FILE__) . '/../../test-suite/tests/simple-link-1.conf'); // initialise the data, otherwise we'll get "" instead of 0 for bandwidth, etc $this->object->readData(); $n1 = $this->object->nodes['n1']; $l1 = $this->object->links['l1']; $this->assertInstanceOf("WeatherMapNode", $n1); $this->assertInstanceOf("WeatherMapLink", $l1); // $weathermap_debugging = TRUE; $n1->add_note("note1", "Data from another plugin"); $n1->add_hint("note2", "User input"); // testing notes-inclusion/exclusion $this->assertEquals("[UNKNOWN]", $this->object->processString("{node:this:note1}", $n1, false, false)); $this->assertEquals("Data from another plugin", $this->object->processString("{node:this:note1}", $n1, true, false)); // vs hints, which always work $this->assertEquals("User input", $this->object->processString("{node:this:note2}", $n1, false, false)); $this->assertEquals("User input", $this->object->processString("{node:this:note2}", $n1, true, false)); $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $n1, true, false)); $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $this->object, true, false)); $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $l1, true, false)); // hints "overwrite" internal variables $this->object->add_hint("title", "fish"); $this->assertEquals("fish", $this->object->processString("{map:title}", $n1, true, false)); // and notes might "overwrite" internal variables depending on where we are (not in TARGETs for example) $this->object->delete_hint("title"); $this->object->add_note("title", "cat"); $this->assertEquals("cat", $this->object->processString("{map:title}", $n1, true, false)); $this->assertEquals("Some Simple Links and Nodes", $this->object->processString("{map:title}", $n1, false, false)); $this->assertEquals("n1", $this->object->processString("{node:this:name}", $n1, true, false)); $this->assertEquals("l1", $this->object->processString("{link:this:name}", $l1, true, false)); $this->assertEquals("0", $this->object->processString("{node:this:bandwidth_in}", $n1, true, false)); $this->assertEquals("0", $this->object->processString("{link:this:bandwidth_in}", $l1, true, false)); $this->assertEquals("0", $this->object->processString("{node:n1:bandwidth_in}", $this->object, true, false)); $this->assertEquals("0", $this->object->processString("{link:l1:bandwidth_in}", $this->object, true, false)); }
/** * Run a config-based test. * Read in config from $conffile, and produce an image and HTML output * Optionally Produce a new config file in $newconffile (for testing WriteConfig) * Optionally collect config-keyword-coverage stats about this config file * * From: https://jtreminio.com/2013/03/unit-testing-tutorial-part-3-testing-protected-private-methods-coverage-reports-and-crap/ * * @param string $conffile * @param string $imagefile * @param string $htmlfile * @param string $newconffile * @param string $coveragefile */ public static function TestOutput_RunTest($conffile, $imagefile, $htmlfile, $newconffile) { global $WEATHERMAP_VERSION; $map = new WeatherMap(); $map->ReadConfig($conffile); $skip = 0; $nwarns = 0; if (!strstr($WEATHERMAP_VERSION, "dev")) { // Allow tests to be from the future. Global SET in test file can exempt test from running // SET REQUIRES_VERSION 0.98 // but don't check if the current version is a dev version $required_version = $map->get_hint("REQUIRES_VERSION"); if ($required_version != "") { // doesn't need to be complete, just in the right order $known_versions = array("0.97", "0.97a", "0.97b", "0.98"); $my_version = array_search($WEATHERMAP_VERSION, $known_versions); $req_version = array_search($required_version, $known_versions); if ($req_version > $my_version) { $skip = 1; $nwarns = -1; } } } if ($skip == 0) { $map->readData(); $map->drawMapImage($imagefile); $map->imagefile = $imagefile; if ($htmlfile != '') { OutputHTML($htmlfile, $map); } if ($newconffile != '') { $map->writeConfig($newconffile); } $nwarns = $map->warncount; } $map->cleanUp(); unset($map); return intval($nwarns); }