public function descriptionProvider() { $descriptionFactory = new DescriptionFactory(); #0 Disjunction $description = $descriptionFactory->newDisjunction(); $description->addDescription($descriptionFactory->newNamespaceDescription(NS_HELP)); $description->addDescription($descriptionFactory->newNamespaceDescription(NS_MAIN)); $expectedDisjunction = new \stdClass(); $expectedDisjunction->type = 3; $expectedDisjunction->components = array(1 => true, 2 => true); $provider[] = array($description, $expectedDisjunction); #1 Conjunction $description = $descriptionFactory->newConjunction(); $description->addDescription($descriptionFactory->newNamespaceDescription(NS_HELP)); $description->addDescription($descriptionFactory->newNamespaceDescription(NS_MAIN)); $expectedConjunction = new \stdClass(); $expectedConjunction->type = 4; $expectedConjunction->components = array(1 => true, 2 => true); $provider[] = array($description, $expectedConjunction); #2 No query $description = $descriptionFactory->newConjunction(); $description->addDescription($descriptionFactory->newThingDescription()); $expectedConjunction = new \stdClass(); $expectedConjunction->type = 0; $expectedConjunction->components = array(); $provider[] = array($description, $expectedConjunction); return $provider; }
private function newDisjunctionFor($currentDescription, $newDescription) { if ($this->queryFeatures & SMW_DISJUNCTION_QUERY) { return $this->descriptionFactory->newDisjunction(array($currentDescription, $newDescription)); } $this->addErrorWithMsgKey('smw_nodisjunctions', $newDescription->getQueryString()); return $currentDescription; }
public function testCanConstructDisjunction() { $descriptions = array(); $description = $this->getMockBuilder('\\SMW\\Query\\Language\\SomeProperty')->disableOriginalConstructor()->getMock(); $description->expects($this->once())->method('getPrintRequests')->will($this->returnValue(array())); $descriptions[] = $description; $description = $this->getMockBuilder('\\SMW\\Query\\Language\\ValueDescription')->disableOriginalConstructor()->getMock(); $description->expects($this->once())->method('getPrintRequests')->will($this->returnValue(array())); $descriptions[] = $description; $instance = new DescriptionFactory(); $this->assertInstanceOf('SMW\\Query\\Language\\Disjunction', $instance->newDisjunction($descriptions)); }
public function descriptionProvider() { $descriptionFactory = new DescriptionFactory(); $dataItemFactory = new DataItemFactory(); #0 Blob + wildcard $isFixedPropertyTable = false; $indexField = ''; $sortKeys = array(); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_txt'); $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newThingDescription()); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id"); $expected->sortfields = array(); $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); #1 WikiPage + SMW_CMP_EQ $isFixedPropertyTable = false; $indexField = 'wikipageIndex'; $sortKeys = array(); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_wpg'); $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Bar', NS_MAIN), null, SMW_CMP_EQ)); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id", 2 => "t0.wikipageIndex"); $expected->queryNumber = 0; $expected->where = ''; $expected->sortfields = array(); $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); #2 WikiPage + SMW_CMP_EQ + sort $isFixedPropertyTable = false; $indexField = 'wikipageIndex'; $sortKeys = array('Foo' => 'DESC'); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_wpg'); $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Bar', NS_MAIN), null, SMW_CMP_EQ)); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id", 2 => "t0.wikipageIndex"); $expected->queryNumber = 0; $expected->where = ''; $expected->sortfields = array('Foo' => 'idst0.smw_sortkey'); $expected->from = ' INNER JOIN AS idst0 ON idst0.smw_id=t0.wikipageIndex'; $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); #3 Blob + SMW_CMP_EQ $isFixedPropertyTable = false; $indexField = 'blobIndex'; $sortKeys = array(); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_txt'); $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Bar'), null, SMW_CMP_EQ)); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id"); $expected->queryNumber = 0; $expected->where = '(t0.blobIndex=fixedFooWhereCond)'; $expected->sortfields = array(); $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); #4 Blob + SMW_CMP_EQ + sort $isFixedPropertyTable = false; $indexField = 'blobIndex'; $sortKeys = array('Foo' => 'ASC'); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_txt'); $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Bar'), null, SMW_CMP_EQ)); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id"); $expected->queryNumber = 0; $expected->where = '(t0.blobIndex=fixedFooWhereCond)'; $expected->sortfields = array('Foo' => 't0.blobIndex'); $expected->from = ''; $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); #5 Check SemanticMaps compatibility mode (invokes `getSQLCondition`) $isFixedPropertyTable = false; $indexField = 'blobIndex'; $sortKeys = array(); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_txt'); $valueDescription = $this->getMockBuilder('\\SMW\\Query\\Language\\ValueDescription')->disableOriginalConstructor()->setMethods(array('getSQLCondition', 'getDataItem'))->getMock(); $valueDescription->expects($this->any())->method('getProperty')->will($this->returnValue($property)); $valueDescription->expects($this->any())->method('getDataItem')->will($this->returnValue($dataItemFactory->newDIBlob('13,56'))); $valueDescription->expects($this->once())->method('getSQLCondition')->will($this->returnValue('foo AND bar')); $description = $descriptionFactory->newSomeProperty($property, $valueDescription); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id"); $expected->queryNumber = 0; $expected->where = '(foo AND bar)'; $expected->sortfields = array(); $expected->from = ''; $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); #6, see 556 $isFixedPropertyTable = false; $indexField = ''; $sortKeys = array(); $property = $dataItemFactory->newDIProperty('Foo'); $property->setPropertyTypeId('_txt'); $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newDisjunction(array($descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Bar')), $descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Baz'))))); $expected = new \stdClass(); $expected->type = 1; $expected->joinTable = 'FooPropTable'; $expected->components = array(1 => "t0.p_id"); $expected->queryNumber = 0; $expected->where = '((t0.=fixedFooWhereCond) OR (t0.=fixedFooWhereCond))'; $expected->sortfields = array(); $expected->from = ''; $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected); return $provider; }