Skip to content

Commit

Permalink
Refactor tests to be object oriented.
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettrayj committed Apr 5, 2017
1 parent 80f9973 commit 8244e5e
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tests/*/*.php
tests/*/*.exp
tests/*/*.log
tests/*/*.sh
!tests/test_case.php
!tests/util/*
!tests/data/*

### Composer
Expand Down
Binary file modified header_graphic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 41 additions & 18 deletions tests/agg_renderer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,46 @@
--FILE--
<?php

// Setup
$configOutput = [];
exec('mapnik-config --input-plugins', $configOutput);
\Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
$map = new \Mapnik\Map(640, 480);
$basePath = realpath(dirname(__FILE__) . '/data');
$map->loadXmlFile($basePath . '/world.xml', false, $basePath);
$map->zoomAll();
$image = new \Mapnik\Image(640, 480);

// Assert AggRenderer instantiation
$renderer = new \Mapnik\AggRenderer($map, $image);
print ($renderer instanceof \Mapnik\AggRenderer);

// Assert apply() successful
print $renderer->apply();
require_once('util/test_case.php');

class AggRendererTest extends MapnikTestCase
{
private $basePath;

private $exampleMap;

public function setup()
{
$configOutput = [];
exec('mapnik-config --input-plugins', $configOutput);
\Mapnik\DatasourceCache::registerDatasources($configOutput[0]);

$this->basePath = realpath(__DIR__ . '/data');

$this->exampleMap = new \Mapnik\Map(640, 480);
$this->exampleMap->loadXmlFile($this->basePath . "/world.xml", false, $this->basePath);
$this->exampleMap->zoomAll();
}


public function testConstructor()
{
$image = new \Mapnik\Image(640, 480);
$renderer = new \Mapnik\AggRenderer($this->exampleMap, $image);

assert('$renderer instanceof \Mapnik\AggRenderer', 'Instantiating \Mapnik\AggRenderer failed.');
}

public function testApply()
{
$image = new \Mapnik\Image(640, 480);
$renderer = new \Mapnik\AggRenderer($this->exampleMap, $image);

assert('$renderer->apply() === true', 'AggRenderer->apply() failed.');
}
}

new AggRendererTest();

?>
--EXPECT--
11
--EXPECT--
42 changes: 37 additions & 5 deletions tests/box2d.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,42 @@
--FILE--
<?php

// Assert Box2D instantiation
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
print ($box2d instanceof \Mapnik\Box2D);
require_once('util/test_case.php');

class Box2DTest extends MapnikTestCase
{
public function testConstructor()
{
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
assert('$box2d instanceof \Mapnik\Box2D', 'Instantiating \Mapnik\Box2D failed.');
}

public function testMinX()
{
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
assert('$box2d->minX() === -180.0', 'Box2D->minX() failed.');
}

public function testMinY()
{
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
assert('$box2d->minY() === -90.0', 'Box2D->minY() failed.');
}

public function testMaxX()
{
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
assert('$box2d->maxX() === 180.0', 'Box2D->maxX() failed.');
}

public function testMaxY()
{
$box2d = new \Mapnik\Box2D(-180, -90, 180, 90);
assert('$box2d->maxY() === 90.0', 'Box2D->maxY() failed.');
}
}

new Box2DTest();

?>
--EXPECT--
1
--EXPECT--
6 changes: 0 additions & 6 deletions tests/data/header_graphic.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Map background-color="darkslateblue" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
<!--
<Style name="title_style">
<Rule>
<TextSymbolizer
Expand All @@ -13,7 +12,6 @@
</TextSymbolizer>
</Rule>
</Style>
-->
<Style name="world_style">
<Rule>
<PolygonSymbolizer fill="slateblue" />
Expand All @@ -28,15 +26,11 @@
<Parameter name="file">ne_110m_admin_0_countries.shp</Parameter>
</Datasource>
</Layer>
<!--
Boost dependency on Ubuntu Trusty (Travis CI) is below required version for CSV input plugin.
<Layer name="title" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
<StyleName>title_style</StyleName>
<Datasource>
<Parameter name="type">csv</Parameter>
<Parameter name="file">header_graphic.csv</Parameter>
</Datasource>
</Layer>
-->
</Map>
33 changes: 21 additions & 12 deletions tests/datasource_cache.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
--FILE--
<?php

// Assert no plugins registered at start
$plugins = \Mapnik\DatasourceCache::getPluginNames();
print (count($plugins) === 0);
require_once('util/test_case.php');

// Assert successful registration of datasource plugins
$configOutput = [];
exec('mapnik-config --input-plugins', $configOutput);
print \Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
class DatasourceCacheTest extends MapnikTestCase
{
public function testGetPluginNamesEmpty()
{
$plugins = \Mapnik\DatasourceCache::getPluginNames();
assert('count($plugins) === 0', 'DatasourceCache cache plugins not empty even though register was not called.');
}

// Assert that we have plugins now
$plugins = \Mapnik\DatasourceCache::getPluginNames();
print (count($plugins) > 0);
public function testRegisterDatasources()
{
$configOutput = [];
exec('mapnik-config --input-plugins', $configOutput);
\Mapnik\DatasourceCache::registerDatasources($configOutput[0]);
$plugins = \Mapnik\DatasourceCache::getPluginNames();

assert('count($plugins) > 0', 'No plugins after registering directory with DatasourceCache.');
}
}

new DatasourceCacheTest();

?>
--EXPECT--
111
--EXPECT--
52 changes: 33 additions & 19 deletions tests/header_graphic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,44 @@ Header Graphic

// Just a fun test to give the project a header graphic...

$pluginConfigOutput = [];
exec('mapnik-config --input-plugins', $pluginConfigOutput);
\Mapnik\DatasourceCache::registerDatasources($pluginConfigOutput[0]);
require_once('util/test_case.php');

$map = new \Mapnik\Map(1280, 320);
class HeaderGraphicTest extends MapnikTestCase
{
public function testMakeHeaderGraphic()
{
$pluginConfigOutput = [];
exec('mapnik-config --input-plugins', $pluginConfigOutput);
\Mapnik\DatasourceCache::registerDatasources($pluginConfigOutput[0]);

$fontConfigOutput = [];
exec('mapnik-config --fonts', $fontConfigOutput);
$map->registerFonts($fontConfigOutput[0]);
// Travis build machine does not have CSV plugin due to incompatible Boost version.
// Just return early if CSV isn't available.
if (!in_array('csv', \Mapnik\DatasourceCache::getPluginNames())) return;

$basePath = realpath(dirname(__FILE__) . '/data');
$map->loadXmlFile($basePath . '/header_graphic.xml', false, $basePath);
$map = new \Mapnik\Map(1280, 320);

$box = new \Mapnik\Box2D(-134, -25, 174, 67);
$map->zoomToBox($box);
$fontConfigOutput = [];
exec('mapnik-config --fonts', $fontConfigOutput);
$map->registerFonts($fontConfigOutput[0]);

$image = new \Mapnik\Image(1280, 320);
$renderer = new \Mapnik\AggRenderer($map, $image);
$renderer->apply();
$basePath = realpath(__DIR__ . '/data');
$map->loadXmlFile($basePath . '/header_graphic.xml', false, $basePath);

$imageFile = realpath(dirname(__FILE__) . '/../') . '/header_graphic.png';
$image->saveToFile($imageFile);
print file_exists($imageFile);
$box = new \Mapnik\Box2D(-134, -25, 174, 67);
$map->zoomToBox($box);

$image = new \Mapnik\Image(1280, 320);
$renderer = new \Mapnik\AggRenderer($map, $image);
$renderer->apply();

$imageFile = realpath(__DIR__ . '/../') . '/header_graphic.png';
$image->saveToFile($imageFile);

assert('file_exists($imageFile) === true', 'Header graphic does not exist.');
}
}

new HeaderGraphicTest();

?>
--EXPECT--
1
--EXPECT--
Loading

0 comments on commit 8244e5e

Please sign in to comment.