public function testCanConstructDIBlob()
 {
     $instance = new DataItemFactory();
     $this->assertInstanceOf('\\SMWDIBlob', $instance->newDIBlob('Foo'));
 }
 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;
 }