Skip to content

Commit 3cfff7d

Browse files
committed
Merge branch 'Completing-KML-parsing' of github.com:earelin/php-libkml into Completing-KML-parsing
2 parents 816cf73 + 0c4e061 commit 3cfff7d

8 files changed

Lines changed: 180 additions & 43 deletions

File tree

composer.lock

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

features/read/kml/parse_style.feature

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,89 @@ Feature: Parse <Style>
33
As an user
44
I need <Style> tag to be parsed as a Style object
55

6-
Scenario:
7-
Given a KML document with a Document in "tests/kml/style.kml"
8-
When I parse the KML document
9-
Then I should get a KmlDocument object containing one Style
10-
And the Style object should contain a IconStyle object with the following properties:
11-
| property | value |
12-
| color | ffffffff |
13-
| colorMode | 2021-09-12T16:14:18.765 |
6+
Scenario: Style with a Balloon
7+
Given a KML document with a Document in "tests/kml/document.kml"
8+
When I parse the KML document
9+
Then I should get a KmlDocument object containing one feature 'LibKml\Domain\Feature\Container\Document'
10+
And the feature should contain a Style object with the following properties:
11+
| property | value |
12+
| id | style-1 |
13+
| targetId | target-1 |
14+
And the Style should contain a BalloonStyle with the following properties:
15+
| property | value |
16+
| bgColor | ffffffbb |
17+
| textColor | ff00aabb |
18+
| text | $[name] |
19+
| displayMode | random |
20+
21+
Scenario: Style with a IconStyle
22+
Given a KML document with a Document in "tests/kml/document.kml"
23+
When I parse the KML document
24+
Then I should get a KmlDocument object containing one feature 'LibKml\Domain\Feature\Container\Document'
25+
And the feature should contain a Style object with the following properties:
26+
| property | value |
27+
| id | style-1 |
28+
| targetId | target-1 |
29+
And the Style should contain a IconStyle with the following properties:
30+
| property | value |
31+
| color | ff00bbcc |
32+
| colorMode | random |
33+
| scale | 0.5 |
34+
| heading | 2.56 |
35+
36+
Scenario: Style with a LabelStyle
37+
Given a KML document with a Document in "tests/kml/document.kml"
38+
When I parse the KML document
39+
Then I should get a KmlDocument object containing one feature 'LibKml\Domain\Feature\Container\Document'
40+
And the feature should contain a Style object with the following properties:
41+
| property | value |
42+
| id | style-1 |
43+
| targetId | target-1 |
44+
And the Style should contain a LabelStyle with the following properties:
45+
| property | value |
46+
| color | ffaabbcc |
47+
| colorMode | random |
48+
| scale | 0.75 |
49+
| heading | 56.42 |
50+
51+
Scenario: Style with a LineStyle
52+
Given a KML document with a Document in "tests/kml/document.kml"
53+
When I parse the KML document
54+
Then I should get a KmlDocument object containing one feature 'LibKml\Domain\Feature\Container\Document'
55+
And the feature should contain a Style object with the following properties:
56+
| property | value |
57+
| id | style-1 |
58+
| targetId | target-1 |
59+
And the Style should contain a LineStyle with the following properties:
60+
| property | value |
61+
| color | ffddbbcc |
62+
| colorMode | random |
63+
| width | 2.75 |
64+
65+
Scenario: Style with a ListStyle
66+
Given a KML document with a Document in "tests/kml/document.kml"
67+
When I parse the KML document
68+
Then I should get a KmlDocument object containing one feature 'LibKml\Domain\Feature\Container\Document'
69+
And the feature should contain a Style object with the following properties:
70+
| property | value |
71+
| id | style-1 |
72+
| targetId | target-1 |
73+
And the Style should contain a ListStyle with the following properties:
74+
| property | value |
75+
| listItemType | radioFolder |
76+
| bgColor | 55aabbcc |
77+
78+
Scenario: Style with a PolyStyle
79+
Given a KML document with a Document in "tests/kml/document.kml"
80+
When I parse the KML document
81+
Then I should get a KmlDocument object containing one feature 'LibKml\Domain\Feature\Container\Document'
82+
And the feature should contain a Style object with the following properties:
83+
| property | value |
84+
| id | style-1 |
85+
| targetId | target-1 |
86+
And the Style should contain a PolyStyle with the following properties:
87+
| property | value |
88+
| color | ffddaa00 |
89+
| colorMode | random |
90+
| fill | 0 |
91+
| outline | 0 |

src/Domain/Feature/Feature.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ abstract class Feature extends KmlObject {
2222
protected $atomAuthor;
2323
protected $atomLink;
2424
protected $address;
25-
protected $addressDetails;
2625
protected $phoneNumber;
2726
protected $snippet;
2827
protected $description;
@@ -89,14 +88,6 @@ public function setAtomLink(?Link $atomLink): void {
8988
$this->atomLink = $atomLink;
9089
}
9190

92-
public function getAddressDetails() {
93-
return $this->addressDetails;
94-
}
95-
96-
public function setAddressDetails($addressDetails) {
97-
$this->addressDetails = $addressDetails;
98-
}
99-
10091
public function getPhoneNumber(): ?string {
10192
return $this->phoneNumber;
10293
}

src/Domain/TimePrimitive/TimeStamp.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class TimeStamp extends TimePrimitive {
1111

1212
private $when;
1313

14+
public static function fromInteger(int $unixTimestamp) {
15+
$timeStamp = new TimeStamp();
16+
$timeStamp->when = date(DATE_ISO8601, $unixTimestamp);
17+
return $timeStamp;
18+
}
19+
1420
public function accept(KmlObjectVisitorInterface $visitor): void {
1521
$visitor->visitTimeStamp($this);
1622
}

tests/kml/style.kml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<name>Document with XML id</name>
55
<open>1</open>
66
<Style id="style-1" targetId="target-1">
7+
<BalloonStyle>
8+
<bgColor>ffffffbb</bgColor>
9+
<textColor>ff00aabb</textColor>
10+
<text>$[name]</text>
11+
<displayMode>random</displayMode>
12+
</BalloonStyle>
713
<IconStyle>
814
<color>a1ff00ff</color>
915
<scale>1.399999976158142</scale>
@@ -24,14 +30,14 @@
2430
<colorMode>random</colorMode>
2531
</PolyStyle>
2632
</Style>
27-
<Style id="style-2" targetId="target-2">
28-
<IconStyle>
29-
<color>ff00ff00</color>
30-
<scale>2</scale>
31-
<Icon>
32-
<href>http://myserver.com/icon.jpg</href>
33-
</Icon>
34-
</IconStyle>
35-
</Style>
33+
<Folder>
34+
<name>Folder 1</name>
35+
</Folder>
36+
<Folder>
37+
<name>Folder 2</name>
38+
</Folder>
39+
<Folder>
40+
<name>Folder 3</name>
41+
</Folder>
3642
</Document>
3743
</kml>

tests/src/Bdd/Read/Kml/ParserKmlContext.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use LibKml\Domain\KmlDocument;
88
use LibKml\Domain\StyleSelector\StyleSelector;
99
use LibKml\Domain\SubStyle\SubStyle;
10+
use LibKml\Domain\StyleSelector\Style;
1011
use LibKml\Reader\LibKmlReader;
1112
use PHPUnit\Framework\TestCase;
1213

@@ -90,6 +91,13 @@ public function theNetworklinkcontrolShouldContainACameraWithATimeprimitivePrope
9091
$this->target = $abstractView->getTimePrimitive();
9192
}
9293

94+
/**
95+
* @Then the TimeSpan/TimeStamp object should contain the following properties:
96+
*/
97+
public function theTimespanTimeStampObjectShouldContainTheFollowingProperties(TableNode $table) {
98+
99+
}
100+
93101
/**
94102
* @Then the feature should contain a LookAt object with the the following properties:
95103
*/
@@ -98,6 +106,27 @@ public function theFeatureShouldContainALookatObjectWithTheTheFollowingPropertie
98106
$this->containsProperties($feature->getAbstractView(), $table);
99107
}
100108

109+
/**
110+
* @Then the feature should contain a Style object with the following properties:
111+
*/
112+
public function theFeatureShouldContainAStyleObjectWithTheFollowingProperties(TableNode $table) {
113+
$styles = $this->kmlDocument->getFeature()->getStyleSelectors();
114+
115+
TestCase::assertCount(1, $styles);
116+
TestCase::assertInstanceOf(Style::class, $styles[0]);
117+
$this->containsProperties($styles[0], $table);
118+
119+
$this->target = $styles[0];
120+
}
121+
122+
/**
123+
* @Then the Style should contain a :subStyle with the following properties:
124+
*/
125+
public function theStyleShouldContainABalloonstyleWithTheFollowingProperties($subStyle, TableNode $table) {
126+
$subStyle = $this->target->{'get' . $subStyle}();
127+
$this->containsProperties($subStyle, $table);
128+
}
129+
101130
/**
102131
* @Then the NetworkLinkControl should have an AbstractView with the following properties:
103132
*/

tests/src/Domain/AbstractView/CameraTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace LibKml\Tests\Domain\AbstractView;
44

55
use LibKml\Domain\AbstractView\Camera;
6+
use LibKml\Domain\FieldType\AltitudeMode;
67
use LibKml\Domain\KmlObjectVisitorInterface;
8+
use LibKml\Domain\TimePrimitive\TimeStamp;
79
use PHPUnit\Framework\TestCase;
810

911
class CameraTest extends TestCase {
@@ -39,4 +41,20 @@ public function testRollField() {
3941
$this->assertEquals($roll, $this->camera->getRoll());
4042
}
4143

44+
public function testAltitudeModeField() {
45+
$altitudeMode = AltitudeMode::ABSOLUTE;
46+
47+
$this->camera->setAltitudeMode($altitudeMode);
48+
49+
$this->assertEquals($altitudeMode, $this->camera->getAltitudeMode());
50+
}
51+
52+
public function testTimePrimitive() {
53+
$timeStamp = TimeStamp::fromInteger(time());
54+
55+
$this->camera->setTimePrimitive($timeStamp);
56+
57+
$this->assertEquals($timeStamp, $this->camera->getTimePrimitive());
58+
}
59+
4260
}

tests/src/Domain/TimePrimitive/TimeStampTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,13 @@ public function testWhenField() {
3737

3838
$this->assertEquals($when, $this->timeStamp->getWhen());
3939
}
40+
41+
public function testFromInteger() {
42+
$unixTimestamp = time();
43+
44+
$timeStamp = TimeStamp::fromInteger($unixTimestamp);
45+
46+
$this->assertEquals(date(DATE_ISO8601, $unixTimestamp), $timeStamp->getWhen());
47+
}
4048

4149
}

0 commit comments

Comments
 (0)