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()); } }
protected function tearDown() { ApplicationFactory::clear(); NamespaceExaminer::clear(); PropertyRegistry::clear(); Settings::clear(); Exporter::getInstance()->clear(); parent::tearDown(); }
private function findBasePropertyToRedirectFor($label) { $property = new DIProperty(PropertyRegistry::getInstance()->findPropertyIdByLabel($label)); // Ensure to redirect to `Property:Modification date` and not using // a possible user contextualized version such as `Property:Date de modification` $canonicalLabel = $property->getCanonicalLabel(); if ($canonicalLabel !== '' && $label !== $canonicalLabel) { $outputPage = $this->getContext()->getOutput(); $outputPage->redirect($property->getCanonicalDiWikiPage()->getTitle()->getFullURL()); } }
private function findPropertyIdByLabel($label) { $property = new DIProperty(PropertyRegistry::getInstance()->findPropertyIdByLabel($label)); $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->findPropertyIdByLabel($property->getCanonicalDiWikiPage()->getTitle()->getText()); } return array($label, $property); }
protected function tearDown() { // If setUp is skipped early this might not be initialized if ($this->testEnvironment !== null) { $this->testEnvironment->tearDown(); } ApplicationFactory::clear(); NamespaceExaminer::clear(); PropertyRegistry::clear(); Settings::clear(); Exporter::getInstance()->clear(); parent::tearDown(); }
/** * Returns an introductory text for a predefined property * * @note In order to enable a more detailed description for a specific * predefined property a concatenated message key can be used (e.g * 'smw-pa-property-predefined' + <internal property key> => '_asksi' ) * * @since 1.9 * * @return string */ protected function getIntroductoryText() { $dv = DataValueFactory::getInstance()->newDataValueByItem($this->mProperty); $propertyName = $dv->getFormattedLabel(); $message = ''; if ($this->mProperty->isUserDefined()) { return $message; } $key = $this->mProperty->getKey(); if (($messageKey = PropertyRegistry::getInstance()->findPropertyDescriptionMsgKeyById($key)) !== '') { $messageKeyLong = $messageKey . '-long'; } else { $messageKey = 'smw-pa-property-predefined' . strtolower($key); $messageKeyLong = 'smw-pa-property-predefined-long' . strtolower($key); } $message .= wfMessage($messageKey)->exists() ? wfMessage($messageKey, $propertyName)->parse() : wfMessage('smw-pa-property-predefined-default', $propertyName)->parse(); $message .= wfMessage($messageKeyLong)->exists() ? ' ' . wfMessage($messageKeyLong)->parse() : ''; $message .= ' ' . wfMessage('smw-pa-property-predefined-common')->parse(); return Html::rawElement('div', array('class' => 'smw-property-predefined-intro plainlinks'), $message); }
/** * @deprecated since 2.1, use PropertyRegistry::registerPropertyAlias */ public static function registerPropertyAlias($id, $label) { PropertyRegistry::getInstance()->registerPropertyAlias($id, $label); }
/** * @dataProvider preferredLabelValueProvider */ public function testFormatWithPreferredLabel($property, $preferredLabel, $type, $linker, $expected) { // Ensures the mocked instance is injected and registered with the // PropertyRegistry instance \SMW\PropertyRegistry::clear(); $this->propertyLabelFinder = $this->getMockBuilder('\\SMW\\PropertyLabelFinder')->disableOriginalConstructor()->getMock(); $this->propertyLabelFinder->expects($this->any())->method('findPropertyListByLabelAndLanguageCode')->will($this->returnValue(array())); $this->propertyLabelFinder->expects($this->any())->method('findPreferredPropertyLabelByLanguageCode')->will($this->returnValue($preferredLabel)); $this->propertyLabelFinder->expects($this->any())->method('searchPropertyIdByLabel')->will($this->returnValue(false)); $this->testEnvironment->registerObject('PropertyLabelFinder', $this->propertyLabelFinder); $propertyValue = new PropertyValue(); $propertyValue->setOption('smwgDVFeatures', SMW_DV_PROV_LHNT); $propertyValue->setOption(PropertyValue::OPT_CONTENT_LANGUAGE, 'en'); $propertyValue->setOption(PropertyValue::OPT_USER_LANGUAGE, 'en'); $propertyValue->setUserValue($property); $instance = new PropertyValueFormatter($propertyValue); $expected = $this->testEnvironment->getLocalizedTextByNamespace(SMW_NS_PROPERTY, $expected); $this->assertEquals($expected, $instance->format($type, $linker)); \SMW\PropertyRegistry::clear(); }
public function testFindPropertyInfoForUnregisteredId() { $datatypeRegistry = $this->getMockBuilder('\\SMW\\DataTypeRegistry')->disableOriginalConstructor()->getMock(); $datatypeRegistry->expects($this->once())->method('getKnownTypeLabels')->will($this->returnValue(array())); $datatypeRegistry->expects($this->once())->method('getKnownTypeAliases')->will($this->returnValue(array())); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $propertyLabelFinder = new PropertyLabelFinder($store, array()); $propertyAliases = array(); $instance = new PropertyRegistry($datatypeRegistry, $propertyLabelFinder, $propertyAliases); $this->assertEquals('', $instance->findPropertyLabelById('_UnknownId')); $this->assertEquals('', $instance->getPropertyTypeId('_UnknownId')); $this->assertFalse($instance->findPropertyIdByLabel('unknownLabel')); $this->assertFalse($instance->findPropertyIdByLabel('unknownLabel', true)); }
private function getPredefinedPropertyDescription($property, $linker, $languageCode) { $description = ''; $key = $property->getKey(); if (($msgKey = PropertyRegistry::getInstance()->findPropertyDescriptionMsgKeyById($key)) === '') { $msgKey = 'smw-pa-property-predefined' . strtolower($key); } if (!Message::exists($msgKey)) { return $description; } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($property); $label = $dataValue->getFormattedLabel(); $message = Message::get(array($msgKey, $label), $linker === null ? Message::ESCAPED : Message::PARSE, $languageCode); return $message; }
public function testDataTypePropertyExemptionList() { $datatypeRegistry = $this->getMockBuilder('\\SMW\\DataTypeRegistry')->disableOriginalConstructor()->getMock(); $datatypeRegistry->expects($this->once())->method('getKnownTypeLabels')->will($this->returnValue(array('_foo' => 'Foo', '_foobar' => 'Foobar'))); $datatypeRegistry->expects($this->once())->method('getKnownTypeAliases')->will($this->returnValue(array('Bar' => '_bar'))); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $propertyLabelFinder = new PropertyLabelFinder($store, array()); $propertyAliases = new PropertyAliasFinder(); $dataTypePropertyExemptionList = array('Foo', 'Bar'); $instance = new PropertyRegistry($datatypeRegistry, $propertyLabelFinder, $propertyAliases, $dataTypePropertyExemptionList); $this->assertEquals('_foobar', $instance->findPropertyIdByLabel('Foobar')); $this->assertFalse($instance->findPropertyIdByLabel('Foo')); $this->assertFalse($instance->findPropertyIdByLabel('Bar')); }
public function testFindPropertyLabel() { $datatypeRegistry = $this->getMockBuilder('\\SMW\\DataTypeRegistry')->disableOriginalConstructor()->getMock(); $datatypeRegistry->expects($this->once())->method('getKnownTypeLabels')->will($this->returnValue(array())); $datatypeRegistry->expects($this->once())->method('getKnownTypeAliases')->will($this->returnValue(array())); $propertyLabels = array(); $propertyAliases = array(); $instance = new PropertyRegistry($datatypeRegistry, $propertyLabels, $propertyAliases); $instance->registerProperty(DIProperty::TYPE_HAS_TYPE, '__typ', 'Has type', true); $this->assertEquals('Has type', $instance->findPropertyLabelById('_TYPE')); $this->assertEquals('', $instance->findPropertyLabelById('_UnknownId')); // findPropertyLabel legacy test $this->assertEquals('Has type', $instance->findPropertyLabel('_TYPE')); // This was part of an extra test but the extra test caused an segfault on postgres travis-ci $this->assertEquals('__typ', $instance->getPropertyTypeId('_TYPE')); $this->assertEquals('', $instance->getPropertyTypeId('_UnknownId')); // getPredefinedPropertyTypeId legacy test $this->assertEquals('__typ', $instance->getPredefinedPropertyTypeId('_TYPE')); }