|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace Maps\Tests\Unit\DataAccess; |
|
6
|
|
|
|
|
7
|
|
|
use Maps\DataAccess\GeoJsonStore\SubObject; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use SMW\DIProperty; |
|
10
|
|
|
use SMW\DIWikiPage; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers \Maps\DataAccess\GeoJsonStore\SubObject |
|
14
|
|
|
*/ |
|
15
|
|
|
class SubObjectTest extends TestCase { |
|
16
|
|
|
|
|
17
|
|
|
private const PAGE_NS = NS_GEO_JSON; |
|
18
|
|
|
private const PAGE_TITLE = 'TestGeoJson'; |
|
19
|
|
|
|
|
20
|
|
|
public function testEmpty() { |
|
21
|
|
|
$subObject = new SubObject( 'MyName' ); |
|
22
|
|
|
|
|
23
|
|
|
$container = $subObject->toContainerSemanticData( $this->newTitleValue() ); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertEquals( |
|
26
|
|
|
new DIWikiPage( self::PAGE_TITLE, self::PAGE_NS, '', 'MyName' ), |
|
27
|
|
|
$container->getSubject() |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertSame( [], $container->getErrors() ); |
|
31
|
|
|
$this->assertSame( [], $container->getProperties() ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
private function newTitleValue(): \TitleValue { |
|
35
|
|
|
return new \TitleValue( self::PAGE_NS, self::PAGE_TITLE ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testPropertyValuesPairsAreTransformed() { |
|
39
|
|
|
$subObject = new SubObject( 'MyName' ); |
|
40
|
|
|
$subObject->addPropertyValuePair( 'SuchNumber', new \SMWDINumber( 42 ) ); |
|
41
|
|
|
$subObject->addPropertyValuePair( 'SuchNumber', new \SMWDINumber( 23 ) ); |
|
42
|
|
|
$subObject->addPropertyValuePair( 'SuchBoolean', new \SMWDIBoolean( true ) ); |
|
43
|
|
|
|
|
44
|
|
|
$container = $subObject->toContainerSemanticData( $this->newTitleValue() ); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertEquals( |
|
47
|
|
|
[ |
|
48
|
|
|
'SuchNumber' => new DIProperty( 'SuchNumber' ), |
|
49
|
|
|
'SuchBoolean' => new DIProperty( 'SuchBoolean' ), |
|
50
|
|
|
], |
|
51
|
|
|
$container->getProperties() |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertEquals( |
|
55
|
|
|
[ |
|
56
|
|
|
new \SMWDINumber( 42 ) , |
|
57
|
|
|
new \SMWDINumber( 23 ) , |
|
58
|
|
|
], |
|
59
|
|
|
$container->getPropertyValues( new DIProperty( 'SuchNumber' ) ) |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertSame( [], $container->getErrors() ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|