public function descriptionProvider()
 {
     #0 Disjunction
     $description = new Disjunction();
     $description->addDescription(new NamespaceDescription(NS_HELP));
     $description->addDescription(new NamespaceDescription(NS_MAIN));
     $expectedDisjunction = new \stdClass();
     $expectedDisjunction->type = 3;
     $expectedDisjunction->components = array(1 => true, 2 => true);
     $provider[] = array($description, $expectedDisjunction);
     #1 Conjunction
     $description = new Conjunction();
     $description->addDescription(new NamespaceDescription(NS_HELP));
     $description->addDescription(new NamespaceDescription(NS_MAIN));
     $expectedConjunction = new \stdClass();
     $expectedConjunction->type = 4;
     $expectedConjunction->components = array(1 => true, 2 => true);
     $provider[] = array($description, $expectedConjunction);
     #2 No query
     $description = new Conjunction();
     $description->addDescription(new ThingDescription());
     $expectedConjunction = new \stdClass();
     $expectedConjunction->type = 0;
     $expectedConjunction->components = array();
     $provider[] = array($description, $expectedConjunction);
     return $provider;
 }
Esempio n. 2
0
 /**
  * @dataProvider disjunctionProvider
  */
 public function testCommonMethods($descriptions, $expected)
 {
     $instance = new Disjunction($descriptions);
     $this->assertEquals($expected['descriptions'], $instance->getDescriptions());
     $this->assertEquals($expected['queryString'], $instance->getQueryString());
     $this->assertEquals($expected['queryStringAsValue'], $instance->getQueryString(true));
     $this->assertEquals($expected['isSingleton'], $instance->isSingleton());
     $this->assertEquals(array(), $instance->getPrintRequests());
     $this->assertEquals($expected['size'], $instance->getSize());
     $this->assertEquals($expected['depth'], $instance->getDepth());
     $this->assertEquals($expected['queryFeatures'], $instance->getQueryFeatures());
 }
 /**
  * {{#ask: [[Category:WickedPlaces]] OR [[LocatedIn.MemberOf::Wonderland]] }}
  */
 public function testDisjunctionSubqueryForPageTypePropertyChainThatComparesEqualToValue()
 {
     /**
      * Page ...-dangerland annotated with [[Category:WickedPlaces]]
      */
     $semanticDataOfDangerland = $this->semanticDataFactory->setTitle(__METHOD__ . '-dangerland')->newEmptySemanticData();
     $semanticDataOfDangerland->addPropertyObjectValue(new DIProperty('_INST'), new DIWikiPage('WickedPlaces', NS_CATEGORY));
     $this->subjectsToBeCleared[] = $semanticDataOfDangerland->getSubject();
     $this->getStore()->updateData($semanticDataOfDangerland);
     /**
      * Page ...-dreamland annotated with [[LocatedIn::BananaWonderland]]
      */
     $semanticDataOfDreamland = $this->semanticDataFactory->setTitle(__METHOD__ . '-dreamland')->newEmptySemanticData();
     $semanticDataOfDreamland->addPropertyObjectValue(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new DIWikiPage('BananaWonderland', NS_MAIN));
     $this->subjectsToBeCleared[] = $semanticDataOfDreamland->getSubject();
     $this->getStore()->updateData($semanticDataOfDreamland);
     /**
      * Page BananaWonderland annotated with [[MemberOf::Wonderland]]
      */
     $semanticDataOfWonderland = $this->semanticDataFactory->setTitle('BananaWonderland')->newEmptySemanticData();
     $semanticDataOfWonderland->addPropertyObjectValue(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new DIWikiPage('Wonderland', NS_MAIN));
     $this->subjectsToBeCleared[] = $semanticDataOfWonderland->getSubject();
     $this->getStore()->updateData($semanticDataOfWonderland);
     /**
      * Query with [[Category:WickedPlaces]] OR [[LocatedIn.MemberOf::Wonderland]]
      */
     $someProperty = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new ValueDescription(new DIWikiPage('Wonderland', NS_MAIN, ''), DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), SMW_CMP_EQ)));
     $classDescription = new ClassDescription(new DIWikiPage('WickedPlaces', NS_CATEGORY, ''));
     $description = new Disjunction();
     $description->addDescription($classDescription);
     $description->addDescription($someProperty);
     $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:WickedPlaces]] OR [[LocatedIn.MemberOf::Wonderland]]'));
     $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:WickedPlaces]] OR [[LocatedIn::<q>[[MemberOf::Wonderland]]</q>]]'));
     $query = new Query($description, false, false);
     $query->querymode = Query::MODE_INSTANCES;
     $queryResult = $this->getStore()->getQueryResult($query);
     $expectedSubjects = array($semanticDataOfDreamland->getSubject(), $semanticDataOfDangerland->getSubject());
     $this->assertEquals(2, $queryResult->getCount());
     $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult);
 }
 public function testDisjunctiveNamespaceDescription()
 {
     $connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock();
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $description = new Disjunction();
     $description->addDescription(new NamespaceDescription(NS_HELP));
     $description->addDescription(new NamespaceDescription(NS_MAIN));
     $instance = new QuerySegmentListBuilder($store);
     $instance->buildQuerySegmentFor($description);
     $expectedDisjunction = new \stdClass();
     $expectedDisjunction->type = 3;
     $expectedHelpNs = new \stdClass();
     $expectedHelpNs->type = 1;
     $expectedHelpNs->where = "t1.smw_namespace=";
     $expectedMainNs = new \stdClass();
     $expectedMainNs->type = 1;
     $expectedMainNs->where = "t2.smw_namespace=";
     $this->assertEquals(0, $instance->getLastQuerySegmentId());
     $this->assertEmpty($instance->getErrors());
     $expected = array($expectedDisjunction, $expectedHelpNs, $expectedMainNs);
     $this->querySegmentValidator->assertThatContainerContains($expected, $instance->getQuerySegmentList());
 }
 public function testDisjunctionForCategoryChainDescription()
 {
     $classFooDescription = new ClassDescription(new DIWikiPage('Foo', NS_CATEGORY, ''));
     $classBarDescription = new ClassDescription(new DIWikiPage('Bar', NS_CATEGORY, ''));
     $description = new Disjunction();
     $description->addDescription($classFooDescription);
     $description->addDescription($classBarDescription);
     $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:Foo||Bar]]'));
     $this->assertEquals($description, $this->queryParser->getQueryDescription('[[Category:Foo]] OR [[Category:Bar]]'));
 }