Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISFactory
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISFactory;
/**
* Test class for PMA\libraries\gis\GISFactory
*
* @package PhpMyAdmin-test
*/
class GISFactoryTest extends PHPUnit_Framework_TestCase
{
/**
* Test factory method
*
* @param string $type geometry type
* @param object $geom geometry object
*
* @dataProvider providerForTestFactory
* @return void
*/
public function testFactory($type, $geom)
{
$this->assertInstanceOf($geom, GISFactory::factory($type));
}
/**
* data provider for testFactory
*
* @return data for testFactory
*/
public function providerForTestFactory()
{
return array(
array(
'MULTIPOLYGON',
'PMA\libraries\gis\GISMultipolygon'
),
array(
'POLYGON',
'PMA\libraries\gis\GISPolygon'
),
array(
'MULTILINESTRING',
'PMA\libraries\gis\GISMultilinestring'
),
array(
'LINESTRING',
'PMA\libraries\gis\GISLinestring'
),
array(
'MULTIPOINT',
'PMA\libraries\gis\GISMultipoint'
),
array(
'POINT',
'PMA\libraries\gis\GISPoint'
),
array(
'GEOMETRYCOLLECTION',
'PMA\libraries\gis\GISGeometrycollection'
),
);
}
}

View File

@ -0,0 +1,70 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Abstract parent class for all PMA_GIS_<Geom_type> test classes
*
* @package PhpMyAdmin-test
*/
/**
* Abstract parent class for all GIS<Geom_type> test classes
*
* @package PhpMyAdmin-test
*/
abstract class GISGeomTest extends PHPUnit_Framework_TestCase
{
/**
* test generateParams method
*
* @param string $wkt point in WKT form
* @param int $index index
* @param array $params expected output array
*
* @dataProvider providerForTestGenerateParams
* @return void
*/
public function testGenerateParams($wkt, $index, $params)
{
if ($index == null) {
$this->assertEquals(
$params,
$this->object->generateParams($wkt)
);
} else {
$this->assertEquals(
$params,
$this->object->generateParams($wkt, $index)
);
}
}
/**
* test scaleRow method
*
* @param string $spatial spatial data of a row
* @param array $min_max expected results
*
* @dataProvider providerForTestScaleRow
* @return void
*/
public function testScaleRow($spatial, $min_max)
{
$this->assertEquals(
$min_max,
$this->object->scaleRow($spatial)
);
}
/**
* Tests whether content is a valid image.
*
* @param object $object Image
*
* @return void
*/
public function assertImage($object)
{
$this->assertGreaterThan(0, imagesx($object));
}
}

View File

@ -0,0 +1,340 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISGeometry
*
* @package PhpMyAdmin-test
*/
/**
* Tests for PMA\libraries\gis\GISGeometry class
*
* @package PhpMyAdmin-test
*/
class GISGeometryTest extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = $this->getMockForAbstractClass('PMA\libraries\gis\GISGeometry');
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Call protected functions by making the visibility to public.
*
* @param string $name method name
* @param array $params parameters for the invocation
*
* @return the output from the protected method.
*/
private function _callProtectedFunction($name, $params)
{
$class = new ReflectionClass('PMA\libraries\gis\GISGeometry');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method->invokeArgs($this->object, $params);
}
/**
* tests setMinMax method
*
* @param string $point_set Point set
* @param array $min_max Existing min, max values
* @param array $output Expected output array
*
* @dataProvider providerForTestSetMinMax
* @return void
*/
public function testSetMinMax($point_set, $min_max, $output)
{
$this->assertEquals(
$this->_callProtectedFunction(
'setMinMax',
array($point_set, $min_max)
),
$output
);
}
/**
* data provider for testSetMinMax
*
* @return data for testSetMinMax
*/
public function providerForTestSetMinMax()
{
return array(
array(
'12 35,48 75,69 23,25 45,14 53,35 78',
array(),
array(
'minX' => 12,
'maxX' => 69,
'minY' => 23,
'maxY' => 78
)
),
array(
'12 35,48 75,69 23,25 45,14 53,35 78',
array(
'minX' => 2,
'maxX' => 29,
'minY' => 23,
'maxY' => 128
),
array(
'minX' => 2,
'maxX' => 69,
'minY' => 23,
'maxY' => 128
)
)
);
}
/**
* tests generateParams method
*
* @param string $value Geometry data
* @param string $output Expected output
*
* @dataProvider providerForTestGenerateParams
* @return void
*/
public function testGenerateParams($value, $output)
{
$this->assertEquals(
$this->_callProtectedFunction(
'generateParams',
array($value)
),
$output
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
return array(
array(
"'MULTIPOINT(125 50,156 25,178 43,175 80)',125",
array(
'srid' => '125',
'wkt' => 'MULTIPOINT(125 50,156 25,178 43,175 80)',
),
),
array(
'MULTIPOINT(125 50,156 25,178 43,175 80)',
array(
'srid' => '0',
'wkt' => 'MULTIPOINT(125 50,156 25,178 43,175 80)',
),
),
array(
"foo",
array(
'srid' => '0',
'wkt' => '',
),
),
);
}
/**
* tests extractPoints method
*
* @param string $point_set String of comma separated points
* @param array $scale_data Data related to scaling
* @param boolean $linear If true, as a 1D array, else as a 2D array
* @param array $output Expected output
*
* @dataProvider providerForTestExtractPoints
* @return void
*/
public function testExtractPoints($point_set, $scale_data, $linear, $output)
{
$this->assertEquals(
$this->_callProtectedFunction(
'extractPoints',
array($point_set, $scale_data, $linear)
),
$output
);
}
/**
* data provider for testExtractPoints
*
* @return data for testExtractPoints
*/
public function providerForTestExtractPoints()
{
return array(
// with no scale data
array(
'12 35,48 75,69 23',
null,
false,
array(
0 => array(12, 35),
1 => array(48, 75),
2 => array(69, 23),
),
),
// with scale data
array(
'12 35,48 75,69 23',
array(
'x' => 5,
'y' => 5,
'scale' => 2,
'height' => 200,
),
false,
array(
0 => array(14, 140),
1 => array(86, 60),
2 => array(128, 164),
),
),
// linear output
array(
'12 35,48 75,69 23',
null,
true,
array(12, 35, 48, 75, 69, 23),
),
// if a single part of a coordinate is empty
array(
'12 35,48 75,69 ',
null,
false,
array(
0 => array(12, 35),
1 => array(48, 75),
2 => array('', ''),
),
),
);
}
/**
* test case for getBoundsForOl() method
*
* @param string $srid spatial reference ID
* @param array $scale_data data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForTestGetBoundsForOl
*/
public function testGetBoundsForOl($srid, $scale_data, $output)
{
$this->assertEquals(
$this->_callProtectedFunction(
'getBoundsForOl',
array($srid, $scale_data)
),
$output
);
}
/**
* data provider for testGetBoundsForOl() test case
*
* @return array test data for the testGetBoundsForOl() test case
*/
public function providerForTestGetBoundsForOl()
{
return array(
array(
4326,
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); '
. 'bound.extend(new OpenLayers.LonLat(0, 0).transform('
. 'new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); '
. 'bound.extend(new OpenLayers.LonLat(1, 1).transform('
. 'new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()));'
)
);
}
/**
* test case for getPolygonArrayForOpenLayers() method
*
* @param array $polygons x and y coordinate pairs for each polygon
* @param string $srid spatial reference id
* @param string $output expected output
*
* @return void
* @dataProvider providerForTestGetPolygonArrayForOpenLayers
*/
public function testGetPolygonArrayForOpenLayers($polygons, $srid, $output)
{
$this->assertEquals(
$this->_callProtectedFunction(
'getPolygonArrayForOpenLayers',
array($polygons, $srid)
),
$output
);
}
/**
* data provider for testGetPolygonArrayForOpenLayers() test case
*
* @return array test data for testGetPolygonArrayForOpenLayers() test case
*/
public function providerForTestGetPolygonArrayForOpenLayers()
{
return array(
array(
array('Triangle'),
4326,
'new Array('
. 'new OpenLayers.Geometry.Polygon('
. 'new Array('
. 'new OpenLayers.Geometry.LinearRing('
. 'new Array('
. '(new OpenLayers.Geometry.Point(,)).transform('
. 'new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()))))))'
)
);
}
}

View File

@ -0,0 +1,405 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISGeometry
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISGeometrycollection;
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISGeometrycollection class
*
* @package PhpMyAdmin-test
*/
class GISGeometryCollectionTest extends PHPUnit_Framework_TestCase
{
/**
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISGeometrycollection::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Test for scaleRow
*
* @param string $spatial string to parse
* @param array $output expected parsed output
*
* @return void
*
* @dataProvider providerForScaleRow
*/
public function testScaleRow($spatial, $output)
{
$this->assertEquals($output, $this->object->scaleRow($spatial));
}
/**
* Data provider for testScaleRow() test case
*
* @return array test data for testScaleRow() test case
*/
public function providerForScaleRow()
{
return array(
array(
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
array(
'maxX' => 45.0,
'minX' => 10.0,
'maxY' => 45.0,
'minY' => 10.0
)
)
);
}
/**
* Test for generateWkt
*
* @param array $gis_data array of GIS data
* @param integer $index index in $gis_data
* @param string $empty empty parameter
* @param string $output expected output
*
* @return void
*
* @dataProvider providerForGenerateWkt
*/
public function testGenerateWkt($gis_data, $index, $empty, $output)
{
$this->assertEquals(
$output,
$this->object->generateWkt($gis_data, $index, $empty)
);
}
/**
* Data provider for testGenerateWkt() test case
*
* @return array test data for testGenerateWkt() test case
*/
public function providerForGenerateWkt()
{
$temp1 = array(
0 => array(
'gis_type' => 'LINESTRING',
'LINESTRING' => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
)
)
);
return array(
array(
$temp1,
0,
null,
'GEOMETRYCOLLECTION(LINESTRING(5.02 8.45,6.14 0.15))'
)
);
}
/**
* Test for generateParams
*
* @param string $value string to parse
* @param array $output expected parsed output
*
* @return void
*
* @dataProvider providerForGenerateParams
*/
public function testGenerateParams($value, $output)
{
$this->assertEquals($output, $this->object->generateParams($value));
}
/**
* Data provider for testGenerateParams() test case
*
* @return array test data for testGenerateParams() test case
*/
public function providerForGenerateParams()
{
return array(
array(
'GEOMETRYCOLLECTION(LINESTRING(5.02 8.45,6.14 0.15))',
array(
'srid' => 0,
'GEOMETRYCOLLECTION' => array('geom_count' => 1),
'0' => array(
'gis_type' => 'LINESTRING',
'LINESTRING' => array(
'no_of_points' => 2,
'0' => array(
'x' => 5.02,
'y' => 8.45
),
'1' => array(
'x' => 6.14,
'y' => 0.15
)
)
)
),
),
);
}
/**
* Test for prepareRowAsPng
*
* @param string $spatial string to parse
* @param string $label field label
* @param string $line_color line color
* @param array $scale_data scaling parameters
* @param resource $image initial image
*
* @return void
*
* @dataProvider providerForPrepareRowAsPng
*/
public function testPrepareRowAsPng(
$spatial, $label, $line_color, $scale_data, $image
) {
$return = $this->object->prepareRowAsPng(
$spatial, $label, $line_color, $scale_data, $image
);
$this->assertEquals(120, imagesx($return));
$this->assertEquals(150, imagesy($return));
}
/**
* Data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150')
)
);
}
/**
* Test for prepareRowAsPdf
*
* @param string $spatial string to parse
* @param string $label field label
* @param string $line_color line color
* @param array $scale_data scaling parameters
* @param string $pdf expected output
*
* @return void
*
* @dataProvider providerForPrepareRowAsPdf
*/
public function testPrepareRowAsPdf(
$spatial, $label, $line_color, $scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $line_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* Data provider for testPrepareRowAsPdf() test case
*
* @return array test data for testPrepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new \TCPDF(),
)
);
}
/**
* Test for prepareRowAsSvg
*
* @param string $spatial string to parse
* @param string $label field label
* @param string $line_color line color
* @param array $scale_data scaling parameters
* @param string $output expected output
*
* @return void
*
* @dataProvider providerForPrepareRowAsSvg
*/
public function testPrepareRowAsSvg(
$spatial, $label, $line_color, $scale_data, $output
) {
$string = $this->object->prepareRowAsSvg(
$spatial, $label, $line_color, $scale_data
);
$this->assertEquals(1, preg_match($output, $string));
$this->assertRegExp(
$output,
$this->object->prepareRowAsSvg(
$spatial, $label, $line_color, $scale_data
)
);
}
/**
* Data provider for testPrepareRowAsSvg() test case
*
* @return array test data for testPrepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
'/^(<path d=" M 46, 268 L -4, 248 L 6, 208 L 66, 198 Z M 16,'
. ' 228 L 46, 224 L 36, 248 Z " name="svg" id="svg)(\d+)'
. '(" class="polygon vector" stroke="black" stroke-width="0.5"'
. ' fill="#B02EE0" fill-rule="evenodd" fill-opacity="0.8"\/>)$/'
)
);
}
/**
* Test for prepareRowAsOl
*
* @param string $spatial string to parse
* @param integer $srid SRID
* @param string $label field label
* @param string $line_color line color
* @param array $scale_data scaling parameters
* @param string $output expected output
*
* @return void
*
* @dataProvider providerForPrepareRowAsOl
*/
public function testPrepareRowAsOl(
$spatial, $srid, $label, $line_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $line_color, $scale_data
)
);
}
/**
* Data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'GEOMETRYCOLLECTION(POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326'
. '"), map.getProjectionObject())); bound.extend(new OpenLayer'
. 's.LonLat(1, 1).transform(new OpenLayers.Projection("EPSG:43'
. '26"), map.getProjectionObject()));vectorLayer.addFeatures(n'
. 'ew OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygo'
. 'n(new Array(new OpenLayers.Geometry.LinearRing(new Array((n'
. 'ew OpenLayers.Geometry.Point(35,10)).transform(new OpenLaye'
. 'rs.Projection("EPSG:4326"), map.getProjectionObject()), (ne'
. 'w OpenLayers.Geometry.Point(10,20)).transform(new OpenLayer'
. 's.Projection("EPSG:4326"), map.getProjectionObject()), (new'
. ' OpenLayers.Geometry.Point(15,40)).transform(new OpenLayers.'
. 'Projection("EPSG:4326"), map.getProjectionObject()), (new O'
. 'penLayers.Geometry.Point(45,45)).transform(new OpenLayers.P'
. 'rojection("EPSG:4326"), map.getProjectionObject()), (new Op'
. 'enLayers.Geometry.Point(35,10)).transform(new OpenLayers.Pr'
. 'ojection("EPSG:4326"), map.getProjectionObject()))), new Op'
. 'enLayers.Geometry.LinearRing(new Array((new OpenLayers.Geom'
. 'etry.Point(20,30)).transform(new OpenLayers.Projection("EPS'
. 'G:4326"), map.getProjectionObject()), (new OpenLayers.Geome'
. 'try.Point(35,32)).transform(new OpenLayers.Projection("EPSG'
. ':4326"), map.getProjectionObject()), (new OpenLayers.Geomet'
. 'ry.Point(30,20)).transform(new OpenLayers.Projection("EPSG:'
. '4326"), map.getProjectionObject()), (new OpenLayers.Geometry'
. '.Point(20,30)).transform(new OpenLayers.Projection("EPSG:43'
. '26"), map.getProjectionObject()))))), null, {"strokeColor":'
. '"#000000","strokeWidth":0.5,"fillColor":"#B02EE0","fillOpac'
. 'ity":0.8,"label":"Ol","fontSize":10}));'
)
);
}
}

View File

@ -0,0 +1,366 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISLinestring
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISLinestring;
require_once 'GISGeomTest.php';
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISLinestring class
*
* @package PhpMyAdmin-test
*/
class GISLinestringTest extends GISGeomTest
{
/**
* @var GISLinestring
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISLinestring::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* data provider for testGenerateWkt
*
* @return data for testGenerateWkt
*/
public function providerForTestGenerateWkt()
{
$temp1 = array(
0 => array(
'LINESTRING' => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
)
)
);
$temp2 = $temp1;
$temp2[0]['LINESTRING']['no_of_points'] = 3;
$temp2[0]['LINESTRING'][2] = array('x' => 1.56);
$temp3 = $temp2;
$temp3[0]['LINESTRING']['no_of_points'] = -1;
$temp4 = $temp3;
$temp4[0]['LINESTRING']['no_of_points'] = 3;
unset($temp4[0]['LINESTRING'][2]['x']);
return array(
array(
$temp1,
0,
null,
'LINESTRING(5.02 8.45,6.14 0.15)'
),
// if a coordinate is missing, default is empty string
array(
$temp2,
0,
null,
'LINESTRING(5.02 8.45,6.14 0.15,1.56 )'
),
// if no_of_points is not valid, it is considered as 2
array(
$temp3,
0,
null,
'LINESTRING(5.02 8.45,6.14 0.15)'
),
// missing coordinates are replaced with provided values (3rd parameter)
array(
$temp4,
0,
'0',
'LINESTRING(5.02 8.45,6.14 0.15,0 0)'
)
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
$temp = array(
'LINESTRING' => array(
'no_of_points' => 2,
0 => array('x' => '5.02', 'y' => '8.45'),
1 => array('x' => '6.14', 'y' => '0.15')
)
);
$temp1 = $temp;
$temp1['gis_type'] = 'LINESTRING';
return array(
array(
"'LINESTRING(5.02 8.45,6.14 0.15)',124",
null,
array(
'srid' => '124',
0 => $temp
)
),
array(
'LINESTRING(5.02 8.45,6.14 0.15)',
2,
array(
2 => $temp1
)
)
);
}
/**
* data provider for testScaleRow
*
* @return data for testScaleRow
*/
public function providerForTestScaleRow()
{
return array(
array(
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
array(
'minX' => 12,
'maxX' => 69,
'minY' => 23,
'maxY' => 78
)
)
);
}
/**
* test case for prepareRowAsPng() method
*
* @param string $spatial GIS LINESTRING object
* @param string $label label for the GIS LINESTRING object
* @param string $line_color color for the GIS LINESTRING object
* @param array $scale_data array containing data related to scaling
* @param object $image image object
*
* @dataProvider providerForPrepareRowAsPng
* @return void
*/
public function testPrepareRowAsPng($spatial, $label, $line_color,
$scale_data, $image
) {
$this->object->prepareRowAsPng(
$spatial, $label, $line_color, $scale_data, $image
);
/* TODO: this never fails */
$this->assertTrue(true);
}
/**
* data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150')
)
);
}
/**
* test case for prepareRowAsPdf() method
*
* @param string $spatial GIS LINESTRING object
* @param string $label label for the GIS LINESTRING object
* @param string $line_color color for the GIS LINESTRING object
* @param array $scale_data array containing data related to scaling
* @param object $pdf TCPDF instance
*
* @dataProvider providerForPrepareRowAsPdf
* @return void
*/
public function testPrepareRowAsPdf($spatial, $label, $line_color,
$scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $line_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* data provider for testPrepareRowAsPdf() test case
*
* @return array test data for testPrepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new TCPDF(),
)
);
}
/**
* test case for prepareRowAsSvg() method
*
* @param string $spatial GIS LINESTRING object
* @param string $label label for the GIS LINESTRING object
* @param string $line_color color for the GIS LINESTRING object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @dataProvider providerForPrepareRowAsSvg
* @return void
*/
public function testPrepareRowAsSvg($spatial, $label, $line_color,
$scale_data, $output
) {
$string = $this->object->prepareRowAsSvg(
$spatial, $label, $line_color, $scale_data
);
$this->assertEquals(1, preg_match($output, $string));
}
/**
* data provider for testPrepareRowAsSvg() test case
*
* @return array test data for testPrepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
'/^(<polyline points="0,218 72,138 114,242 26,198 4,182 46,132 " '
. 'name="svg" id="svg)(\d+)(" class="linestring vector" fill="none" '
. 'stroke="#B02EE0" stroke-width="2"\/>)$/'
)
);
}
/**
* test case for prepareRowAsOl() method
*
* @param string $spatial GIS LINESTRING object
* @param int $srid spatial reference ID
* @param string $label label for the GIS LINESTRING object
* @param string $line_color color for the GIS LINESTRING object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @dataProvider providerForPrepareRowAsOl
* @return void
*/
public function testPrepareRowAsOl($spatial, $srid, $label,
$line_color, $scale_data, $output
) {
$this->assertEquals(
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $line_color, $scale_data
),
$output
);
}
/**
* data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.get'
. 'ProjectionObject()));vectorLayer.addFeatures(new OpenLayers.Feat'
. 'ure.Vector(new OpenLayers.Geometry.LineString(new Array((new Open'
. 'Layers.Geometry.Point(12,35)).transform(new OpenLayers.Projection'
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.Geome'
. 'try.Point(48,75)).transform(new OpenLayers.Projection("EPSG:4326"'
. '), map.getProjectionObject()), (new OpenLayers.Geometry.Point(69'
. ',23)).transform(new OpenLayers.Projection("EPSG:4326"), map.'
. 'getProjectionObject()), (new OpenLayers.Geometry.Point(25,45)).'
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.'
. 'getProjectionObject()), (new OpenLayers.Geometry.Point(14,53)).'
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.get'
. 'ProjectionObject()), (new OpenLayers.Geometry.Point(35,78)).'
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.'
. 'getProjectionObject()))), null, {"strokeColor":"#B02EE0",'
. '"strokeWidth":2,"label":"Ol","fontSize":10}));'
)
);
}
}

View File

@ -0,0 +1,430 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISMultilinestring
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISMultilinestring;
require_once 'GISGeomTest.php';
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISMultilinestring class
*
* @package PhpMyAdmin-test
*/
class GISMultilinestringTest extends GISGeomTest
{
/**
* @var GISMultilinestring
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISMultilinestring::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* data provider for testGenerateWkt
*
* @return data for testGenerateWkt
*/
public function providerForTestGenerateWkt()
{
$temp = array(
0 => array(
'MULTILINESTRING' => array(
'no_of_lines' => 2,
0 => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
),
1 => array(
'no_of_points' => 2,
0 => array('x' => 1.23, 'y' => 4.25),
1 => array('x' => 9.15, 'y' => 0.47)
)
)
)
);
$temp1 = $temp;
unset($temp1[0]['MULTILINESTRING'][1][1]['y']);
$temp2 = $temp;
$temp2[0]['MULTILINESTRING']['no_of_lines'] = 0;
$temp3 = $temp;
$temp3[0]['MULTILINESTRING'][1]['no_of_points'] = 1;
return array(
array(
$temp,
0,
null,
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'
),
// values at undefined index
array(
$temp,
1,
null,
'MULTILINESTRING(( , ))'
),
// if a coordinate is missing, default is empty string
array(
$temp1,
0,
null,
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 ))'
),
// missing coordinates are replaced with provided values (3rd parameter)
array(
$temp1,
0,
'0',
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0))'
),
// at least one line should be there
array(
$temp2,
0,
null,
'MULTILINESTRING((5.02 8.45,6.14 0.15))'
),
// a line should have at least two points
array(
$temp3,
0,
'0',
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'
),
);
}
/**
* test getShape method
*
* @return void
*/
public function testGetShape()
{
$row_data = array(
'numparts' => 2,
'parts' => array(
0 => array(
'points' => array(
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15),
),
),
1 => array(
'points' => array(
0 => array('x' => 1.23, 'y' => 4.25),
1 => array('x' => 9.15, 'y' => 0.47),
),
),
),
);
$this->assertEquals(
$this->object->getShape($row_data),
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))'
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
$temp = array(
'MULTILINESTRING' => array(
'no_of_lines' => 2,
0 => array(
'no_of_points' => 2,
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15),
),
1 => array(
'no_of_points' => 2,
0 => array('x' => 1.23, 'y' => 4.25),
1 => array('x' => 9.15, 'y' => 0.47),
)
)
);
$temp1 = $temp;
$temp1['gis_type'] = 'MULTILINESTRING';
return array(
array(
"'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))',124",
null,
array(
'srid' => '124',
0 => $temp
)
),
array(
'MULTILINESTRING((5.02 8.45,6.14 0.15),(1.23 4.25,9.15 0.47))',
2,
array(
2 => $temp1
)
)
);
}
/**
* data provider for testScaleRow
*
* @return data for testScaleRow
*/
public function providerForTestScaleRow()
{
return array(
array(
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
array(
'minX' => 17,
'maxX' => 178,
'minY' => 10,
'maxY' => 75
)
)
);
}
/**
* test case for prepareRowAsPng() method
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label label for the GIS MULTILINESTRING object
* @param string $line_color color for the GIS MULTILINESTRING object
* @param array $scale_data array containing data related to scaling
* @param object $image image object
*
* @return void
* @dataProvider providerForPrepareRowAsPng
*/
public function testPrepareRowAsPng(
$spatial, $label, $line_color, $scale_data, $image
) {
$this->object->prepareRowAsPng(
$spatial, $label, $line_color, $scale_data, $image
);
/* TODO: this never fails */
$this->assertTrue(true);
}
/**
* data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150')
)
);
}
/**
* test case for prepareRowAsPdf() method
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label label for the GIS MULTILINESTRING object
* @param string $line_color color for the GIS MULTILINESTRING object
* @param array $scale_data array containing data related to scaling
* @param object $pdf TCPDF instance
*
* @return void
* @dataProvider providerForPrepareRowAsPdf
*/
public function testPrepareRowAsPdf(
$spatial, $label, $line_color, $scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $line_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* data provider for testPrepareRowAsPdf() test case
*
* @return array test data for testPrepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new TCPDF(),
)
);
}
/**
* test case for prepareRowAsSvg() method
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label label for the GIS MULTILINESTRING object
* @param string $line_color color for the GIS MULTILINESTRING object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsSvg
*/
public function testPrepareRowAsSvg(
$spatial, $label, $line_color, $scale_data, $output
) {
$string = $this->object->prepareRowAsSvg(
$spatial, $label, $line_color, $scale_data
);
$this->assertEquals(1, preg_match($output, $string));
}
/**
* data provider for testPrepareRowAsSvg() test case
*
* @return array test data for testPrepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
'/^(<polyline points="48,260 70,242 100,138 " name="svg" '
. 'class="linestring vector" fill="none" stroke="#B02EE0" '
. 'stroke-width="2" id="svg)(\d+)("\/><polyline points="48,268 10,'
. '242 332,182 " name="svg" class="linestring vector" fill="none" '
. 'stroke="#B02EE0" stroke-width="2" id="svg)(\d+)("\/>)$/'
)
);
}
/**
* test case for prepareRowAsOl() method
*
* @param string $spatial GIS MULTILINESTRING object
* @param int $srid spatial reference ID
* @param string $label label for the GIS MULTILINESTRING object
* @param string $line_color color for the GIS MULTILINESTRING object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsOl
*/
public function testPrepareRowAsOl(
$spatial, $srid, $label, $line_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $line_color, $scale_data
)
);
}
/**
* data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'MULTILINESTRING((36 14,47 23,62 75),(36 10,17 23,178 53))',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.'
. 'getProjectionObject()));vectorLayer.addFeatures(new OpenLayers.'
. 'Feature.Vector(new OpenLayers.Geometry.MultiLineString(new Arr'
. 'ay(new OpenLayers.Geometry.LineString(new Array((new OpenLayers.'
. 'Geometry.Point(36,14)).transform(new OpenLayers.Projection("EPSG:'
. '4326"), map.getProjectionObject()), (new OpenLayers.Geometry.Po'
. 'int(47,23)).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(62,75)'
. ').transform(new OpenLayers.Projection("EPSG:4326"), map.getProjec'
. 'tionObject()))), new OpenLayers.Geometry.LineString(new Array(('
. 'new OpenLayers.Geometry.Point(36,10)).transform(new OpenLayers.'
. 'Projection("EPSG:4326"), map.getProjectionObject()), (new Open'
. 'Layers.Geometry.Point(17,23)).transform(new OpenLayers.Projection'
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.Geo'
. 'metry.Point(178,53)).transform(new OpenLayers.Projection("EPSG:'
. '4326"), map.getProjectionObject()))))), null, {"strokeColor":"'
. '#B02EE0","strokeWidth":2,"label":"Ol","fontSize":10}));'
)
);
}
}

View File

@ -0,0 +1,379 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISMultipoint
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISMultipoint;
require_once 'GISGeomTest.php';
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISMultipoint class
*
* @package PhpMyAdmin-test
*/
class GISMultipointTest extends GISGeomTest
{
/**
* @var GISMultipoint
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISMultipoint::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* data provider for testGenerateWkt
*
* @return data for testGenerateWkt
*/
public function providerForTestGenerateWkt()
{
$gis_data1 = array(
0 => array(
'MULTIPOINT' => array(
'no_of_points' => 2,
0 => array(
'x' => 5.02,
'y' => 8.45
),
1 => array(
'x' => 1.56,
'y' => 4.36
)
)
)
);
$gis_data2 = $gis_data1;
$gis_data2[0]['MULTIPOINT']['no_of_points'] = -1;
return array(
array(
$gis_data1,
0,
null,
'MULTIPOINT(5.02 8.45,1.56 4.36)'
),
array(
$gis_data2,
0,
null,
'MULTIPOINT(5.02 8.45)'
)
);
}
/**
* test getShape method
*
* @return void
*/
public function testGetShape()
{
$gis_data = array(
'numpoints' => 2,
'points' => array(
0 => array('x' => 5.02, 'y' => 8.45),
1 => array('x' => 6.14, 'y' => 0.15)
)
);
$this->assertEquals(
$this->object->getShape($gis_data),
'MULTIPOINT(5.02 8.45,6.14 0.15)'
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
$temp1 = array(
'MULTIPOINT' => array(
'no_of_points' => 2,
0 => array('x' => '5.02', 'y' => '8.45'),
1 => array('x' => '6.14', 'y' => '0.15')
)
);
$temp2 = $temp1;
$temp2['gis_type'] = 'MULTIPOINT';
return array(
array(
"'MULTIPOINT(5.02 8.45,6.14 0.15)',124",
null,
array(
'srid' => '124',
0 => $temp1
)
),
array(
'MULTIPOINT(5.02 8.45,6.14 0.15)',
2,
array(
2 => $temp2
)
)
);
}
/**
* data provider for testScaleRow
*
* @return data for testScaleRow
*/
public function providerForTestScaleRow()
{
return array(
array(
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
array(
'minX' => 12,
'maxX' => 69,
'minY' => 23,
'maxY' => 78
)
)
);
}
/**
* test case for prepareRowAsPng() method
*
* @param string $spatial GIS MULTIPOINT object
* @param string $label label for the GIS MULTIPOINT object
* @param string $point_color color for the GIS MULTIPOINT object
* @param array $scale_data array containing data related to scaling
* @param object $image image object
*
* @return void
* @dataProvider providerForPrepareRowAsPng
*/
public function testPrepareRowAsPng(
$spatial, $label, $point_color, $scale_data, $image
) {
$return = $this->object->prepareRowAsPng(
$spatial, $label, $point_color, $scale_data, $image
);
$this->assertImage($return);
}
/**
* data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150'),
)
);
}
/**
* test case for prepareRowAsPdf() method
*
* @param string $spatial GIS MULTIPOINT object
* @param string $label label for the GIS MULTIPOINT object
* @param string $point_color color for the GIS MULTIPOINT object
* @param array $scale_data array containing data related to scaling
* @param object $pdf TCPDF instance
*
* @return void
* @dataProvider providerForPrepareRowAsPdf
*/
public function testPrepareRowAsPdf(
$spatial, $label, $point_color, $scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $point_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* data provider for testPrepareRowAsPdf() test case
*
* @return array test data for testPrepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new TCPDF(),
)
);
}
/**
* test case for prepareRowAsSvg() method
*
* @param string $spatial GIS MULTIPOINT object
* @param string $label label for the GIS MULTIPOINT object
* @param string $point_color color for the GIS MULTIPOINT object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsSvg
*/
public function testPrepareRowAsSvg(
$spatial, $label, $point_color, $scale_data, $output
) {
$string = $this->object->prepareRowAsSvg(
$spatial, $label, $point_color, $scale_data
);
$this->assertEquals(1, preg_match($output, $string));
}
/**
* data provider for testPrepareRowAsSvg() test case
*
* @return array test data for testPrepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
'/^(<circle cx="72" cy="138" r="3" name="svg" class="multipoint '
. 'vector" fill="white" stroke="#B02EE0" stroke-width="2" id="svg)'
. '(\d+)("\/><circle cx="114" cy="242" r="3" name="svg" class="mult'
. 'ipoint vector" fill="white" stroke="#B02EE0" stroke-width="2" id'
. '="svg)(\d+)("\/><circle cx="26" cy="198" r="3" name="svg" class='
. '"multipoint vector" fill="white" stroke="#B02EE0" stroke-width='
. '"2" id="svg)(\d+)("\/><circle cx="4" cy="182" r="3" name="svg" '
. 'class="multipoint vector" fill="white" stroke="#B02EE0" stroke-'
. 'width="2" id="svg)(\d+)("\/><circle cx="46" cy="132" r="3" name='
. '"svg" class="multipoint vector" fill="white" stroke="#B02EE0" '
. 'stroke-width="2" id="svg)(\d+)("\/>)$/'
)
);
}
/**
* test case for prepareRowAsOl() method
*
* @param string $spatial GIS MULTIPOINT object
* @param int $srid spatial reference ID
* @param string $label label for the GIS MULTIPOINT object
* @param string $point_color color for the GIS MULTIPOINT object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsOl
*/
public function testPrepareRowAsOl(
$spatial, $srid, $label, $point_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $point_color, $scale_data
)
);
}
/**
* data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'MULTIPOINT(12 35,48 75,69 23,25 45,14 53,35 78)',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.Lon'
. 'Lat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.'
. 'getProjectionObject()));vectorLayer.addFeatures(new OpenLayers.'
. 'Feature.Vector(new OpenLayers.Geometry.MultiPoint(new Array(('
. 'new OpenLayers.Geometry.Point(12,35)).transform(new OpenLayers.'
. 'Projection("EPSG:4326"), map.getProjectionObject()), (new Open'
. 'Layers.Geometry.Point(48,75)).transform(new OpenLayers.Projec'
. 'tion("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
. 'Geometry.Point(69,23)).transform(new OpenLayers.Projection("'
. 'EPSG:4326"), map.getProjectionObject()), (new OpenLayers.Geometry'
. '.Point(25,45)).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(14,53)'
. ').transform(new OpenLayers.Projection("EPSG:4326"), map.getProjec'
. 'tionObject()), (new OpenLayers.Geometry.Point(35,78)).transform'
. '(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject('
. ')))), null, {"pointRadius":3,"fillColor":"#ffffff","strokeColor"'
. ':"#B02EE0","strokeWidth":2,"label":"Ol","labelYOffset":-8,'
. '"fontSize":10}));'
)
);
}
}

View File

@ -0,0 +1,487 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISMultipolygon
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISMultipolygon;
require_once 'GISGeomTest.php';
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISMultipolygon class
*
* @package PhpMyAdmin-test
*/
class GISMultipolygonTest extends GISGeomTest
{
/**
* @var GISMultipolygon
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISMultipolygon::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Provide some common data to data providers
*
* @return array common data for data providers
*/
private function _getData()
{
return array(
'MULTIPOLYGON' => array(
'no_of_polygons' => 2,
0 => array(
'no_of_lines' => 2,
0 => array(
'no_of_points' => 5,
0 => array('x' => 35, 'y' => 10),
1 => array('x' => 10, 'y' => 20),
2 => array('x' => 15, 'y' => 40),
3 => array('x' => 45, 'y' => 45),
4 => array('x' => 35, 'y' => 10),
),
1 => array(
'no_of_points' => 4,
0 => array('x' => 20, 'y' => 30),
1 => array('x' => 35, 'y' => 32),
2 => array('x' => 30, 'y' => 20),
3 => array('x' => 20, 'y' => 30),
)
),
1 => array(
'no_of_lines' => 1,
0 => array(
'no_of_points' => 4,
0 => array('x' => 123, 'y' => 0),
1 => array('x' => 23, 'y' => 30),
2 => array('x' => 17, 'y' => 63),
3 => array('x' => 123, 'y' => 0),
)
)
)
);
}
/**
* data provider for testGenerateWkt
*
* @return data for testGenerateWkt
*/
public function providerForTestGenerateWkt()
{
$temp = array(
0 => $this->_getData()
);
$temp1 = $temp;
$temp1[0]['MULTIPOLYGON']['no_of_polygons'] = 0;
$temp2 = $temp;
$temp2[0]['MULTIPOLYGON'][1]['no_of_lines'] = 0;
$temp3 = $temp;
$temp3[0]['MULTIPOLYGON'][1][0]['no_of_points'] = 3;
return array(
array(
$temp,
0,
null,
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))'
),
// at lease one polygon should be there
array(
$temp1,
0,
null,
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
. ',(20 30,35 32,30 20,20 30)))'
),
// a polygon should have at least one ring
array(
$temp2,
0,
null,
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))'
),
// a ring should have at least four points
array(
$temp3,
0,
'0',
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))'
),
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
$temp = $this->_getData();
$temp1 = $this->_getData();
$temp1['gis_type'] = 'MULTIPOLYGON';
return array(
array(
"'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10),"
. "(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))',124",
null,
array(
'srid' => '124',
0 => $temp
)
),
array(
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10)'
. ',(20 30,35 32,30 20,20 30)),((123 0,23 30,17 63,123 0)))',
2,
array(
2 => $temp1
)
)
);
}
/**
* test getShape method
*
* @param array $row_data array of GIS data
* @param string $shape expected shape in WKT
*
* @dataProvider providerForTestGetShape
* @return void
*/
public function testGetShape($row_data, $shape)
{
$this->assertEquals($this->object->getShape($row_data), $shape);
}
/**
* data provider for testGetShape
*
* @return data for testGetShape
*/
public function providerForTestGetShape()
{
return array(
array(
array(
'parts' => array(
0 => array(
'points' => array(
0 => array('x' => 10, 'y' => 10),
1 => array('x' => 10, 'y' => 40),
2 => array('x' => 50, 'y' => 40),
3 => array('x' => 50, 'y' => 10),
4 => array('x' => 10, 'y' => 10),
),
),
1 => array(
'points' => array(
0 => array('x' => 60, 'y' => 40),
1 => array('x' => 75, 'y' => 65),
2 => array('x' => 90, 'y' => 40),
3 => array('x' => 60, 'y' => 40),
),
),
2 => array(
'points' => array(
0 => array('x' => 20, 'y' => 20),
1 => array('x' => 40, 'y' => 20),
2 => array('x' => 25, 'y' => 30),
3 => array('x' => 20, 'y' => 20),
),
),
),
),
'MULTIPOLYGON(((10 10,10 40,50 40,50 10,10 10),(20 20,40 20,25 30'
. ',20 20)),((60 40,75 65,90 40,60 40)))'
)
);
}
/**
* data provider for testScaleRow
*
* @return data for testScaleRow
*/
public function providerForTestScaleRow()
{
return array(
array(
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
. '((105 0,56 20,78 73,105 0)))',
array(
'minX' => 16,
'maxX' => 147,
'minY' => 0,
'maxY' => 83
)
),
array(
'MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20'
. ',20 30)),((105 0,56 20,78 73,105 0)))',
array(
'minX' => 10,
'maxX' => 105,
'minY' => 0,
'maxY' => 73
)
)
);
}
/**
* test case for prepareRowAsPng() method
*
* @param string $spatial GIS MULTIPOLYGON object
* @param string $label label for the GIS MULTIPOLYGON object
* @param string $fill_color color for the GIS MULTIPOLYGON object
* @param array $scale_data array containing data related to scaling
* @param object $image image object
*
* @return void
* @dataProvider providerForPrepareRowAsPng
*/
public function testPrepareRowAsPng(
$spatial, $label, $fill_color, $scale_data, $image
) {
$return = $this->object->prepareRowAsPng(
$spatial, $label, $fill_color, $scale_data, $image
);
$this->assertImage($return);
}
/**
* data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
. '((105 0,56 20,78 73,105 0)))',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150'),
)
);
}
/**
* test case for prepareRowAsPdf() method
*
* @param string $spatial GIS MULTIPOLYGON object
* @param string $label label for the GIS MULTIPOLYGON object
* @param string $fill_color color for the GIS MULTIPOLYGON object
* @param array $scale_data array containing data related to scaling
* @param object $pdf TCPDF instance
*
* @return void
* @dataProvider providerForPrepareRowAsPdf
*/
public function testPrepareRowAsPdf(
$spatial, $label, $fill_color, $scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $fill_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* data provider for testPrepareRowAsPdf() test case
*
* @return array test data for testPrepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
. '((105 0,56 20,78 73,105 0)))',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new TCPDF(),
)
);
}
/**
* test case for prepareRowAsSvg() method
*
* @param string $spatial GIS MULTIPOLYGON object
* @param string $label label for the GIS MULTIPOLYGON object
* @param string $fill_color color for the GIS MULTIPOLYGON object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsSvg
*/
public function testPrepareRowAsSvg(
$spatial, $label, $fill_color, $scale_data, $output
) {
$string = $this->object->prepareRowAsSvg(
$spatial, $label, $fill_color, $scale_data
);
$this->assertEquals(1, preg_match($output, $string));
}
/**
* data provider for testPrepareRowAsSvg() test case
*
* @return array test data for testPrepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
. '((105 0,56 20,78 73,105 0)))',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
'/^(<path d=" M 248, 208 L 270, 122 L 8, 138 Z " name="svg" class="'
. 'multipolygon vector" stroke="black" stroke-width="0.5" fill="'
. '#B02EE0" fill-rule="evenodd" fill-opacity="0.8" id="svg)(\d+)'
. '("\/><path d=" M 186, 288 L 88, 248 L 132, 142 Z " name="svg" '
. 'class="multipolygon vector" stroke="black" stroke-width="0.5" '
. 'fill="#B02EE0" fill-rule="evenodd" fill-opacity="0.8" id="svg)'
. '(\d+)("\/>)$/'
)
);
}
/**
* test case for prepareRowAsOl() method
*
* @param string $spatial GIS MULTIPOLYGON object
* @param int $srid spatial reference ID
* @param string $label label for the GIS MULTIPOLYGON object
* @param string $fill_color color for the GIS MULTIPOLYGON object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsOl
*/
public function testPrepareRowAsOl(
$spatial, $srid, $label, $fill_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $fill_color, $scale_data
)
);
}
/**
* data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'MULTIPOLYGON(((136 40,147 83,16 75,136 40)),'
. '((105 0,56 20,78 73,105 0)))',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), map.ge'
. 'tProjectionObject()));vectorLayer.addFeatures(new OpenLayers.'
. 'Feature.Vector(new OpenLayers.Geometry.MultiPolygon(new Array'
. '(new OpenLayers.Geometry.Polygon(new Array(new OpenLayers.Geo'
. 'metry.LinearRing(new Array((new OpenLayers.Geometry.Point'
. '(136,40)).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(147,'
. '83)).transform(new OpenLayers.Projection("EPSG:4326"), map.get'
. 'ProjectionObject()), (new OpenLayers.Geometry.Point(16,75)).'
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.getPro'
. 'jectionObject()), (new OpenLayers.Geometry.Point(136,40)).trans'
. 'form(new OpenLayers.Projection("EPSG:4326"), map.getProjection'
. 'Object()))))), new OpenLayers.Geometry.Polygon(new Array(new '
. 'OpenLayers.Geometry.LinearRing(new Array((new OpenLayers.Geometry'
. '.Point(105,0)).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()), (new OpenLayers.Geometry.Point(56,20)'
. ').transform(new OpenLayers.Projection("EPSG:4326"), map.getProjec'
. 'tionObject()), (new OpenLayers.Geometry.Point(78,73)).transform'
. '(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject'
. '()), (new OpenLayers.Geometry.Point(105,0)).transform(new Open'
. 'Layers.Projection("EPSG:4326"), map.getProjectionObject()))))))'
. '), null, {"strokeColor":"#000000","strokeWidth":0.5,"fillColor":'
. '"#B02EE0","fillOpacity":0.8,"label":"Ol","fontSize":10}));'
)
);
}
}

View File

@ -0,0 +1,362 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISPoint
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISPoint;
require_once 'GISGeomTest.php';
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISPoint class.
*
* @package PhpMyAdmin-test
*/
class GISPointTest extends GISGeomTest
{
/**
* @var GISPoint
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISPoint::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* data provider for testGenerateWkt
*
* @return data for testGenerateWkt
*/
public function providerForTestGenerateWkt()
{
return array(
array(
array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
0,
null,
'POINT(5.02 8.45)'
),
array(
array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
1,
null,
'POINT( )'
),
array(
array(0 => array('POINT' => array('x' => 5.02))),
0,
null,
'POINT(5.02 )'
),
array(
array(0 => array('POINT' => array('y' => 8.45))),
0,
null,
'POINT( 8.45)'
),
array(
array(0 => array('POINT' => array())),
0,
null,
'POINT( )'
),
);
}
/**
* test getShape method
*
* @param array $row_data array of GIS data
* @param string $shape expected shape in WKT
*
* @dataProvider providerForTestGetShape
* @return void
*/
public function testGetShape($row_data, $shape)
{
$this->assertEquals($this->object->getShape($row_data), $shape);
}
/**
* data provider for testGetShape
*
* @return data for testGetShape
*/
public function providerForTestGetShape()
{
return array(
array(
array('x' => 5.02, 'y' => 8.45),
'POINT(5.02 8.45)'
)
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
return array(
array(
"'POINT(5.02 8.45)',124",
null,
array(
'srid' => '124',
0 => array(
'POINT' => array('x' => '5.02', 'y' => '8.45')
),
)
),
array(
'POINT(5.02 8.45)',
2,
array(
2 => array(
'gis_type' => 'POINT',
'POINT' => array('x' => '5.02', 'y' => '8.45')
),
)
)
);
}
/**
* data provider for testScaleRow
*
* @return data for testScaleRow
*/
public function providerForTestScaleRow()
{
return array(
array(
'POINT(12 35)',
array(
'minX' => 12,
'maxX' => 12,
'minY' => 35,
'maxY' => 35,
)
)
);
}
/**
* test case for prepareRowAsPng() method
*
* @param string $spatial GIS POINT object
* @param string $label label for the GIS POINT object
* @param string $point_color color for the GIS POINT object
* @param array $scale_data array containing data related to scaling
* @param object $image image object
*
* @return void
* @dataProvider providerForPrepareRowAsPng
*/
public function testPrepareRowAsPng(
$spatial, $label, $point_color, $scale_data, $image
) {
$return = $this->object->prepareRowAsPng(
$spatial, $label, $point_color, $scale_data, $image
);
$this->assertImage($return);
}
/**
* data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'POINT(12 35)',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150')
)
);
}
/**
* test case for prepareRowAsPdf() method
*
* @param string $spatial GIS POINT object
* @param string $label label for the GIS POINT object
* @param string $point_color color for the GIS POINT object
* @param array $scale_data array containing data related to scaling
* @param object $pdf TCPDF instance
*
* @return void
* @dataProvider providerForPrepareRowAsPdf
*/
public function testPrepareRowAsPdf(
$spatial, $label, $point_color, $scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $point_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* data provider for prepareRowAsPdf() test case
*
* @return array test data for prepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'POINT(12 35)',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new TCPDF(),
)
);
}
/**
* test case for prepareRowAsSvg() method
*
* @param string $spatial GIS POINT object
* @param string $label label for the GIS POINT object
* @param string $point_color color for the GIS POINT object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsSvg
*/
public function testPrepareRowAsSvg(
$spatial, $label, $point_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsSvg(
$spatial, $label, $point_color, $scale_data
)
);
}
/**
* data provider for prepareRowAsSvg() test case
*
* @return array test data for prepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'POINT(12 35)',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
''
)
);
}
/**
* test case for prepareRowAsOl() method
*
* @param string $spatial GIS POINT object
* @param int $srid spatial reference ID
* @param string $label label for the GIS POINT object
* @param string $point_color color for the GIS POINT object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsOl
*/
public function testPrepareRowAsOl(
$spatial, $srid, $label, $point_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $point_color, $scale_data
)
);
}
/**
* data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'POINT(12 35)',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
. 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
. '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()));vectorLayer.addFeatures(new Open'
. 'Layers.Feature.Vector((new OpenLayers.Geometry.Point(12,35)).'
. 'transform(new OpenLayers.Projection("EPSG:4326"), map.get'
. 'ProjectionObject()), null, {"pointRadius":3,"fillColor":"#ffffff"'
. ',"strokeColor":"#B02EE0","strokeWidth":2,"label":"Ol","labelY'
. 'Offset":-8,"fontSize":10}));'
)
);
}
}

View File

@ -0,0 +1,589 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\gis\GISPolygon
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\gis\GISPolygon;
require_once 'GISGeomTest.php';
require_once 'libraries/tcpdf/tcpdf.php';
/**
* Tests for PMA\libraries\gis\GISPolygon class
*
* @package PhpMyAdmin-test
*/
class GISPolygonTest extends GISGeomTest
{
/**
* @var GISPolygon
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
* @return void
*/
protected function setUp()
{
$this->object = GISPolygon::singleton();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Provide some common data to data providers
*
* @return array common data for data providers
*/
private function _getData()
{
return array(
'POLYGON' => array(
'no_of_lines' => 2,
0 => array(
'no_of_points' => 5,
0 => array('x' => 35, 'y' => 10),
1 => array('x' => 10, 'y' => 20),
2 => array('x' => 15, 'y' => 40),
3 => array('x' => 45, 'y' => 45),
4 => array('x' => 35, 'y' => 10),
),
1 => array(
'no_of_points' => 4,
0 => array('x' => 20, 'y' => 30),
1 => array('x' => 35, 'y' => 32),
2 => array('x' => 30, 'y' => 20),
3 => array('x' => 20, 'y' => 30),
)
)
);
}
/**
* data provider for testGenerateWkt
*
* @return data for testGenerateWkt
*/
public function providerForTestGenerateWkt()
{
$temp = array(
0 => $this->_getData()
);
$temp1 = $temp;
unset($temp1[0]['POLYGON'][1][3]['y']);
$temp2 = $temp;
$temp2[0]['POLYGON']['no_of_lines'] = 0;
$temp3 = $temp;
$temp3[0]['POLYGON'][1]['no_of_points'] = 3;
return array(
array(
$temp,
0,
null,
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))'
),
// values at undefined index
array(
$temp,
1,
null,
'POLYGON(( , , , ))'
),
// if a coordinate is missing, default is empty string
array(
$temp1,
0,
null,
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 ))'
),
// missing coordinates are replaced with provided values (3rd parameter)
array(
$temp1,
0,
'0',
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 0))'
),
// should have at least one ring
array(
$temp2,
0,
'0',
'POLYGON((35 10,10 20,15 40,45 45,35 10))'
),
// a ring should have at least four points
array(
$temp3,
0,
'0',
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))'
),
);
}
/**
* data provider for testGenerateParams
*
* @return data for testGenerateParams
*/
public function providerForTestGenerateParams()
{
$temp = $this->_getData();
$temp1 = $temp;
$temp1['gis_type'] = 'POLYGON';
return array(
array(
"'POLYGON((35 10,10 20,15 40,45 45,35 10),"
. "(20 30,35 32,30 20,20 30))',124",
null,
array(
'srid' => '124',
0 => $temp
)
),
array(
'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))',
2,
array(
2 => $temp1
)
)
);
}
/**
* test for Area
*
* @param array $ring array of points forming the ring
* @param float $area area of the ring
*
* @dataProvider providerForTestArea
* @return void
*/
public function testArea($ring, $area)
{
$this->assertEquals($this->object->area($ring), $area);
}
/**
* data provider for testArea
*
* @return data for testArea
*/
public function providerForTestArea()
{
return array(
array(
array(
0 => array('x' => 35, 'y' => 10),
1 => array('x' => 10, 'y' => 10),
2 => array('x' => 15, 'y' => 40)
),
-375.00
),
// first point of the ring repeated as the last point
array(
array(
0 => array('x' => 35, 'y' => 10),
1 => array('x' => 10, 'y' => 10),
2 => array('x' => 15, 'y' => 40),
3 => array('x' => 35, 'y' => 10)
),
-375.00
),
// anticlockwise gives positive area
array(
array(
0 => array('x' => 15, 'y' => 40),
1 => array('x' => 10, 'y' => 10),
2 => array('x' => 35, 'y' => 10)
),
375.00
)
);
}
/**
* test for isPointInsidePolygon
*
* @param array $point x, y coordinates of the point
* @param array $polygon array of points forming the ring
* @param bool $isInside output
*
* @dataProvider providerForTestIsPointInsidePolygon
* @return void
*/
public function testIsPointInsidePolygon($point, $polygon, $isInside)
{
$this->assertEquals(
$this->object->isPointInsidePolygon($point, $polygon),
$isInside
);
}
/**
* data provider for testIsPointInsidePolygon
*
* @return data for testIsPointInsidePolygon
*/
public function providerForTestIsPointInsidePolygon()
{
$ring = array(
0 => array('x' => 35, 'y' => 10),
1 => array('x' => 10, 'y' => 10),
2 => array('x' => 15, 'y' => 40),
3 => array('x' => 35, 'y' => 10)
);
return array(
// point inside the ring
array(
array('x' => 20, 'y' => 15),
$ring,
true
),
// point on an edge of the ring
array(
array('x' => 20, 'y' => 10),
$ring,
false
),
// point on a vertex of the ring
array(
array('x' => 10, 'y' => 10),
$ring,
false
),
// point outside the ring
array(
array('x' => 5, 'y' => 10),
$ring,
false
),
);
}
/**
* test for getPointOnSurface
*
* @param array $ring array of points forming the ring
*
* @dataProvider providerForTestGetPointOnSurface
* @return void
*/
public function testGetPointOnSurface($ring)
{
$this->assertEquals(
$this->object->isPointInsidePolygon(
$this->object->getPointOnSurface($ring),
$ring
),
true
);
}
/**
* data provider for testGetPointOnSurface
*
* @return data for testGetPointOnSurface
*/
public function providerForTestGetPointOnSurface()
{
$temp = $this->_getData();
unset($temp['POLYGON'][0]['no_of_points']);
unset($temp['POLYGON'][1]['no_of_points']);
return array(
array(
$temp['POLYGON'][0]
),
array(
$temp['POLYGON'][1]
)
);
}
/**
* data provider for testScaleRow
*
* @return data for testScaleRow
*/
public function providerForTestScaleRow()
{
return array(
array(
'POLYGON((123 0,23 30,17 63,123 0))',
array(
'minX' => 17,
'maxX' => 123,
'minY' => 0,
'maxY' => 63,
)
),
array(
'POLYGON((35 10,10 20,15 40,45 45,35 10),'
. '(20 30,35 32,30 20,20 30)))',
array(
'minX' => 10,
'maxX' => 45,
'minY' => 10,
'maxY' => 45
)
),
);
}
/**
* test case for prepareRowAsPng()
*
* @param string $spatial GIS POLYGON object
* @param string $label label for the GIS POLYGON object
* @param string $fill_color color for the GIS POLYGON object
* @param array $scale_data array containing data related to scaling
* @param object $image image object
*
* @return void
* @dataProvider providerForPrepareRowAsPng
*/
public function testPrepareRowAsPng(
$spatial, $label, $fill_color, $scale_data, $image
) {
$return = $this->object->prepareRowAsPng(
$spatial, $label, $fill_color, $scale_data, $image
);
$this->assertImage($return);
}
/**
* data provider for testPrepareRowAsPng() test case
*
* @return array test data for testPrepareRowAsPng() test case
*/
public function providerForPrepareRowAsPng()
{
return array(
array(
'POLYGON((123 0,23 30,17 63,123 0))',
'image',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
imagecreatetruecolor('120', '150')
)
);
}
/**
* test case for prepareRowAsPdf() method
*
* @param string $spatial GIS POLYGON object
* @param string $label label for the GIS POLYGON object
* @param string $fill_color color for the GIS POLYGON object
* @param array $scale_data array containing data related to scaling
* @param object $pdf TCPDF instance
*
* @return void
* @dataProvider providerForPrepareRowAsPdf
*/
public function testPrepareRowAsPdf(
$spatial, $label, $fill_color, $scale_data, $pdf
) {
$return = $this->object->prepareRowAsPdf(
$spatial, $label, $fill_color, $scale_data, $pdf
);
$this->assertInstanceOf('TCPDF', $return);
}
/**
* data provider for testPrepareRowAsPdf() test case
*
* @return array test data for testPrepareRowAsPdf() test case
*/
public function providerForPrepareRowAsPdf()
{
return array(
array(
'POLYGON((123 0,23 30,17 63,123 0))',
'pdf',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
new TCPDF(),
)
);
}
/**
* test case for prepareRowAsSvg() method
*
* @param string $spatial GIS POLYGON object
* @param string $label label for the GIS POLYGON object
* @param string $fill_color color for the GIS POLYGON object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsSvg
*/
public function testPrepareRowAsSvg(
$spatial, $label, $fill_color, $scale_data, $output
) {
$string = $this->object->prepareRowAsSvg(
$spatial, $label, $fill_color, $scale_data
);
$this->assertEquals(1, preg_match($output, $string));
}
/**
* data provider for testPrepareRowAsSvg() test case
*
* @return array test data for testPrepareRowAsSvg() test case
*/
public function providerForPrepareRowAsSvg()
{
return array(
array(
'POLYGON((123 0,23 30,17 63,123 0))',
'svg',
'#B02EE0',
array(
'x' => 12,
'y' => 69,
'scale' => 2,
'height' => 150
),
'/^(<path d=" M 222, 288 L 22, 228 L 10, 162 Z " name="svg" '
. 'id="svg)(\d+)(" class="polygon vector" stroke="black" '
. 'stroke-width="0.5" fill="#B02EE0" fill-rule="evenodd" '
. 'fill-opacity="0.8"\/>)$/'
)
);
}
/**
* test case for prepareRowAsOl() method
*
* @param string $spatial GIS POLYGON object
* @param int $srid spatial reference ID
* @param string $label label for the GIS POLYGON object
* @param string $fill_color color for the GIS POLYGON object
* @param array $scale_data array containing data related to scaling
* @param string $output expected output
*
* @return void
* @dataProvider providerForPrepareRowAsOl
*/
public function testPrepareRowAsOl(
$spatial, $srid, $label, $fill_color, $scale_data, $output
) {
$this->assertEquals(
$output,
$this->object->prepareRowAsOl(
$spatial, $srid, $label, $fill_color, $scale_data
)
);
}
/**
* data provider for testPrepareRowAsOl() test case
*
* @return array test data for testPrepareRowAsOl() test case
*/
public function providerForPrepareRowAsOl()
{
return array(
array(
'POLYGON((123 0,23 30,17 63,123 0))',
4326,
'Ol',
'#B02EE0',
array(
'minX' => '0',
'minY' => '0',
'maxX' => '1',
'maxY' => '1',
),
'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.Lon'
. 'Lat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject())); bound.extend(new OpenLayers.'
. 'LonLat(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), '
. 'map.getProjectionObject()));vectorLayer.addFeatures(new Open'
. 'Layers.Feature.Vector(new OpenLayers.Geometry.Polygon(new Array'
. '(new OpenLayers.Geometry.LinearRing(new Array((new OpenLayers.'
. 'Geometry.Point(123,0)).transform(new OpenLayers.Projection'
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
. 'Geometry.Point(23,30)).transform(new OpenLayers.Projection'
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
. 'Geometry.Point(17,63)).transform(new OpenLayers.Projection'
. '("EPSG:4326"), map.getProjectionObject()), (new OpenLayers.'
. 'Geometry.Point(123,0)).transform(new OpenLayers.Projection'
. '("EPSG:4326"), map.getProjectionObject()))))), null, {"stroke'
. 'Color":"#000000","strokeWidth":0.5,"fillColor":"#B02EE0",'
. '"fillOpacity":0.8,"label":"Ol","fontSize":10}));'
)
);
}
/**
* test case for isOuterRing() method
*
* @param array $ring coordinates of the points in a ring
*
* @return void
* @dataProvider providerForIsOuterRing
*/
public function testIsOuterRing($ring)
{
$this->assertTrue($this->object->isOuterRing($ring));
}
/**
* data provider for testIsOuterRing() test case
*
* @return array test data for testIsOuterRing() test case
*/
public function providerForIsOuterRing()
{
return array(
array(
array(
array('x' => 0, 'y' => 0),
array('x' => 0, 'y' => 1),
array('x' => 1, 'y' => 1),
array('x' => 1, 'y' => 0)
),
)
);
}
}