protected function setUp() { parent::setUp(); $this->applicationFactory = ApplicationFactory::getInstance(); $settings = Settings::newFromArray(array('smwgShowFactbox' => SMW_FACTBOX_NONEMPTY, 'smwgFactboxUseCache' => true, 'smwgCacheType' => 'hash', 'smwgLinksInValues' => false, 'smwgInlineErrors' => true)); $this->applicationFactory->registerObject('Settings', $settings); }
/** * @since 1.9 */ protected function loadAtInstantiation() { /** * Settings object definition * * @since 1.9 * * @return Settings */ $this->registerObject('Settings', function () { return Settings::newFromGlobals(); }, DependencyObject::SCOPE_SINGLETON); /** * Store object definition * * @since 1.9 * * @return Store */ $this->registerObject('Store', function (DependencyBuilder $builder) { return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore')); }, DependencyObject::SCOPE_SINGLETON); /** * @since 1.9 * * @return Cache */ $this->registerObject('Cache', function (DependencyBuilder $builder) { return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache(); }, DependencyObject::SCOPE_SINGLETON); }
/** * @depends testGetPropertyTables */ public function testPropertyTablesWithValidCustomizableProperties() { $instance = $this->acquireInstance(); $instance->setConfiguration(Settings::newFromArray(array('smwgFixedProperties' => array(), 'smwgPageSpecialProperties' => array('_MDAT', '_MEDIA')))); $this->assertCount($this->defaultPropertyTableCount + 2, $instance->getPropertyTables()); $instance->clear(); }
/** * Returns a static instance with an invoked global settings array * * @par Example: * @code * \SMW\NamespaceExaminer::getInstance()->isSemanticEnabled( NS_MAIN ) * @endcode * * @note Used in smwfIsSemanticsProcessed * * @since 1.9 * * @return NamespaceExaminer */ public static function getInstance() { if (self::$instance === null) { self::$instance = self::newFromArray(Settings::newFromGlobals()->get('smwgNamespacesWithSemanticLinks')); } return self::$instance; }
/** * @since 1.9 */ protected function loadAtInstantiation() { /** * Settings object definition * * @since 1.9 * * @return Settings */ $this->registerObject('Settings', function () { return Settings::newFromGlobals(); }, DependencyObject::SCOPE_SINGLETON); /** * Store object definition * * @since 1.9 * * @return Store */ $this->registerObject('Store', function (DependencyBuilder $builder) { return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore')); }, DependencyObject::SCOPE_SINGLETON); /** * CacheHandler object definition * * @since 1.9 * * @return CacheHandler */ $this->registerObject('CacheHandler', function (DependencyBuilder $builder) { return CacheHandler::newFromId($builder->newObject('Settings')->get('smwgCacheType')); }, DependencyObject::SCOPE_SINGLETON); }
private function registerSettings() { $this->applicationFactory->registerObject('Settings', Settings::newFromGlobals($this->globalVars)); if (CompatibilityMode::extensionNotEnabled()) { CompatibilityMode::disableSemantics(); } }
/** * Returns information related to user-defined properties * * @since 1.9 * * @param Title $title * @param DIProperty $property * @param integer $useCount * * @return array */ private function getUserDefinedPropertyInfo($title, $property, $useCount) { if ($useCount <= $this->settings->get('smwgPropertyLowUsageThreshold')) { $this->getMessageFormatter()->addFromKey('smw_propertyhardlyused'); } // User defined types default to Page $typestring = SMWTypesValue::newFromTypeId($this->settings->get('smwgPDefaultType'))->getLongHTMLText($this->getLinker()); $label = htmlspecialchars($property->getLabel()); $linkAttributes = array(); if (isset($property->id)) { $linkAttributes['title'] = 'ID: ' . $property->id; } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($property); $dataValue->setLinkAttributes($linkAttributes); $proplink = $dataValue->getFormattedLabel(DataValueFormatter::HTML_SHORT, $this->getLinker()); if (!$title->exists()) { $this->getMessageFormatter()->addFromKey('smw_propertylackspage'); } $typeProperty = new DIProperty('_TYPE'); $types = $this->store->getPropertyValues($property->getDiWikiPage(), $typeProperty); if (count($types) >= 1) { $typeDataValue = DataValueFactory::getInstance()->newDataValueByItem(current($types), $typeProperty); $typestring = $typeDataValue->getLongHTMLText($this->getLinker()); } else { $this->getMessageFormatter()->addFromKey('smw_propertylackstype', $typestring); } return array($typestring, $proplink); }
protected function setUp() { parent::setUp(); $this->applicationFactory = ApplicationFactory::getInstance(); $settings = Settings::newFromArray(array('smwgFactboxUseCache' => true, 'smwgCacheType' => 'hash')); $this->applicationFactory->registerObject('Settings', $settings); }
protected function setUp() { parent::setUp(); $this->store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $this->skin = $this->getMockBuilder('\\Skin')->disableOriginalConstructor()->getMock(); $this->settings = Settings::newFromArray(array('smwgPDefaultType' => '_wpg', 'smwgPropertyLowUsageThreshold' => 5, 'smwgPropertyZeroCountDisplay' => true)); $this->dataItemFactory = new DataItemFactory(); }
public function testGetDefaultStore() { $instance = StoreFactory::getStore(); $this->assertInstanceOf(Settings::newFromGlobals()->get('smwgDefaultStore'), $instance); $this->assertSame(StoreFactory::getStore(), $instance); StoreFactory::clear(); $this->assertNotSame(StoreFactory::getStore(), $instance); }
protected function setUp() { parent::setUp(); $this->store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $this->skin = $this->getMockBuilder('\\Skin')->disableOriginalConstructor()->getMock(); $this->settings = Settings::newFromArray(array()); $this->dataItemFactory = new DataItemFactory(); }
protected function tearDown() { ApplicationFactory::clear(); NamespaceExaminer::clear(); PropertyRegistry::clear(); Settings::clear(); Exporter::getInstance()->clear(); parent::tearDown(); }
protected function setUp() { parent::setUp(); $this->applicationFactory = ApplicationFactory::getInstance(); $settings = Settings::newFromArray(array('smwgCacheType' => 'hash', 'smwgEnableUpdateJobs' => false)); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $this->applicationFactory->registerObject('Store', $store); $this->applicationFactory->registerObject('Settings', $settings); }
protected function setUp() { parent::setUp(); $this->applicationFactory = ApplicationFactory::getInstance(); $settings = Settings::newFromArray(array('smwgFactboxUseCache' => true, 'smwgCacheType' => 'hash', 'smwgLinksInValues' => false, 'smwgInlineErrors' => true)); $this->applicationFactory->registerObject('Settings', $settings); $this->cache = $this->applicationFactory->newCacheFactory()->newFixedInMemoryCache(); $this->applicationFactory->registerObject('Cache', $this->cache); }
/** * @dataProvider skinTemplateDataProvider */ public function testProcess($setup, $expected) { $toolbox = ''; ApplicationFactory::getInstance()->registerObject('Settings', Settings::newFromArray($setup['settings'])); $instance = new BaseTemplateToolbox($setup['skinTemplate'], $toolbox); $this->assertTrue($instance->process()); if ($expected['count'] == 0) { return $this->assertEmpty($toolbox); } $this->assertCount($expected['count'], $toolbox['smw-browse']); }
public function testProcess() { $oldTitle = MockTitle::buildMock('old'); $newTitle = MockTitle::buildMock('new'); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $store->expects($this->once())->method('changeTitle')->with($this->equalTo($oldTitle), $this->equalTo($newTitle), $this->anything(), $this->anything()); $this->applicationFactory->registerObject('Settings', Settings::newFromArray(array('smwgCacheType' => 'hash', 'smwgAutoRefreshOnPageMove' => true))); $this->applicationFactory->registerObject('Store', $store); $instance = new TitleMoveComplete($oldTitle, $newTitle, new MockSuperUser(), 0, 0); $this->assertTrue($instance->process()); }
/** * @dataProvider wikiPageDataProvider */ public function testProcess($parameters, $expected) { $this->applicationFactory->registerObject('Settings', Settings::newFromArray($parameters['settings'])); $instance = new NewRevisionFromEditComplete($parameters['wikiPage'], $parameters['revision'], 0); $this->assertTrue($instance->process()); $editInfo = $parameters['editInfo']; if ($editInfo && $editInfo->output instanceof ParserOutput) { $parserData = $this->applicationFactory->newParserData($parameters['wikiPage']->getTitle(), $editInfo->output); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserData->getSemanticData()); } }
public function testDeleteSubjectForNotSupportedSemanticNamespace() { $oldTitle = \Title::newFromText('Old'); $newTitle = \Title::newFromText('New', NS_HELP); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $store->expects($this->once())->method('deleteSubject')->with($this->equalTo($oldTitle)); $this->applicationFactory->registerObject('Settings', Settings::newFromArray(array('smwgCacheType' => 'hash', 'smwgAutoRefreshOnPageMove' => true, 'smwgNamespacesWithSemanticLinks' => array(NS_MAIN => true, NS_HELP => false)))); $this->applicationFactory->registerObject('Store', $store); $instance = new TitleMoveComplete($oldTitle, $newTitle, new MockSuperUser(), 0, 0); $this->assertTrue($instance->process()); }
/** * @dataProvider specialPropertiesDataProvider */ public function testAddSpecialProperties(array $parameters, array $expected) { $semanticData = $this->semanticDataFactory->setSubject($parameters['subject'])->newEmptySemanticData(); $pageInfo = $this->getMockBuilder('\\SMW\\PageInfo')->disableOriginalConstructor()->getMock(); foreach ($parameters['pageInfo'] as $method => $returnValue) { $pageInfo->expects($this->any())->method($method)->will($this->returnValue($returnValue)); } $this->applicationFactory->registerObject('Settings', Settings::newFromArray($parameters['settings'])); $instance = new PredefinedPropertyAnnotator(new NullPropertyAnnotator($semanticData), $pageInfo); $instance->addAnnotation(); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance->getSemanticData()); }
/** * @dataProvider textDataProvider */ public function testTextChangeWithParserOuputUpdateIntegration($parameters, $expected) { $text = $parameters['text']; $parser = $this->parserFactory->newFromTitle($parameters['title']); $instance = new InternalParseBeforeLinks($parser, $text); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($parameters['settings'])); $this->assertTrue($instance->process()); $this->assertEquals($expected['resultText'], $text); $parserData = $this->applicationFactory->newParserData($parser->getTitle(), $parser->getOutput()); $this->assertEquals($expected['propertyCount'] > 0, $parser->getOutput()->getProperty('smw-semanticdata-status')); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserData->getSemanticData()); }
/** * @dataProvider annotationDataProvider */ public function testChainableDecoratorAnnotation(array $parameters, array $expected) { $pageInfoProvider = $this->getMockBuilder('\\SMW\\PageInfo')->disableOriginalConstructor()->getMock(); $pageInfoProvider->expects($this->atLeastOnce())->method('getModificationDate')->will($this->returnValue($parameters['modificationDate'])); $semanticData = $this->semanticDataFactory->newEmptySemanticData(__METHOD__); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($parameters['settings'])); $instance = new CategoryPropertyAnnotator(new NullPropertyAnnotator($semanticData), $parameters['categories']); $instance = new SortKeyPropertyAnnotator($instance, $parameters['sortkey']); $instance = new PredefinedPropertyAnnotator($instance, $pageInfoProvider); $instance->addAnnotation(); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance->getSemanticData()); }
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(); }
/** * @dataProvider hiddenCategoriesDataProvider */ public function testAddCategoriesWithHiddenCategories(array $parameters, array $expected) { $expectedPageLookup = $parameters['settings']['smwgShowHiddenCategories'] ? $this->never() : $this->atLeastOnce(); $wikiPage = $this->getMockBuilder('\\WikiPage')->disableOriginalConstructor()->getMock(); $wikiPage->expects($expectedPageLookup)->method('getHiddenCategories')->will($this->returnValue($parameters['hidCategories'])); $pageCreator = $this->getMockBuilder('\\SMW\\MediaWiki\\PageCreator')->disableOriginalConstructor()->getMock(); $pageCreator->expects($expectedPageLookup)->method('createPage')->will($this->returnValue($wikiPage)); $semanticData = $this->semanticDataFactory->setSubject(new DIWikiPage(__METHOD__, $parameters['namespace'], ''))->newEmptySemanticData(); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($parameters['settings'])); $this->applicationFactory->registerObject('PageCreator', $pageCreator); $instance = new CategoryPropertyAnnotator(new NullPropertyAnnotator($semanticData), $parameters['categories']); $instance->addAnnotation(); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $semanticData); }
/** * Factory method that creates a CacheHandler instance and instantiate a * BagOStuff object from available settings ($smwgCacheType) while * invoking additional parameters ($wgCachePrefix etc.) * * @par Example: * @code * $cache = new CacheHandler::newFromId()->setkey( new CachIdGenerator( 'Foo' ) ) * * $cache->set( 'CacheableObject' ) * $cache->get() returns 'CacheableObject' * $cache->delete() deletes 'CacheableObject' * @endcode * * @note If a BagOStuff instance is not available setCacheEnabled() is * disabled by default which prevents to run into unintended behaviour * while trying to access BagOStuff methods. * * @note This method is exposed to $wgObjectCaches, $wgCachePrefix globals * which can't and shouldn't be accessed otherwise. It is the task of this * method alone to invoke globals and avoid leakage into the object * life cycle. * * @note This method serves invoked instances from a static variable due to * the fact that the actual working object is being accessed through * getCache() and therefore not in direct conflict with its testability. * * @since 1.9 * * @param string $id Ids available in wgObjectCaches * * @return CacheHandler */ public static function newFromId($id = false) { $cacheType = $id ? $id : Settings::newFromGlobals()->get('smwgCacheType'); if (!isset(self::$instance[$cacheType])) { if ($cacheType && array_key_exists($cacheType, $GLOBALS['wgObjectCaches'])) { $cache = new self(ObjectCache::getInstance($cacheType)); } else { $cache = new self(); } $cache->setCacheEnabled(true); self::$instance[$cacheType] = $cache; } return self::$instance[$cacheType]; }
/** * @dataProvider templateDataProvider */ public function testPreprocessTemplateAndParse($namespace, array $settings, $text, $tmplValue, array $expected) { $parserOutput = new ParserOutput(); $title = Title::newFromText(__METHOD__, $namespace); $outputText = $this->runTemplateTransclusion($title, $text, $tmplValue); $this->applicationFactory->registerObject('Settings', Settings::newFromArray($settings)); $parserData = new ParserData($title, $parserOutput); $instance = new InTextAnnotationParser($parserData, new MagicWordsFinder(), new RedirectTargetFinder()); $instance->parse($outputText); $this->assertContains($expected['resultText'], $outputText); $parserData = new ParserData($title, $parserOutput); $this->assertInstanceOf('\\SMW\\SemanticData', $parserData->getSemanticData()); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserData->getSemanticData()); }
protected function setUp() { parent::setUp(); $this->testEnvironment = new TestEnvironment(); $this->store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $this->skin = $this->getMockBuilder('\\Skin')->disableOriginalConstructor()->getMock(); $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock(); $blobStore = $this->getMockBuilder('\\Onoi\\BlobStore\\BlobStore')->disableOriginalConstructor()->getMock(); $blobStore->expects($this->any())->method('read')->will($this->returnValue($container)); $cachedPropertyValuesPrefetcher = $this->getMockBuilder('\\SMW\\CachedPropertyValuesPrefetcher')->setConstructorArgs(array($this->store, $blobStore))->setMethods(null)->getMock(); $this->testEnvironment->registerObject('CachedPropertyValuesPrefetcher', $cachedPropertyValuesPrefetcher); $this->settings = Settings::newFromArray(array()); $this->dataItemFactory = new DataItemFactory(); }
private function registerCallbackHandlers($callbackLoader) { $callbackLoader->registerExpectedReturnType('Settings', '\\SMW\\Settings'); $callbackLoader->registerCallback('Settings', function () use($callbackLoader) { return Settings::newFromGlobals(); }); $callbackLoader->registerExpectedReturnType('Store', '\\SMW\\Store'); $callbackLoader->registerCallback('Store', function () use($callbackLoader) { return StoreFactory::getStore($callbackLoader->singleton('Settings')->get('smwgDefaultStore')); }); $callbackLoader->registerExpectedReturnType('Cache', '\\Onoi\\Cache\\Cache'); $callbackLoader->registerCallback('Cache', function () { return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache(); }); $callbackLoader->registerCallback('NamespaceExaminer', function () use($callbackLoader) { return NamespaceExaminer::newFromArray($callbackLoader->singleton('Settings')->get('smwgNamespacesWithSemanticLinks')); }); $callbackLoader->registerExpectedReturnType('ParserData', '\\SMW\\ParserData'); $callbackLoader->registerCallback('ParserData', function (\Title $title, \ParserOutput $parserOutput) { return new ParserData($title, $parserOutput); }); $callbackLoader->registerCallback('MessageFormatter', function (\Language $language) { return new MessageFormatter($language); }); $callbackLoader->registerExpectedReturnType('PageCreator', '\\SMW\\MediaWiki\\PageCreator'); $callbackLoader->registerCallback('PageCreator', function () { return new PageCreator(); }); $callbackLoader->registerExpectedReturnType('TitleCreator', '\\SMW\\MediaWiki\\TitleCreator'); $callbackLoader->registerCallback('TitleCreator', function () { return new TitleCreator(); }); $callbackLoader->registerExpectedReturnType('WikiPage', '\\WikiPage'); $callbackLoader->registerCallback('WikiPage', function (\Title $title) { return \WikiPage::factory($title); }); $callbackLoader->registerExpectedReturnType('ContentParser', '\\SMW\\ContentParser'); $callbackLoader->registerCallback('ContentParser', function (\Title $title) { return new ContentParser($title); }); $callbackLoader->registerExpectedReturnType('JobFactory', '\\SMW\\MediaWiki\\Jobs\\JobFactory'); $callbackLoader->registerCallback('JobFactory', function () { return new JobFactory(); }); $callbackLoader->registerExpectedReturnType('FactboxFactory', '\\SMW\\Factbox\\FactboxFactory'); $callbackLoader->registerCallback('FactboxFactory', function () { return new FactboxFactory(); }); }
public function testSemanticDataParserOuputUpdateIntegration() { $settings = Settings::newFromArray(array('smwgCacheType' => 'hash', 'smwgEnableUpdateJobs' => false, 'smwgUseCategoryHierarchy' => false, 'smwgCategoriesAsInstances' => true, 'smwgShowHiddenCategories' => true)); $this->applicationFactory->registerObject('Settings', $settings); $text = ''; $title = Title::newFromText(__METHOD__); $parser = $this->parserFactory->newFromTitle($title); $parser->getOutput()->addCategory('Foo', 'Foo'); $parser->getOutput()->addCategory('Bar', 'Bar'); $parser->getOutput()->setProperty('smw-semanticdata-status', true); $instance = new ParserAfterTidy($parser, $text); $this->assertTrue($instance->process()); $expected = array('propertyCount' => 2, 'propertyKeys' => array('_INST', '_SKEY'), 'propertyValues' => array('Foo', 'Bar', $title->getText())); $parserData = $this->applicationFactory->newParserData($title, $parser->getOutput()); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $parserData->getSemanticData()); }
public function testCanonicalNames() { $this->mwHooksHandler->deregisterListedHooks(); $count = 0; $index = NamespaceManager::buildNamespaceIndex(Settings::newFromGlobals()->get('smwgNamespaceIndex')); $names = NamespaceManager::getCanonicalNames(); $this->assertInternalType('array', $names); $this->assertInternalType('array', $index); foreach ($index as $ns => $idx) { $mwNamespace = MWNamespace::getCanonicalName($idx); if ($mwNamespace && isset($names[$idx])) { $this->assertEquals($mwNamespace, $names[$idx]); $count++; } } $this->assertCount($count, $names, "Asserts that expected amount of cannonical names have been verified"); }
protected function skipConcept($title, $concept = null) { $skip = false; if ($concept === null) { $skip = 'page not cachable (no concept description, maybe a redirect)'; } elseif ($this->hasOption('update') && $concept->getCacheStatus() !== 'full') { $skip = 'page not cached yet'; } elseif ($this->hasOption('old') && $concept->getCacheStatus() === 'full' && $concept->getCacheDate() > strtotime('now') - intval($this->options['old']) * 60) { $skip = 'cache is not old yet'; } elseif ($this->hasOption('hard') && $this->settings->get('smwgQMaxSize') >= $concept->getSize() && ($this->settings->get('smwgQMaxDepth') >= $concept->getDepth() && ~(~($concept->getQueryFeatures() + 0) | $this->settings->get('smwgQFeatures')) == 0)) { $skip = 'concept is not "hard" according to wiki settings'; } if ($skip) { $line = $this->lines !== false ? "({$this->lines}) " : ''; $this->reportMessage($line . 'Skipping concept "' . $title->getPrefixedText() . "\": {$skip}\n", $this->verbose); } return $skip; }