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 setUp(): void { |
21
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
22
|
|
|
$this->markTestSkipped( 'SMW is not available' ); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testEmpty() { |
27
|
|
|
$subObject = new SubObject( 'MyName' ); |
28
|
|
|
|
29
|
|
|
$container = $subObject->toContainerSemanticData( $this->newTitleValue() ); |
30
|
|
|
|
31
|
|
|
$this->assertEquals( |
32
|
|
|
new DIWikiPage( self::PAGE_TITLE, self::PAGE_NS, '', 'MyName' ), |
33
|
|
|
$container->getSubject() |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$this->assertSame( [], $container->getErrors() ); |
37
|
|
|
$this->assertSame( [], $container->getProperties() ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private function newTitleValue(): \TitleValue { |
41
|
|
|
return new \TitleValue( self::PAGE_NS, self::PAGE_TITLE ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testPropertyValuesPairsAreTransformed() { |
45
|
|
|
$subObject = new SubObject( 'MyName' ); |
46
|
|
|
$subObject->addPropertyValuePair( 'SuchNumber', new \SMWDINumber( 42 ) ); |
47
|
|
|
$subObject->addPropertyValuePair( 'SuchNumber', new \SMWDINumber( 23 ) ); |
48
|
|
|
$subObject->addPropertyValuePair( 'SuchBoolean', new \SMWDIBoolean( true ) ); |
49
|
|
|
|
50
|
|
|
$container = $subObject->toContainerSemanticData( $this->newTitleValue() ); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( |
53
|
|
|
[ |
54
|
|
|
'SuchNumber' => new DIProperty( 'SuchNumber' ), |
55
|
|
|
'SuchBoolean' => new DIProperty( 'SuchBoolean' ), |
56
|
|
|
], |
57
|
|
|
$container->getProperties() |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->assertEquals( |
61
|
|
|
[ |
62
|
|
|
new \SMWDINumber( 42 ) , |
63
|
|
|
new \SMWDINumber( 23 ) , |
64
|
|
|
], |
65
|
|
|
$container->getPropertyValues( new DIProperty( 'SuchNumber' ) ) |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->assertSame( [], $container->getErrors() ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|