/** * @dataProvider propertyProvider */ public function testFindTableIdForProperty($property, $expected) { $property = DIProperty::newFromUserLabel($property); $instance = new PropertyTableInfoFetcher(); $instance->setCustomSpecialPropertyList(array('_MDAT', '_MEDIA', '_MIME')); $this->assertEquals($expected, $instance->findTableIdForProperty($property)); }
public function testImportOfDifferentDateWithAssortmentOfOutputConversion() { $this->importedTitles = array('TimeDataTypeRegressionTest', 'Property:Has query date', 'Property:Has calendar date', 'Property:Has date'); $this->titleValidator->assertThatTitleIsKnown($this->importedTitles); $title = Title::newFromText('TimeDataTypeRegressionTest'); $expectedCategoryAsWikiValue = array('property' => new DIProperty('_INST'), 'propertyValues' => array('Regression test')); $expectedPropertiesFromImport = array('properties' => array(DIProperty::newFromUserLabel('Has date'), DIProperty::newFromUserLabel('Has calendar date'), DIProperty::newFromUserLabel('Has query date'), new DIProperty('_ASK'), new DIProperty('_MDAT'), new DIProperty('_SKEY'), new DIProperty('_SOBJ'), new DIProperty('_INST'))); $expectedDateValuesAsISO = array('valueFormatter' => $this->setISO8601DateValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has query date'), 'propertyValues' => array('2010-01-04T19:00:00', '2011-06-08', '1980-01-01', '2000-02-11T10:00:00', '2000-02-03')); $expectedDateValuesAsMediaWiki = array('valueFormatter' => $this->setMediaWikiDateValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has query date'), 'propertyValues' => array('19:00, 4 January 2010', '8 June 2011', '1 January 1980', '10:00, 11 February 2000', '3 February 2000')); $expectedDateValuesAsWikiValue = array('valueFormatter' => $this->setWikiValueDateValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has query date'), 'propertyValues' => array('4 January 2010 19:00:00', '8 June 2011', '1 January 1980', '11 February 2000 10:00:00', '3 February 2000')); // Note Windows vs Linux date conversion on PHP // where 14000000000 BC is 2147483647 BC on Windows $expectedCalendarSpecificDateValuesAsISO = array('valueFormatter' => $this->setISO8601DateValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has calendar date'), 'propertyValues' => array('--301-12-28', '--2147483647-01-01', '--14000000000-01-01', '2000-02-24', '1492-02-11')); $expectedCalendarSpecificDateValuesAsWikiValue = array('valueFormatter' => $this->setWikiValueDateValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has calendar date'), 'propertyValues' => array('1 January 300 BC', '2147483647 BC', '14000000000 BC', '24 February 2000', '2 February 1492')); $expectedCalendarSpecificDateValuesAsWikiValueWithGRCalendarModel = array('valueFormatter' => $this->setWikiValueDateWithGRCalendarModelValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has calendar date'), 'propertyValues' => array('28 December 301 BC', '2147483647 BC', '14000000000 BC', '24 February 2000', '11 February 1492')); $expectedCalendarSpecificDateValuesAsWikiValueWithJLCalendarModel = array('valueFormatter' => $this->setWikiValueDateWithJLCalendarModelValueFormatter(), 'property' => DIProperty::newFromUserLabel('Has calendar date'), 'propertyValues' => array('1 January 300 BC', '2147483647 BC', '14000000000 BC', '11 February 2000', '2 February 1492')); $this->semanticDataFinder = new ByPageSemanticDataFinder(); $this->semanticDataFinder->setTitle($title)->setStore($this->getStore()); $semanticDataBatches = array($this->semanticDataFinder->fetchFromOutput(), $this->semanticDataFinder->fetchFromStore()); $expectedDateValuesBatches = array($expectedDateValuesAsISO, $expectedDateValuesAsMediaWiki, $expectedDateValuesAsWikiValue, $expectedCalendarSpecificDateValuesAsISO, $expectedCalendarSpecificDateValuesAsWikiValue, $expectedCalendarSpecificDateValuesAsWikiValueWithGRCalendarModel, $expectedCalendarSpecificDateValuesAsWikiValueWithJLCalendarModel); foreach ($semanticDataBatches as $semanticData) { $this->semanticDataValidator->assertThatCategoriesAreSet($expectedCategoryAsWikiValue, $semanticData); $this->semanticDataValidator->assertThatPropertiesAreSet($expectedPropertiesFromImport, $semanticData); $this->assertBatchesOfDateValues($expectedDateValuesBatches, $semanticData); } }
public function testImportOfRecordValues() { $this->importedTitles = array('Property:Has record number field', 'Property:Has record page field', 'Property:Has record text field', 'Property:Has record type', 'Property:Has record type for single test', 'RecordDataTypePage', 'RecordDataTypeRegressionTest/WithSubpage', 'RecordDataTypeRegressionTest'); $this->titleValidator->assertThatTitleIsKnown($this->importedTitles); $title = Title::newFromText('RecordDataTypeRegressionTest'); $expectedCategoryAsWikiValue = array('property' => new DIProperty('_INST'), 'propertyValues' => array('Regression test', 'Data type regression test', 'Record type regression test')); $expectedSomeProperties = array('properties' => array(DIProperty::newFromUserLabel('RecordDataTypePage'), DIProperty::newFromUserLabel('BarText'), DIProperty::newFromUserLabel('BooPage'), DIProperty::newFromUserLabel('FooPage'), DIProperty::newFromUserLabel('QyuPage'), new DIProperty('_ASK'), new DIProperty('_MDAT'), new DIProperty('_SKEY'), new DIProperty('_SOBJ'), new DIProperty('_INST'))); $property = DIProperty::newFromUserLabel('Has record type for single test'); $valueString = 'ForSingleTestAsPage;ForSingleTestAsText;3333'; if ($property->findPropertyTypeID() === '_rec') { $valueString = 'ForSingleTestAsPage; ForSingleTestAsText; 3333'; } $expectedRecordTypeValuesAsWikiValue = array('subject' => DIWikiPage::newFromTitle($title), 'record' => $property, 'property' => $property, 'propertyValues' => array($valueString, '?; ?; ?')); $expectedRecordPageFieldValuesAsWikiValue = array('subject' => DIWikiPage::newFromTitle($title), 'record' => DIProperty::newFromUserLabel('Has record type'), 'property' => DIProperty::newFromUserLabel('Has record page field'), 'propertyValues' => array('FooPage', 'QyuPageOnSubobject', 'QyuPage', 'XeuiPageOnSubobject', 'RecordDataTypePage', 'BooPage')); $expectedRecordTextFieldValuesAsWikiValue = array('subject' => DIWikiPage::newFromTitle($title), 'record' => DIProperty::newFromUserLabel('Has record type'), 'property' => DIProperty::newFromUserLabel('Has record text field'), 'propertyValues' => array('BarText', 'ForSingleTestAsText', 'FooText', 'XeuiTextOnSubobject')); $expectedRecordNumberFieldValuesAsNumber = array('subject' => DIWikiPage::newFromTitle(Title::newFromText('RecordDataTypeRegressionTest/WithSubpage')), 'record' => DIProperty::newFromUserLabel('Has record type'), 'property' => DIProperty::newFromUserLabel('Has record number field'), 'propertyValues' => array(1111, 9001, 9999, 1009)); $semanticDataFinder = new ByPageSemanticDataFinder(); $semanticDataFinder->setTitle($title)->setStore($this->getStore()); $semanticDataBatches = array($this->getStore()->getSemanticData(DIWikiPage::newFromTitle($title))); foreach ($semanticDataBatches as $semanticData) { $this->semanticDataValidator->assertThatCategoriesAreSet($expectedCategoryAsWikiValue, $semanticData); $this->semanticDataValidator->assertThatPropertiesAreSet($expectedSomeProperties, $semanticData); $this->assertThatSemanticDataValuesAreSet($expectedRecordTypeValuesAsWikiValue, $semanticData); } $this->assertThatRecordValuesAreSet($expectedRecordTypeValuesAsWikiValue); $this->assertThatRecordValuesAreSet($expectedRecordPageFieldValuesAsWikiValue); $this->assertThatRecordValuesAreSet($expectedRecordTextFieldValuesAsWikiValue); $this->assertThatRecordValuesAreSet($expectedRecordNumberFieldValuesAsNumber); }
private function newDataValueForPagePropertyValue($property, $value) { $property = DIProperty::newFromUserLabel($property); $property->setPropertyTypeId('_wpg'); $dataItem = new DIWikiPage($value, NS_MAIN, ''); return $this->dataValueFactory->newDataItemValue($dataItem, $property); }
public function testPageMoveWithRemovalOfOldPage() { // PHPUnit query issue $this->skipTestForDatabase(array('postgres')); // Revison showed an issue on 1.19 not being null after the move $this->skipTestForMediaWikiVersionLowerThan('1.21'); // Further hooks required to ensure in-text annotations can be used for queries $this->mwHooksHandler->register('InternalParseBeforeLinks', $this->mwHooksHandler->getHookRegistry()->getDefinition('InternalParseBeforeLinks')); $this->mwHooksHandler->register('LinksUpdateConstructed', $this->mwHooksHandler->getHookRegistry()->getDefinition('LinksUpdateConstructed')); $title = Title::newFromText(__METHOD__ . '-old'); $expectedNewTitle = Title::newFromText(__METHOD__ . '-new'); $this->assertNull(WikiPage::factory($expectedNewTitle)->getRevision()); $this->pageCreator->createPage($title)->doEdit('[[Has function hook test::PageCompleteMove]]'); $this->pageCreator->getPage()->getTitle()->moveTo($expectedNewTitle, false, 'test', false); $this->assertNull(WikiPage::factory($title)->getRevision()); $this->assertNotNull(WikiPage::factory($expectedNewTitle)->getRevision()); /** * @query {{#ask: [[Has function hook test::PageCompleteMove]] }} */ $description = new SomeProperty(DIProperty::newFromUserLabel('Has function hook test'), new ValueDescription(new DIWikiPage('PageCompleteMove', 0), null, SMW_CMP_EQ)); $query = new Query($description, false, true); $query->querymode = Query::MODE_INSTANCES; $queryResult = $this->getStore()->getQueryResult($query); // #566 $this->assertCount(1, $queryResult->getResults()); $this->queryResultValidator->assertThatQueryResultHasSubjects(DIWikiPage::newFromTitle($expectedNewTitle), $queryResult); $this->toBeDeleted = array($title, $expectedNewTitle); }
public function testCreatePropertyFromLabelThatContainsInverseMarker() { $property = DIProperty::newFromUserLabel('-Foo'); $property->setInterwiki('bar'); $this->assertTrue($property->isInverse()); $this->assertEquals(new DiWikiPage('Foo', SMW_NS_PROPERTY, 'bar'), $property->getDiWikiPage()); }
/** * @since 2.5 * * @param integer $id * * @return boolean */ public function isExemptedPropertyById($id) { $dataItem = $this->store->getObjectIds()->getDataItemById($id); if (!$dataItem instanceof DIWikiPage || $dataItem->getDBKey() === '') { return false; } return $this->isExemptedProperty(DIProperty::newFromUserLabel($dataItem->getDBKey())); }
public function testSerializeFormatForTimeValue() { $property = \SMW\DIProperty::newFromUserLabel('Foo'); $property->setPropertyTypeId('_dat'); $printRequestFactory = new \SMW\Query\PrintRequestFactory(); $serialization = QueryResultSerializer::getSerialization(\SMWDITime::doUnserialize('2/1393/1/1'), $printRequestFactory->newPropertyPrintRequest($property)); $expected = array('timestamp' => '-18208281600', 'raw' => '2/1393/1/1'); $this->assertEquals($expected, $serialization); }
public function specialCharactersNameProvider() { $provider[] = array('特殊文字', 'Nuñez', DIProperty::newFromUserLabel('特殊文字')->setPropertyTypeId('_txt'), new DIBlob('Nuñez')); $provider[] = array('特殊字符', '^[0-9]*$', DIProperty::newFromUserLabel('特殊字符')->setPropertyTypeId('_txt'), new DIBlob('^[0-9]*$')); $provider[] = array('Caractères spéciaux', 'Caractères spéciaux', DIProperty::newFromUserLabel('Caractères spéciaux')->setPropertyTypeId('_wpg'), new DIWikiPage('âêîôûëïçé', NS_MAIN)); $provider[] = array('áéíóúñÑü¡¿', 'áéíóúñÑü¡¿', DIProperty::newFromUserLabel('áéíóúñÑü¡¿')->setPropertyTypeId('_num'), new DINumber(8888)); $provider[] = array('Foo', '{({[[&,,;-]]})}', DIProperty::newFromUserLabel('{({[[&,,;-]]})}')->setPropertyTypeId('_wpg'), new DIWikiPage('{({[[&,,;-]]})}', NS_MAIN)); return $provider; }
/** * @since 2.0 * * @return boolean */ public function process() { // Avoid having "noarticletext" info being generated for predefined // properties as we are going to display an introductory text if ($this->article->getTitle()->getNamespace() === SMW_NS_PROPERTY) { return DIProperty::newFromUserLabel($this->article->getTitle()->getText())->isUserDefined(); } return true; }
/** * @see SMWOrderedListPage::initParameters() * @note We use a smaller limit here; property pages might become large. */ protected function initParameters() { global $smwgPropertyPagingLimit; $this->limit = $smwgPropertyPagingLimit; $this->mProperty = DIProperty::newFromUserLabel($this->mTitle->getText()); $this->store = ApplicationFactory::getInstance()->getStore(); $this->propertyValue = DataValueFactory::getInstance()->newDataItemValue($this->mProperty); return true; }
public function testImportToVerifyAnnotationByTemplateInclusion() { $this->importedTitles = array('Foo-1-19-7', 'Template:FooAsk', 'Template:FooShow', 'Template:FooSubobject', 'Template:FooTemplate'); $this->titleValidator->assertThatTitleIsKnown($this->importedTitles); $expectedProperties = array('properties' => array(DIProperty::newFromUserLabel('Foo'), DIProperty::newFromUserLabel('Quux'), new DIProperty('_ASK'), new DIProperty('_MDAT'), new DIProperty('_SKEY'), new DIProperty('_SOBJ'), new DIProperty('_INST'))); $title = Title::newFromText('Foo-1-19-7'); $semanticDataFinder = new ByPageSemanticDataFinder(); $semanticDataFinder->setTitle($title)->setStore($this->getStore()); $this->semanticDataValidator->assertThatPropertiesAreSet($expectedProperties, $semanticDataFinder->fetchFromOutput()); }
public function valueDescriptionProvider() { $dataItem = new DIWikiPage('Foo', NS_MAIN); $provider[] = array($dataItem, null, SMW_CMP_EQ, array('comparator' => SMW_CMP_EQ, 'dataItem' => $dataItem, 'property' => null, 'queryString' => '[[:Foo]]', 'queryStringAsValue' => 'Foo', 'isSingleton' => true)); $provider[] = array($dataItem, null, SMW_CMP_LEQ, array('comparator' => SMW_CMP_LEQ, 'dataItem' => $dataItem, 'property' => null, 'queryString' => '[[≤Foo]]', 'queryStringAsValue' => '≤Foo', 'isSingleton' => false)); $property = DIProperty::newFromUserLabel('Foo')->setPropertyTypeId('_num'); $dataItem = new DINumber(9001); $provider[] = array($dataItem, $property, SMW_CMP_LEQ, array('comparator' => SMW_CMP_LEQ, 'dataItem' => $dataItem, 'property' => $property, 'queryString' => '[[≤9,001]]', 'queryStringAsValue' => '≤9,001', 'isSingleton' => false)); return $provider; }
protected function addPropertyValues() { $subject = $this->getSemanticData()->getSubject(); if ($subject->getNamespace() !== SMW_NS_PROPERTY) { return; } $property = DIProperty::newFromUserLabel(str_replace('_', ' ', $subject->getDBKey())); if (!$property->isUserDefined()) { return; } $this->findMandatoryTypeForImportVocabulary(); }
private function newFromUserLabel($label, $languageCode = false) { $property = DIProperty::newFromUserLabel($label, false, $languageCode); $canonicalLabel = $property->getCanonicalLabel(); // #1966 and #1968 // In case something goes wrong, a recursive loop will kill PHP // and we know we messed up if ($canonicalLabel !== '' && $label !== $canonicalLabel) { $this->newFromUserLabel($property->getCanonicalDiWikiPage()->getTitle()->getText()); } return array($label, $property); }
/** * @see Job::run * * @since 1.9 * * @return boolean */ public function run() { Profiler::In(__METHOD__, true); /** * @var Store */ $this->store = ApplicationFactory::getInstance()->getStore(); if ($this->getTitle()->getNamespace() === SMW_NS_PROPERTY) { $this->dispatchUpdateForProperty(DIProperty::newFromUserLabel($this->getTitle()->getText()))->pushToJobQueue(); } $this->dispatchUpdateForSubject(DIWikiPage::newFromTitle($this->getTitle()))->pushToJobQueue(); Profiler::Out(__METHOD__, true); return true; }
private function findMessageKeyFor($namespace) { if ($this->isPropertyPage($namespace)) { if (DIProperty::newFromUserLabel($this->editPage->getTitle()->getText())->isUserDefined()) { return 'smw-editpage-property-annotation-enabled'; } else { return 'smw-editpage-property-annotation-disabled'; } } elseif ($this->isConceptPage($namespace)) { return 'smw-editpage-concept-annotation-enabled'; } elseif ($this->isSemanticEnabledPage($namespace)) { return 'smw-editpage-annotation-enabled'; } return 'smw-editpage-annotation-disabled'; }
public function testChildSearchForValidPageTypeProperty() { $subject = new DIWikiPage('Foo', NS_MAIN); $property = DIProperty::newFromUserLabel('Bar'); $property->setPropertyTypeId('_wpg'); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $store->expects($this->atLeastOnce())->method('getPropertyValues')->will($this->returnValue(array())); $store->expects($this->at(1))->method('getPropertySubjects')->with($this->equalTo($property), $this->equalTo($subject))->will($this->returnValue(array(new DIWikiPage('Foo', NS_MAIN), new DIWikiPage('Ichi', NS_MAIN), new DIWikiPage('NotBeSelectable', NS_MAIN)))); $instance = new ByPropertyHierarchicalLinksFinder($store); $instance->setFindClosestDescendantState(true); $instance->setPropertySearchPatternByNamespace(array(NS_MAIN => array('Bar'))); $instance->tryToFindLinksFor($subject); $this->assertEmpty($instance->getParents()); $this->assertEquals(array(new DIWikiPage('Ichi', NS_MAIN)), $instance->getChildren()); }
protected function addPropertyValues() { $subject = $this->getSemanticData()->getSubject(); if ($subject->getNamespace() !== SMW_NS_PROPERTY) { return; } $property = DIProperty::newFromUserLabel(str_replace('_', ' ', $subject->getDBKey())); if (!$property->isUserDefined()) { return; } $dataItems = $this->getSemanticData()->getPropertyValues(new DIProperty('_IMPO')); if ($dataItems === null || $dataItems === array()) { return; } $this->addTypeFromImportVocabulary(current($dataItems)); }
/** * @see Job::run * * @since 1.9 * * @return boolean */ public function run() { if ($this->hasParameter('job-list')) { return $this->createUpdateJobsFromSecondaryDispatchRunJobList($this->getParameter('job-list')); } if ($this->getTitle()->getNamespace() === SMW_NS_PROPERTY) { $this->dispatchUpdateForProperty(DIProperty::newFromUserLabel($this->getTitle()->getText())); } else { $this->dispatchUpdateForSubject(DIWikiPage::newFromTitle($this->getTitle())); } // Push generated job list into a secondary dispatch run if ($this->jobs !== array()) { $this->createSecondaryDispatchRunWithChunkedJobList(); } Hooks::run('SMW::Job::AfterUpdateDispatcherJobComplete', array($this)); return true; }
public function testGetContentRoundTripForNonEmptyContent() { $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__)); $this->applicationFactory->getSettings()->set('smwgShowFactbox', SMW_FACTBOX_NONEMPTY); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $mockSemanticData = $this->mockbuilder->newObject('SemanticData', array('getSubject' => $subject, 'hasVisibleProperties' => true, 'getPropertyValues' => array($subject), 'getProperties' => array(DIProperty::newFromUserLabel('SomeFancyProperty')))); $parserOutput = $this->setupParserOutput($mockSemanticData); $message = $this->getMockBuilder('\\Message')->disableOriginalConstructor()->getMock(); $message->expects($this->any())->method('inContentLanguage')->will($this->returnSelf()); $messageBuilder = $this->getMockBuilder('\\SMW\\MediaWiki\\MessageBuilder')->disableOriginalConstructor()->getMock(); $messageBuilder->expects($this->any())->method('getMessage')->will($this->returnValue($message)); $instance = new Factbox($store, new ParserData($subject->getTitle(), $parserOutput), $messageBuilder); $result = $instance->doBuild()->getContent(); $this->assertInternalType('string', $result); $this->assertContains($subject->getDBkey(), $result); $this->assertEquals($subject->getTitle(), $instance->getTitle()); }
public function testCreatePageWithSubobjectParserFunctionForQueryResultLookup() { $this->titles[] = Title::newFromText('CreatePageWithSubobjectParserFunction'); $pageCreator = new PageCreator(); $pageCreator->createPage(Title::newFromText('Has subobject parser function test', SMW_NS_PROPERTY))->doEdit('[[Has type::Page]]'); $property = DIProperty::newFromUserLabel('Has subobject parser function test'); $pageCreator->createPage($this->titles[0])->doEdit('{{#subobject:|Has subobject parser function test=WXYZ|@sortkey=B}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=A}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=A}}' . '{{#subobject:|Has subobject parser function test=ABCD|@sortkey=C}}'); $propertyValue = new PropertyValue('__pro'); $propertyValue->setDataItem($property); $description = new SomeProperty($property, new ThingDescription()); $description->addPrintRequest(new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue)); $query = new Query($description, false, false); $query->querymode = Query::MODE_COUNT; $result = $this->getStore()->getQueryResult($query); $this->assertEquals(3, $result instanceof \SMWQueryResult ? $result->getCountValue() : $result); $query->querymode = Query::MODE_INSTANCES; $this->assertCount(3, $this->getStore()->getQueryResult($query)->getResults()); }
/** * @see Job::run * * @since 1.9 * * @return boolean */ public function run() { if ($this->hasParameter('job-list')) { return $this->createUpdateJobsFromListBySecondaryRun($this->getParameter('job-list')); } if ($this->getTitle()->getNamespace() === SMW_NS_PROPERTY) { $this->dispatchUpdateForProperty(DIProperty::newFromUserLabel($this->getTitle()->getText())); } else { $this->dispatchUpdateForSubject(DIWikiPage::newFromTitle($this->getTitle())); } // Push generated job list into a secondary dispatch run if ($this->jobs !== array()) { foreach (array_chunk($this->jobs, self::CHUNK_SIZE, true) as $jobs) { $updateDispatcherJob = new self(Title::newFromText('UpdateDispatcherJobForSecondaryRun'), array('job-list' => $jobs)); $updateDispatcherJob->insert(); } } return true; }
/** * @since 2.0 * * @return boolean */ public function process() { // Two possible ways of going forward: // // The FIRST seen here is to use the hook to override the known status // for predefined properties in order to avoid any edit link // which makes no-sense for predefined properties // // The SECOND approach is to inject SMWWikiPageValue with a setLinkOptions setter // that enables to set the custom options 'known' for each invoked linker during // getShortHTMLText // $linker->link( $this->getTitle(), $caption, $customAttributes, $customQuery, $customOptions ) // // @see also HooksTest::testOnTitleIsAlwaysKnown if ($this->title->getNamespace() === SMW_NS_PROPERTY) { if (!DIProperty::newFromUserLabel($this->title->getText())->isUserDefined()) { $this->result = true; } } return true; }
/** * {{#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); }
/** * @since 2.1 */ public function __construct() { $this->property = DIProperty::newFromUserLabel('Telephone number'); $this->property->setPropertyTypeId('_tel'); }
/** * '[[LocatedIn.MemberOf::Wonderland]]' */ public function testPropertyChain() { $description = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf'), new ValueDescription(new DIWikiPage('Wonderland', NS_MAIN, ''), DIProperty::newFromUserLabel('MemberOf'), SMW_CMP_EQ))); $instance = new CompoundConditionBuilder(); $condition = $instance->buildCondition($description); $this->assertInstanceOf('\\SMW\\SPARQLStore\\QueryEngine\\Condition\\WhereCondition', $condition); $expectedConditionString = $this->stringBuilder->addString('?result property:LocatedIn ?v1 .')->addNewLine()->addString('{ ?v1 property:MemberOf wiki:Wonderland .')->addNewLine()->addString('}')->addNewLine()->getString(); $this->assertEquals($expectedConditionString, $instance->convertConditionToString($condition)); }
/** * Displays the subject that is currently being browsed to. * * @return string A string containing the HTML with the subject line */ private function displayHead() { if ($this->subject->getDataItem()->getNamespace() === SMW_NS_PROPERTY) { $caption = ''; $dv = DataValueFactory::getInstance()->newDataValueByItem(DIProperty::newFromUserLabel($this->subject->getDataItem()->getDBKey())); $this->subject->setCaption($dv->getFormattedLabel(DataValueFormatter::WIKI_LONG)); } $html = "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n" . "<tr class=\"smwb-title\"><td colspan=\"2\">\n" . $this->subject->getLongHTMLText(smwfGetLinker()) . "\n" . "</td></tr>\n</table>\n"; return $html; }
private function isUserDefinedPropertyPage($diWikiPage) { if ($diWikiPage->getNamespace() !== SMW_NS_PROPERTY || $diWikiPage->getDBKey() === '') { return false; } return DIProperty::newFromUserLabel($diWikiPage->getDBKey())->isUserDefined(); }
/** * {{#ask: [[LocatedIn.Has subobject.MemberOf::+]] }} */ public function testSubqueryForCombinedSubobjectPropertyChainForWilcardSearch() { /** * Page ...-dreamland annotated with [[LocatedIn::BananaWonderland]] */ $semanticDataOfDreamland = $this->semanticDataFactory->setTitle(__METHOD__ . '-dreamland')->newEmptySemanticData(); $semanticDataOfDreamland->addDataValue($this->newDataValueForPagePropertyValue('LocatedIn', 'BananaWonderland')); /** * Page ...-fairyland annotated with [[LocatedIn::BananaWonderland]] */ $semanticDataOfFairyland = $this->semanticDataFactory->setTitle(__METHOD__ . '-fairyland')->newEmptySemanticData(); $semanticDataOfFairyland->addDataValue($this->newDataValueForPagePropertyValue('LocatedIn', 'BananaWonderland')); /** * Page BananaWonderland annotated with [[Has subobject.MemberOf::Wonderland]] */ $semanticDataOfWonderland = $this->semanticDataFactory->setTitle('BananaWonderland')->newEmptySemanticData(); $subobject = new Subobject($semanticDataOfWonderland->getSubject()->getTitle()); $subobject->setEmptyContainerForId('SomeSubobjectOnWonderland'); $subobject->addDataValue($this->newDataValueForPagePropertyValue('MemberOf', 'Wonderland')); $semanticDataOfWonderland->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $this->getStore()->updateData($semanticDataOfDreamland); $this->getStore()->updateData($semanticDataOfFairyland); $this->getStore()->updateData($semanticDataOfWonderland); $description = new SomeProperty(DIProperty::newFromUserLabel('LocatedIn')->setPropertyTypeId('_wpg'), new SomeProperty(DIProperty::newFromUserLabel('_SOBJ')->setPropertyTypeId('__sob'), new SomeProperty(DIProperty::newFromUserLabel('MemberOf')->setPropertyTypeId('_wpg'), new ThingDescription()))); $this->assertEquals($description, $this->queryParser->getQueryDescription('[[LocatedIn.Has subobject.MemberOf::+]]')); $query = new Query($description, false, false); $query->querymode = Query::MODE_INSTANCES; $queryResult = $this->getStore()->getQueryResult($query); $expectedSubjects = array($semanticDataOfDreamland->getSubject(), $semanticDataOfFairyland->getSubject()); $this->assertEquals(2, $queryResult->getCount()); $this->queryResultValidator->assertThatQueryResultHasSubjects($expectedSubjects, $queryResult); $this->subjectsToBeCleared = array($semanticDataOfWonderland->getSubject(), $semanticDataOfDreamland->getSubject(), $semanticDataOfFairyland->getSubject()); }