作者:Rikuforeve
项目:wik
public function testCorrectInversePrefixForPredefinedProperty()
{
$property = new DIProperty('_SOBJ', true);
$this->assertTrue($property->isInverse());
$label = $property->getLabel();
$this->assertEquals('-', $label[0]);
}
作者:whysass
项目:kmwik
public function testPredefinedProperty()
{
$instance = new HashBuilder();
$property = new DIProperty('_MDAT');
$dataItem = $property->getDiWikiPage();
$this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->getHashIdForDiWikiPage($dataItem)));
$this->assertEquals($dataItem, $instance->newDiWikiPageFromHash($instance->createHashIdFromSegments($property->getKey(), SMW_NS_PROPERTY)));
}
作者:WolfgangFah
项目:SemanticMediaWik
private function findBasePropertyToRedirectFor($label)
{
$property = new DIProperty(PropertyRegistry::getInstance()->findPropertyIdByLabel($label));
if ($property->getLabel() !== '' && $label !== $property->getLabel()) {
$outputPage = $this->getContext()->getOutput();
$outputPage->redirect($property->getDiWikiPage()->getTitle()->getFullURL());
}
}
作者:whysass
项目:kmwik
public function testAddUserDefinedBlobPropertyAsObjectToSemanticDataForStorage()
{
$property = new DIProperty('SomeBlobProperty');
$property->setPropertyTypeId('_txt');
$this->subjects[] = $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__));
$semanticData = new SemanticData($subject);
$semanticData->addPropertyObjectValue($property, new DIBlob('SomePropertyBlobValue'));
$this->getStore()->updateData($semanticData);
$this->assertArrayHasKey($property->getKey(), $this->getStore()->getSemanticData($subject)->getProperties());
}
作者:WolfgangFah
项目:SemanticMediaWik
/**
* @since 2.4
*
* @param DIProperty $property
* @param array|string $errorMsg
*
* @return DIContainer
*/
public function getContainerFor(DIProperty $property = null, $errorMsg = '')
{
if ($property !== null && $property->isInverse()) {
$property = new DIProperty($property->getKey());
}
$errorMsg = is_array($errorMsg) ? implode(' ', $errorMsg) : $errorMsg;
$subject = new DIWikiPage($this->subject->getDBkey(), $this->subject->getNamespace(), $this->subject->getInterwiki(), '_ERR' . md5(($property !== null ? $property->getKey() : 'UNKNOWN') . $errorMsg));
// Encode brackets to avoid an annotion is created/included
return $this->newDiContainer($subject, $property, InTextAnnotationParser::obscureAnnotation($errorMsg));
}
作者:jongfel
项目:SemanticMediaWik
public function testDescendingOrderedQueryResult()
{
$expectedSubjects = array(new DIWikiPage('AA', NS_MAIN), new DIWikiPage('AB', NS_MAIN), new DIWikiPage('AC', NS_MAIN));
$property = new DIProperty('SomeDescendingPageProperty');
$property->setPropertyTypeId('_wpg');
$query = $this->createQueryForSamplePagesThatContain($property, $expectedSubjects);
$query->sort = true;
$query->sortkeys = array($property->getKey() => 'DESC');
$query->setUnboundLimit(50);
$this->assertResultOrder(array_reverse($expectedSubjects), $this->getStore()->getQueryResult($query)->getResults());
}
作者:jongfel
项目:SemanticMediaWik
public function testUserDefinedPropertyUsedForInvalidValueAssignment()
{
$property = new DIProperty('SomePropertyWithInvalidValueAssignment');
$property->setPropertyTypeId('_tem');
$dataValue = $this->dataValueFactory->newDataValueByProperty($property, '1 Jan 1970');
$semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__);
$semanticData->addDataValue($dataValue);
$this->getStore()->updateData($semanticData);
$this->assertEquals(0, $this->searchForResultsThatCompareEqualToOnlySingularPropertyOf($property)->getCount());
$this->subjectsToBeCleared = array($semanticData->getSubject());
}
作者:jongfel
项目:SemanticMediaWik
/**
* @since 2.4
*
* @param DIProperty $property
*
* @return DataItem|false
*/
public function tryToFindAtLeastOneReferenceForProperty(DIProperty $property)
{
$dataItem = $property->getDiWikiPage();
$sid = $this->store->getObjectIds()->getSMWPageID($dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), '');
// Lets see if we have some lower/upper case matching for
// when wgCapitalLinks setting was involved
if (!$this->usesCapitalLinks && $sid == 0) {
$sid = $this->store->getObjectIds()->getSMWPageID(lcfirst($dataItem->getDBkey()), $dataItem->getNamespace(), $dataItem->getInterwiki(), '');
}
return $this->tryToFindAtLeastOneReferenceForId($sid);
}
作者:jongfel
项目:SemanticMediaWik
/**
* @since 2.4
*
* @param DIWikiPage $subject
* @param DIProperty $property
* @param RequestOptions|null $requestOptions
*
* @return array
*/
public function getPropertyValues(DIWikiPage $subject, DIProperty $property, RequestOptions $requestOptions = null)
{
$key = $property->getKey() . ':' . $subject->getSubobjectName() . ':' . ($requestOptions !== null ? $requestOptions->getHash() : null);
$container = $this->blobStore->read($this->getRootHashFrom($subject));
if ($container->has($key)) {
return $container->get($key);
}
$dataItems = $this->store->getPropertyValues($subject, $property, $requestOptions);
$container->set($key, $dataItems);
$this->blobStore->save($container);
return $dataItems;
}
作者:jongfel
项目:SemanticMediaWik
/**
* Create some initial DB entries for important built-in properties. Having the DB contents predefined
* allows us to safe DB calls when certain data is needed. At the same time, the entries in the DB
* make sure that DB-based functions work as with all other properties.
*/
private function doCheckInternalPropertyIndices($connection)
{
$this->messageReporter->reportMessage("\nSetting up internal property indices ...\n");
$this->doCheckPredefinedPropertyBorder($connection);
// now write actual properties; do that each time, it is cheap enough and we can update sortkeys by current language
$this->messageReporter->reportMessage(" ... writing entries for internal properties ...\n");
foreach (SMWSql3SmwIds::$special_ids as $prop => $id) {
$property = new DIProperty($prop);
$connection->replace(SQLStore::ID_TABLE, array('smw_id'), array('smw_id' => $id, 'smw_title' => $property->getKey(), 'smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => $this->store->getObjectIds()->getPropertyInterwiki($property), 'smw_subobject' => '', 'smw_sortkey' => $property->getCanonicalLabel()), __METHOD__);
}
$this->messageReporter->reportMessage(" ... done.\n");
}
作者:jongfel
项目:SemanticMediaWik
public function testFindSubpropertyList()
{
$property = new DIProperty('Foo');
$store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
$store->expects($this->once())->method('getPropertySubjects')->with($this->equalTo(new DIProperty('_SUBP')), $this->equalTo($property->getDiWikiPage()), $this->anything())->will($this->returnValue(array(DIWikiPage::newFromText('Bar', SMW_NS_PROPERTY))));
$cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMock();
$cache->expects($this->once())->method('contains')->will($this->returnValue(false));
$cache->expects($this->once())->method('save')->with($this->equalTo('_SUBP#Foo#-1#0##1##1#'), $this->anything());
$instance = new PropertyHierarchyLookup($store, $cache);
$expected = array(DIWikiPage::newFromText('Bar', SMW_NS_PROPERTY));
$this->assertEquals($expected, $instance->findSubpropertListFor($property));
}
作者:jongfel
项目:SemanticMediaWik
/**
* @since 2.5
*
* {@inheritDoc}
*/
public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem)
{
$diSubject = $expData->getSubject()->getDataItem();
if ($diSubject === null) {
return;
}
$expNsResource = $this->exporter->getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace());
$expElement = $this->exporter->getDataItemExpElement($dataItem);
if ($expElement === null || $expNsResource === null) {
return;
}
$expData->addPropertyObjectValue($expNsResource, $expElement);
$this->addResourceHelperValue($expData, $property, $dataItem);
}
作者:whysass
项目:kmwik
private function newDataValueForPagePropertyValue($property, $value)
{
$property = DIProperty::newFromUserLabel($property);
$property->setPropertyTypeId('_wpg');
$dataItem = new DIWikiPage($value, NS_MAIN, '');
return $this->dataValueFactory->newDataItemValue($dataItem, $property);
}
作者:jdforreste
项目:SemanticMediaWik
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());
}
作者:brandonphuon
项目:mediawik
public function testRegister()
{
$instance = new PropertyRegistry();
$instance->register();
$this->assertNotEmpty(DIProperty::findPropertyLabel(PropertyRegistry::SBL_PARENTPAGE));
$this->assertSame(SBL_PROP_PARENTPAGE, DIProperty::findPropertyLabel(PropertyRegistry::SBL_PARENTPAGE));
}
作者:WolfgangFah
项目:SemanticMediaWik
/**
* @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));
}
作者:whysass
项目:kmwik
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);
}
作者:WolfgangFah
项目:SemanticMediaWik
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);
}
}
作者:jongfel
项目:SemanticMediaWik
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);
}
作者:jongfel
项目:SemanticMediaWik
/**
* @since 2.5
*
* {@inheritDoc}
*/
public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem)
{
$diSubject = $expData->getSubject()->getDataItem();
if ($diSubject === null) {
return;
}
$expNsResource = $this->exporter->getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace());
if ($expNsResource === null) {
return;
}
$dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $property);
if (!$dataValue instanceof ImportValue) {
return;
}
$expData->addPropertyObjectValue($expNsResource, $this->exporter->getDataItemExpElement(new DIBlob($dataValue->getImportReference())));
$this->addResourceHelperValue($expData, $property, $dataItem);
}