assertInstanceOf( '\SMW\Serializers\SemanticDataSerializer', new SemanticDataSerializer() ); } public function testInvalidSerializerObjectThrowsException() { $this->expectException( 'OutOfBoundsException' ); $instance = new SemanticDataSerializer(); $instance->serialize( 'Foo' ); } /** * @dataProvider semanticDataProvider */ public function testSerializerDeserializerRountrip( $data ) { $instance = new SemanticDataSerializer(); $this->assertIsArray( $instance->serialize( $data ) ); } public function semanticDataProvider() { // Is a dataprovider therefore can't use the setUp $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); $this->dataValueFactory = DataValueFactory::getInstance(); $title = MediaWikiServices::getInstance()->getTitleFactory()->newFromText( 'Foo' ); # 0 Empty container $foo = $this->semanticDataFactory->setSubject( DIWikiPage::newFromTitle( $title ) )->newEmptySemanticData(); $provider[] = [ $foo ]; # 1 Single entry $foo = $this->semanticDataFactory->setSubject( DIWikiPage::newFromTitle( $title ) )->newEmptySemanticData(); $foo->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has fooQuex', 'Bar' ) ); $provider[] = [ $foo ]; // #2 Single + single subobject entry $foo = $this->semanticDataFactory->setSubject( DIWikiPage::newFromTitle( $title ) )->newEmptySemanticData(); $foo->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has fooQuex', 'Bar' ) ); $subobject = new Subobject( $title ); $subobject->setSemanticData( 'Foo' ); $subobject->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has subobjects', 'Bam' ) ); $foo->addPropertyObjectValue( $subobject->getProperty(), $subobject->getContainer() ); $provider[] = [ $foo ]; # 3 Multiple entries $foo = $this->semanticDataFactory->setSubject( DIWikiPage::newFromTitle( $title ) )->newEmptySemanticData(); $foo->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has fooQuex', 'Bar' ) ); $foo->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has queez', 'Xeey' ) ); $subobject = new Subobject( $title ); $subobject->setSemanticData( 'Foo' ); $subobject->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has subobjects', 'Bam' ) ); $subobject->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has fooQuex', 'Fuz' ) ); $subobject->setSemanticData( 'Bar' ); $subobject->addDataValue( $this->dataValueFactory->newDataValueByText( 'Has fooQuex', 'Fuz' ) ); $foo->addPropertyObjectValue( $subobject->getProperty(), $subobject->getContainer() ); $provider[] = [ $foo ]; return $provider; } }