dataItemFactory = new DataItemFactory(); } public function testCanConstruct() { $this->assertInstanceOf( QueryToken::class, new QueryToken() ); } /** * @dataProvider descriptionProvider */ public function testAddFromDesciption( $description, $expected ) { $instance = new QueryToken(); $instance->addFromDesciption( $description ); $this->assertEquals( $expected, $instance->getTokens() ); } public function testMulitpleAddFromDesciption() { $instance = new QueryToken(); $description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) ->disableOriginalConstructor() ->getMock(); $description->expects( $this->once() ) ->method( 'getComparator' ) ->willReturn( SMW_CMP_LIKE ); $description->expects( $this->atLeastOnce() ) ->method( 'getDataItem' ) ->willReturn( $this->dataItemFactory->newDIBlob( 'abc Foo 123' ) ); $instance->addFromDesciption( $description ); $description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) ->disableOriginalConstructor() ->getMock(); $description->expects( $this->atLeastOnce() ) ->method( 'getDataItem' ) ->willReturn( $this->dataItemFactory->newDIWikiPage( '~*123 bar 456' ) ); $instance->addFromDesciption( $description ); $this->assertEquals( [ 'abc' => 0, 'Foo' => 1, 123 => 2, 'bar' => 1, 456 => 2 ], $instance->getTokens() ); } /** * @dataProvider highlightProvider */ public function testHighlight( $description, $text, $type, $expected ) { $instance = new QueryToken(); $instance->addFromDesciption( $description ); $instance->setOutputFormat( '-hL' ); $this->assertEquals( $expected, $instance->highlight( $text, $type ) ); } public function descriptionProvider() { $dataItemFactory = new DataItemFactory(); $description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) ->disableOriginalConstructor() ->getMock(); $description->expects( $this->once() ) ->method( 'getComparator' ) ->willReturn( SMW_CMP_LIKE ); $description->expects( $this->atLeastOnce() ) ->method( 'getDataItem' ) ->willReturn( $dataItemFactory->newDIBlob( 'abc Foo 123' ) ); $provider[] = [ $description, [ 'abc' => 0, 'Foo' => 1, 123 => 2 ] ]; return $provider; } public function highlightProvider() { $dataItemFactory = new DataItemFactory(); $description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) ->disableOriginalConstructor() ->getMock(); $description->expects( $this->any() ) ->method( 'getComparator' ) ->willReturn( SMW_CMP_LIKE ); $description->expects( $this->any() ) ->method( 'getDataItem' ) ->willReturn( $dataItemFactory->newDIBlob( 'abc Foo 123 foobar' ) ); $provider[] = [ $description, 'Lorem abc foobar', QueryToken::HL_BOLD, "Lorem abc foobar" ]; $provider[] = [ $description, 'Lorem abc foobar', QueryToken::HL_WIKI, "Lorem '''abc''' '''foo'''bar" ]; $provider[] = [ $description, 'Lorem abc foobar', QueryToken::HL_UNDERLINE, "Lorem abc foobar" ]; $description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) ->disableOriginalConstructor() ->getMock(); $description->expects( $this->any() ) ->method( 'getComparator' ) ->willReturn( SMW_CMP_LIKE ); $description->expects( $this->any() ) ->method( 'getDataItem' ) ->willReturn( $dataItemFactory->newDIBlob( 'integer porttitor portt' ) ); $provider[] = [ $description, 'Integer porttitor mi id ante consequat consequat porttitor', QueryToken::HL_BOLD, "Integer porttitor mi id ante consequat consequat porttitor" ]; $provider[] = [ $description, 'Integer porttitor mi id ante consequat consequat porttitor', QueryToken::HL_SPAN, "Integer porttitor mi id ante consequat consequat porttitor" ]; $description = $this->getMockBuilder( '\SMW\Query\Language\ValueDescription' ) ->disableOriginalConstructor() ->getMock(); $description->expects( $this->any() ) ->method( 'getComparator' ) ->willReturn( SMW_CMP_PRIM_LIKE ); $description->expects( $this->any() ) ->method( 'getDataItem' ) ->willReturn( $dataItemFactory->newDIBlob( 'abc Foo 123 foobar' ) ); $provider[] = [ $description, 'Lorem abc foobar', QueryToken::HL_BOLD, "Lorem abc foobar" ]; return $provider; } }