descriptionFactory = new DescriptionFactory(); $this->store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMock(); $parameters = $this->getMockBuilder( '\SMW\Elastic\QueryEngine\TermsLookup\Parameters' ) ->disableOriginalConstructor() ->getMock(); $this->termsLookup = $this->getMockBuilder( '\SMW\Elastic\QueryEngine\TermsLookup' ) ->disableOriginalConstructor() ->getMock(); $this->termsLookup->expects( $this->any() ) ->method( 'newParameters' ) ->willReturn( $parameters ); $this->conditionBuilder = $this->getMockBuilder( '\SMW\Elastic\QueryEngine\ConditionBuilder' ) ->disableOriginalConstructor() ->setMethods( [ 'getTermsLookup', 'getStore', 'getID', 'interpretDescription' ] ) ->getMock(); $this->conditionBuilder->expects( $this->any() ) ->method( 'getStore' ) ->willReturn( $this->store ); $this->conditionBuilder->expects( $this->any() ) ->method( 'getTermsLookup' ) ->willReturn( $this->termsLookup ); $this->queryParser = $this->getMockBuilder( '\SMW\Query\Parser' ) ->disableOriginalConstructor() ->getMock(); } public function testCanConstruct() { $this->assertInstanceOf( ConceptDescriptionInterpreter::class, new ConceptDescriptionInterpreter( $this->conditionBuilder, $this->queryParser ) ); } public function testInterpretDescription_EmptyConcept() { $instance = new ConceptDescriptionInterpreter( $this->conditionBuilder, $this->queryParser ); $conceptDescription = $this->descriptionFactory->newConceptDescription( DIWikiPage::newFromText( 'Foo', SMW_NS_CONCEPT ) ); $this->assertEquals( [], $instance->interpretDescription( $conceptDescription ) ); } public function testInterpretDescription_AvailableConceptQuery() { $this->conditionBuilder->expects( $this->any() ) ->method( 'interpretDescription' ) ->willReturn( $this->conditionBuilder->newCondition( [ 'Foo' ] ) ); $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() ->getMock(); $concept = $this->getMockBuilder( '\SMW\DIConcept' ) ->disableOriginalConstructor() ->getMock(); $this->store->expects( $this->any() ) ->method( 'getPropertyValues' ) ->willReturn( [ $concept ] ); $this->queryParser->expects( $this->any() ) ->method( 'getQueryDescription' ) ->willReturn( $description ); $instance = new ConceptDescriptionInterpreter( $this->conditionBuilder, $this->queryParser ); $conceptDescription = $this->descriptionFactory->newConceptDescription( DIWikiPage::newFromText( 'Foo', SMW_NS_CONCEPT ) ); $this->assertEquals( '{"bool":{"must":["Foo"]}}', $instance->interpretDescription( $conceptDescription ) ); } }