diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Serializers/ExpDataSerializerTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Serializers/ExpDataSerializerTest.php | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Serializers/ExpDataSerializerTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Serializers/ExpDataSerializerTest.php new file mode 100644 index 00000000..9e38a8d7 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Serializers/ExpDataSerializerTest.php @@ -0,0 +1,174 @@ +<?php + +namespace SMW\Tests\Serializers; + +use SMW\Exporter\Element\ExpLiteral; +use SMW\Exporter\Element\ExpNsResource; +use SMW\Serializers\ExpDataSerializer; +use SMWDIBlob as DIBlob; +use SMWExpData as ExpData; +use SMW\Tests\PHPUnitCompat; + +/** + * @covers \SMW\Serializers\ExpDataSerializer + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.2 + * + * @author mwjames + */ +class ExpDataSerializerTest extends \PHPUnit_Framework_TestCase { + + use PHPUnitCompat; + + public function testCanConstructor() { + + $this->assertInstanceOf( + '\SMW\Serializers\ExpDataSerializer', + new ExpDataSerializer() + ); + } + + public function testInvalidSerializerObjectThrowsException() { + + $instance = new ExpDataSerializer(); + + $this->setExpectedException( 'OutOfBoundsException' ); + $instance->serialize( 'Foo' ); + } + + /** + * @dataProvider expDataProvider + */ + public function testSerialize( $data, $expected ) { + + $instance = new ExpDataSerializer(); + + $this->assertEquals( + $expected, + $instance->serialize( $data ) + ); + } + + public function expDataProvider() { + + #0 + $expData = new ExpData( new ExpNsResource( 'Foo', 'Bar', 'Mo', null ) ); + + $provider[] = [ + $expData, + [ + 'subject' => [ + 'type' => 1, + 'uri' => 'Foo|Bar|Mo', + 'dataitem' => null + ], + 'data' => [], + 'serializer' => 'SMW\Serializers\ExpDataSerializer', + 'version' => 0.1 + ] + ]; + + #1 + $expData = new ExpData( new ExpNsResource( 'Foo', 'Bar', 'Mo', null ) ); + + $expData->addPropertyObjectValue( + new ExpNsResource( 'Li', 'La', 'Lu', null ), + new ExpLiteral( 'Foo', 'Bar' ) + ); + + $provider[] = [ + $expData, + [ + 'subject' => [ + 'type' => 1, + 'uri' => 'Foo|Bar|Mo', + 'dataitem' => null + ], + 'data' => [ + 'LaLi' => [ + 'property' => [ + 'type' => 1, + 'uri' => 'Li|La|Lu', + 'dataitem' => null + ], + 'children' => [ + [ + 'type' => 2, + 'lexical' => 'Foo', + 'datatype' => 'Bar', + 'lang' => '', + 'dataitem' => null + ] + ] + ] + ], + 'serializer' => 'SMW\Serializers\ExpDataSerializer', + 'version' => 0.1 + ] + ]; + + #2 Nested + $expData = new ExpData( new ExpNsResource( 'Foo', 'Bar', 'Mo', null ) ); + + $expData->addPropertyObjectValue( + new ExpNsResource( 'Li', 'La', 'Lu', new DIBlob( 'SomeText' ) ), + new ExpLiteral( 'Foo', 'Bar' ) + ); + + $expData->addPropertyObjectValue( + new ExpNsResource( 'Li', 'La', 'Lu', null ), + new ExpData( new ExpNsResource( 'Foo', 'Bar', 'Mo', new DIBlob( 'SomeOtherText' ) ) ) + ); + + $provider[] = [ + $expData, + [ + 'subject' => [ + 'type' => 1, + 'uri' => 'Foo|Bar|Mo', + 'dataitem' => null + ], + 'data' => [ + 'LaLi' => [ + 'property' => [ + 'type' => 1, + 'uri' => 'Li|La|Lu', + 'dataitem' => [ // DIBlob + 'type' => 2, + 'item' => 'SomeText' + ] + ], + 'children' => [ + [ // ExpLiteral + 'type' => 2, + 'lexical' => 'Foo', + 'datatype' => 'Bar', + 'lang' => '', + 'dataitem' => null + ], + [ // ExpData + 'subject' => [ + 'type' => 1, + 'uri' => 'Foo|Bar|Mo', + 'dataitem' => [ + 'type' => 2, + 'item' => 'SomeOtherText' + ] + ], + 'data' => [] + ] + ] + ] + ], + 'serializer' => 'SMW\Serializers\ExpDataSerializer', + 'version' => 0.1 + ] + ]; + + return $provider; + } + + +} |