1
|
|
|
<?php |
2
|
|
|
namespace ShapeFile; |
3
|
|
|
|
4
|
|
|
class ShapeFileTest extends PHPUnit_Framework_TestCase |
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* Tests loading of a file |
8
|
|
|
* |
9
|
|
|
* @param string $filename Name of file |
10
|
|
|
* @param integer $records Expected number of records |
11
|
|
|
* @param integer $parts Expected number of parts in first record |
12
|
|
|
* |
13
|
|
|
* @return void |
14
|
|
|
* |
15
|
|
|
* @dataProvider provideFiles |
16
|
|
|
*/ |
17
|
|
|
public function testLoad($filename, $records, $parts) |
18
|
|
|
{ |
19
|
|
|
$shp = new ShapeFile(1); |
20
|
|
|
$shp->loadFromFile($filename); |
21
|
|
|
$this->assertEquals($records, count($shp->records)); |
22
|
|
|
if (!is_null($parts)) { |
23
|
|
|
$this->assertEquals($parts, count($shp->records[0]->SHPData["parts"])); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Data provider for file loading tests. |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function provideFiles() |
33
|
|
|
{ |
34
|
|
|
return array( |
35
|
|
|
array('data/capitals.*', 652, null), |
36
|
|
|
array('data/mexico.*', 32, 3), |
37
|
|
|
array('data/Czech_Republic_AL2.*', 1, 1), |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Tests creating file |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function testCreate() |
47
|
|
|
{ |
48
|
|
|
$shp = new ShapeFile(1); |
49
|
|
|
|
50
|
|
|
$record0 = new ShapeRecord(1); |
51
|
|
|
$record0->addPoint(array("x" => 482131.764567, "y" => 2143634.39608)); |
52
|
|
|
|
53
|
|
|
$record1 = new ShapeRecord(1); |
54
|
|
|
$record1->addPoint(array("x" => 472131.764567, "y" => 2143634.39608)); |
55
|
|
|
|
56
|
|
|
$record2 = new ShapeRecord(1); |
57
|
|
|
$record2->addPoint(array("x" => 492131.764567, "y" => 2143634.39608)); |
58
|
|
|
|
59
|
|
|
$shp->addRecord($record0); |
60
|
|
|
$shp->addRecord($record1); |
61
|
|
|
$shp->addRecord($record2); |
62
|
|
|
|
63
|
|
|
$shp->setDBFHeader( |
64
|
|
|
array( |
65
|
|
|
array('ID', 'N', 8, 0), |
66
|
|
|
array('DESC', 'C', 50, 0) |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$shp->records[0]->DBFData['ID'] = '1'; |
71
|
|
|
$shp->records[0]->DBFData['DESC'] = 'AAAAAAAAA'; |
72
|
|
|
|
73
|
|
|
$shp->records[1]->DBFData['ID'] = '2'; |
74
|
|
|
$shp->records[1]->DBFData['DESC'] = 'BBBBBBBBBB'; |
75
|
|
|
|
76
|
|
|
$shp->records[2]->DBFData['ID'] = '3'; |
77
|
|
|
$shp->records[2]->DBFData['DESC'] = 'CCCCCCCCCCC'; |
78
|
|
|
|
79
|
|
|
$shp->saveToFile('./data/test_shape.*'); |
80
|
|
|
|
81
|
|
|
$shp = new ShapeFile(1); |
82
|
|
|
$shp->loadFromFile('./data/test_shape.*'); |
83
|
|
|
$this->assertEquals(3, count($shp->records)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|