public function subjectProvider()
 {
     $provider[] = array(DIWikiPage::newFromText('Foo'));
     $provider[] = array(DIWikiPage::newFromText('Bar', SMW_NS_PROPERTY));
     $provider[] = array(DIWikiPage::newFromText('Modification date', SMW_NS_PROPERTY));
     return $provider;
 }
 public function testErrorContainerForSamePropertyButDifferentMsg()
 {
     $instance = new Error(DIWikiPage::newFromText('Foo'));
     $property = new DIProperty('Foo');
     $container = $instance->getContainerFor($property, array('Some error'));
     $this->assertNotSame($container->getHash(), $instance->getContainerFor($property, array('Different error'))->getHash());
 }
 public function testGetHash()
 {
     $diff = array();
     $instance = new CompositePropertyTableDiffIterator($diff);
     $instance->setSubject(DIWikiPage::newFromText(__METHOD__));
     $this->assertInternalType('string', $instance->getHash());
 }
 /**
  * @dataProvider durationDataProvider
  */
 public function testCreateProfile($duration, $expected)
 {
     $profiler = new NullProfileAnnotator(new Subobject(DIWikiPage::newFromText(__METHOD__)->getTitle()), 'foo');
     $instance = new DurationProfileAnnotator($profiler, $duration);
     $instance->addAnnotation();
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance->getContainer()->getSemanticData());
 }
 public function testRun()
 {
     $parameters = array('slot:id' => 42);
     $this->transitionalDiffStore->expects($this->once())->method('delete');
     $subject = DIWikiPage::newFromText(__METHOD__);
     $instance = new ChronologyPurgeJob($subject->getTitle(), $parameters);
     $this->assertTrue($instance->run());
 }
 public function testCreateProfile()
 {
     $profiler = new NullProfileAnnotator(new Subobject(DIWikiPage::newFromText(__METHOD__)->getTitle()), 'foo');
     $instance = new FormatProfileAnnotator($profiler, 'table');
     $instance->addAnnotation();
     $expected = array('propertyCount' => 1, 'propertyKeys' => array('_ASKFO'), 'propertyValues' => array('table'));
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance->getContainer()->getSemanticData());
 }
 /**
  * @depends testAddToEntityList
  */
 public function testAddAnotherToEntityList()
 {
     $dataItem = DIWikiPage::newFromText('Bar');
     $this->query->expects($this->any())->method('getQueryId')->will($this->returnValue('FOO:BAR'));
     $instance = new EntityListAccumulator($this->query);
     $instance->addToEntityList($dataItem);
     $this->assertEquals(array('FOO:BAR' => array('Bar#0#' => $dataItem)), $instance->getEntityList());
 }
 public function dataItemDataProvider()
 {
     // Single
     $subject = array(DIWikiPage::newFromText(__METHOD__));
     // Multiple
     $subjects = array(DIWikiPage::newFromText(__METHOD__ . 'm-0'), DIWikiPage::newFromText(__METHOD__ . 'm-1'), DIWikiPage::newFromText(__METHOD__ . 'm-2'));
     return array(array($subjects, array(), array('_PVAL', '_LIST'), array('diff' => true, 'job' => true)), array(array(), $subjects, array('_PVAL', '_LIST'), array('diff' => true, 'job' => true)), array($subject, $subjects, array('_PVAL', '_LIST'), array('diff' => true, 'job' => true)), array($subject, array(), array('_PVAL', '_LIST'), array('diff' => true, 'job' => true)), array($subject, array(), array('_PVAL'), array('diff' => true, 'job' => true)), array($subjects, $subjects, array('_PVAL'), array('diff' => false, 'job' => false)), array($subject, $subject, array('_PVAL'), array('diff' => false, 'job' => false)), array($subjects, $subjects, array('_PVAL', '_LIST'), array('diff' => true, 'job' => true)), array($subject, $subject, array('_PVAL', '_LIST'), array('diff' => true, 'job' => true)));
 }
 public function testGetHash()
 {
     $instance = new SemanticData(DIWikiPage::newFromText(__METHOD__));
     $instance->addDataValue(DataValueFactory::getInstance()->newDataValueByText('Has fooQuex', 'Bar'));
     $subobject = $this->newSubobject($instance->getSubject()->getTitle());
     $instance->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $this->assertInternalType('string', $instance->getHash());
 }
 protected function setUp()
 {
     parent::setUp();
     $idTable = $this->getMockBuilder('\\stdClass')->setMethods(array('getDataItemById'))->getMock();
     $idTable->expects($this->any())->method('getDataItemById')->will($this->returnValue(DIWikiPage::newFromText('Foo')));
     $this->store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->disableOriginalConstructor()->getMock();
     $this->store->expects($this->any())->method('getObjectIds')->will($this->returnValue($idTable));
 }
 /**
  * @dataProvider preliminaryCheckProvider
  */
 public function testPreliminaryCheckForType($type, $parameters = array())
 {
     $httpRequest = $this->getMockBuilder('\\Onoi\\HttpRequest\\SocketRequest')->disableOriginalConstructor()->getMock();
     $httpRequest->expects($this->any())->method('ping')->will($this->returnValue(true));
     $instance = new DeferredRequestDispatchManager($httpRequest);
     $instance->reset();
     $this->assertNull($instance->dispatchJobRequestFor($type, DIWikiPage::newFromText(__METHOD__)->getTitle(), $parameters));
 }
 public function testNoAnnotationWhenDisabled()
 {
     $semanticData = $this->semanticDataFactory->newEmptySemanticData(DIWikiPage::newFromText('Foo'));
     $instance = new DisplayTitlePropertyAnnotator(new NullPropertyAnnotator($semanticData), 'Bar');
     $instance->canCreateAnnotation(false);
     $instance->addAnnotation();
     $expected = array('propertyCount' => 0);
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance->getSemanticData());
 }
 public function testDisabledSubcategoryLookup()
 {
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMock();
     $cache->expects($this->never())->method('contains')->will($this->returnValue(false));
     $instance = new PropertyHierarchyLookup($store, $cache);
     $instance->setSubcategoryDepth(0);
     $this->assertFalse($instance->hasSubcategoryFor(DIWikiPage::newFromText('Foo', NS_CATEGORY)));
 }
 public function testFindRedirectTargetOnSelfReferencedDataItem()
 {
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->setMethods(array('getRedirectTarget'))->getMockForAbstractClass();
     $store->expects($this->never())->method('getRedirectTarget');
     $circularReferenceGuard = $this->getMockBuilder('\\SMW\\CircularReferenceGuard')->disableOriginalConstructor()->getMock();
     $circularReferenceGuard->expects($this->atLeastOnce())->method('isCircularByRecursionFor')->will($this->returnValue(true));
     $instance = new RedirectTargetLookup($store, $circularReferenceGuard);
     $instance->findRedirectTarget(DIWikiPage::newFromText('Foo'));
 }
 public function testGetPropertyValuesFromCache()
 {
     $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock();
     $container->expects($this->atLeastOnce())->method('has')->will($this->returnValue(true));
     $container->expects($this->once())->method('get')->with($this->stringContains('Bar:123'))->will($this->returnValue(1001));
     $this->blobStore->expects($this->atLeastOnce())->method('read')->will($this->returnValue($container));
     $instance = new CachedPropertyValuesPrefetcher($this->store, $this->blobStore);
     $this->assertEquals(1001, $instance->getPropertyValues(DIWikiPage::newFromText('Foo#123'), new DIProperty('Bar')));
 }
 private function assertParserOutputForCase($case)
 {
     if (!isset($case['expected-output']) || !isset($case['expected-output']['to-contain'])) {
         return;
     }
     $subject = DIWikiPage::newFromText($case['subject'], isset($case['namespace']) ? constant($case['namespace']) : NS_MAIN);
     $parserOutput = UtilityFactory::getInstance()->newPageReader()->getEditInfo($subject->getTitle())->output;
     $this->stringValidator->assertThatStringContains($case['expected-output']['to-contain'], $parserOutput->getText(), $case['about']);
 }
 public function testConstructJointProfileAnnotator()
 {
     $description = $this->getMockBuilder('\\SMW\\Query\\Language\\Description')->disableOriginalConstructor()->getMock();
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $query->expects($this->once())->method('getSubject')->will($this->returnValue(DIWikiPage::newFromText(__METHOD__)));
     $query->expects($this->once())->method('getDescription')->will($this->returnValue($description));
     $instance = new QueryProfileAnnotatorFactory();
     $this->assertInstanceOf('\\SMW\\Query\\ProfileAnnotator\\ProfileAnnotator', $instance->newJointProfileAnnotator($query, ''));
 }
 /**
  * @dataProvider parserFunctionDefinitionProvider
  */
 public function testParserFunctionDefinition($method, $expected)
 {
     $parser = $this->parserFactory->newFromTitle(DIWikiPage::newFromText(__METHOD__)->getTitle());
     $parserFunctionFactory = new ParserFunctionFactory($parser);
     $definition = call_user_func_array(array($parserFunctionFactory, $method), array(''));
     $this->assertEquals($expected, $definition[0]);
     $this->assertInstanceOf('\\Closure', $definition[1]);
     $this->assertInternalType('integer', $definition[2]);
 }
 /**
  * @dataProvider queryDataProvider
  */
 public function testCreateProfile(array $rawParams, array $expected)
 {
     list($query, $formattedParams) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, false);
     $query->setContextPage(DIWikiPage::newFromText(__METHOD__));
     $profileAnnotatorFactory = ApplicationFactory::getInstance()->getQueryFactory()->newProfileAnnotatorFactory();
     $combinedProfileAnnotator = $profileAnnotatorFactory->newCombinedProfileAnnotator($query, $formattedParams['format']->getValue());
     $combinedProfileAnnotator->addAnnotation();
     $this->assertInstanceOf('\\SMW\\SemanticData', $combinedProfileAnnotator->getSemanticData());
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $combinedProfileAnnotator->getSemanticData());
 }
 public function testOptions()
 {
     $subject = DIWikiPage::newFromText('Foo');
     $instance = new HtmlContentBuilder($this->store, $subject);
     $options = array('Foo' => 42);
     $instance->setOptionsFromJsonFormat(json_encode($options));
     $instance->setOption('Bar', 1001);
     $this->assertEquals(42, $instance->getOption('Foo'));
     $this->assertEquals(1001, $instance->getOption('Bar'));
 }
 public function testGetErrorContainerFromDataValue()
 {
     $instance = new ProcessingErrorMsgHandler(DIWikiPage::newFromText(__METHOD__));
     $dataValue = $this->getMockBuilder('\\SMWDataValue')->disableOriginalConstructor()->setMethods(array('getErrors', 'getProperty'))->getMockForAbstractClass();
     $dataValue->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array('Foo')));
     $dataValue->expects($this->atLeastOnce())->method('getProperty')->will($this->returnValue($this->dataItemFactory->newDIProperty('Bar')));
     $container = $instance->getErrorContainerFromDataValue($dataValue);
     $this->assertInstanceOf('\\SMWDIContainer', $container);
     $expected = array('propertyCount' => 2, 'propertyKeys' => array('_ERRP', '_ERRT'));
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $container->getSemanticData());
 }
 public function testGetExpDataForMultipleClassDescriptions()
 {
     $instance = new ConceptToExpDataMapper();
     $exact = false;
     $description = $this->descriptionFactory->newClassDescription(DIWikiPage::newFromText('Foo', NS_CATEGORY));
     $description->addDescription($this->descriptionFactory->newClassDescription(DIWikiPage::newFromText('Bar', NS_CATEGORY)));
     $elementType = new ExpNsResource('type', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf');
     $elementUnionOf = new ExpNsResource('unionOf', 'http://www.w3.org/2002/07/owl#', 'owl');
     $result = $instance->getExpDataFromDescription($description, $exact);
     $this->assertEquals(array('http://www.w3.org/1999/02/22-rdf-syntax-ns#type' => $elementType, 'http://www.w3.org/2002/07/owl#unionOf' => $elementUnionOf), $result->getProperties());
 }
 public function testMethodAccess()
 {
     $subobject = new Subobject(DIWikiPage::newFromText(__METHOD__)->getTitle());
     $instance = new NullProfileAnnotator($subobject, '_QUERYadcb944aa33b2c972470b73964c547c0');
     $instance->addAnnotation();
     $this->assertInstanceOf('\\SMW\\DIProperty', $instance->getProperty());
     $this->assertInstanceOf('\\SMWDIContainer', $instance->getContainer());
     $this->assertInstanceOf('\\SMWContainerSemanticData', $instance->getSemanticData());
     $this->assertEmpty($instance->getErrors());
     $this->assertEquals('_QUERYadcb944aa33b2c972470b73964c547c0', $subobject->getSubobjectId());
 }
 public function testMutableMethodAccess()
 {
     // EntityIdTable
     $idTable = $this->getMockBuilder('\\stdClass')->setMethods(array('getSMWPageID', 'makeSMWPageID'))->getMock();
     $idTable->expects($this->any())->method('getSMWPageID')->will($this->returnValue(42));
     $idTable->expects($this->any())->method('makeSMWPageID')->will($this->returnValue(1001));
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->disableOriginalConstructor()->getMock();
     $store->expects($this->any())->method('getObjectIds')->will($this->returnValue($idTable));
     $instance = new DIWikiPageHandler($store);
     $this->assertInternalType('array', $instance->getWhereConds(DIWikiPage::newFromText('Foo')));
     $this->assertInternalType('array', $instance->getInsertValues(DIWikiPage::newFromText('Foo')));
 }
 public function testCreateProfile()
 {
     $description = $this->getMockBuilder('\\SMW\\Query\\Language\\Description')->disableOriginalConstructor()->getMock();
     $description->expects($this->once())->method('getQueryString')->will($this->returnValue('Foo'));
     $description->expects($this->once())->method('getSize')->will($this->returnValue(2));
     $description->expects($this->once())->method('getDepth')->will($this->returnValue(42));
     $profiler = new NullProfileAnnotator(new Subobject(DIWikiPage::newFromText(__METHOD__)->getTitle()), 'ichimarukyuu');
     $instance = new DescriptionProfileAnnotator($profiler, $description);
     $instance->addAnnotation();
     $expected = array('propertyCount' => 3, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE'), 'propertyValues' => array('Foo', 2, 42));
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance->getContainer()->getSemanticData());
 }
 public function testNoCache()
 {
     $this->blobStore->expects($this->never())->method('read');
     $this->blobStore->expects($this->atLeastOnce())->method('canUse')->will($this->returnValue(true));
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $query->expects($this->atLeastOnce())->method('getLimit')->will($this->returnValue(100));
     $query->expects($this->atLeastOnce())->method('getContextPage')->will($this->returnValue(DIWikiPage::newFromText(__METHOD__)));
     $query->expects($this->atLeastOnce())->method('getOptionBy')->with($this->equalTo($query::NO_CACHE))->will($this->returnValue(true));
     $queryEngine = $this->getMockBuilder('\\SMW\\QueryEngine')->disableOriginalConstructor()->getMock();
     $instance = new CachedQueryResultPrefetcher($this->store, $this->queryFactory, $this->blobStore, $this->transientStatsdCollector);
     $instance->setQueryEngine($queryEngine);
     $instance->getQueryResult($query);
 }
 public function printRequestProvider()
 {
     $provider['print-cats-wiki'] = array(new PrintRequest(PrintRequest::PRINT_CATS, 'Foo'), null, Formatter::FORMAT_WIKI, 'Foo');
     $provider['print-cats-html'] = array(new PrintRequest(PrintRequest::PRINT_CATS, 'Foo'), null, Formatter::FORMAT_HTML, 'Foo');
     $provider['print-ccat-html'] = array(new PrintRequest(PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText('Bar')->getTitle()), null, Formatter::FORMAT_HTML, 'Foo');
     $provider['print-ccat-wiki'] = array(new PrintRequest(PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText('Bar')->getTitle()), null, Formatter::FORMAT_WIKI, 'Foo');
     $provider['print-this-wiki'] = array(new PrintRequest(PrintRequest::PRINT_THIS, 'Foo'), null, Formatter::FORMAT_WIKI, 'Foo');
     $provider['print-this-html'] = array(new PrintRequest(PrintRequest::PRINT_THIS, 'Foo'), null, Formatter::FORMAT_HTML, 'Foo');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar');
     $provider['print-prop-wiki-no-linker'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data), null, Formatter::FORMAT_WIKI, 'Foo');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar');
     $provider['print-prop-html-no-linker'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data), null, Formatter::FORMAT_HTML, 'Foo');
     return $provider;
 }
 public function testgetFilteredIdListOnExemptedUserdefinedProperty()
 {
     $orderedDiffByTable = array('fpt_foo' => array('insert' => array(array('p_id' => 100, 's_id' => 201, 'o_serialized' => '1/2016/6/1/11/1/48/0', 'o_sortkey' => '2457540.9595833')), 'delete' => array(array('p_id' => 100, 's_id' => 201, 'o_serialized' => '1/2016/6/1/11/1/59/0', 'o_sortkey' => '2457540.9582292'))));
     $idTable = $this->getMockBuilder('\\stdClass')->setMethods(array('getDataItemById'))->getMock();
     $idTable->expects($this->any())->method('getDataItemById')->with($this->equalTo(100))->will($this->returnValue(DIWikiPage::newFromText('Has date', SMW_NS_PROPERTY)));
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->disableOriginalConstructor()->setMethods(array('getObjectIds'))->getMockForAbstractClass();
     $store->expects($this->any())->method('getObjectIds')->will($this->returnValue($idTable));
     $compositePropertyTableDiffIterator = $this->getMockBuilder('\\SMW\\SQLStore\\CompositePropertyTableDiffIterator')->disableOriginalConstructor()->setMethods(array('getCombinedIdListOfChangedEntities', 'getOrderedDiffByTable'))->getMock();
     $compositePropertyTableDiffIterator->expects($this->once())->method('getCombinedIdListOfChangedEntities')->will($this->returnValue(array(100, 201, 1001)));
     $compositePropertyTableDiffIterator->expects($this->any())->method('getOrderedDiffByTable')->will($this->returnValue($orderedDiffByTable));
     $instance = new EntityIdListRelevanceDetectionFilter($store, $compositePropertyTableDiffIterator);
     $instance->setPropertyExemptionlist(array('Has date'));
     $this->assertEquals(array(1001), $instance->getFilteredIdList());
 }
 public function testQueryResultSerializerForRecordType()
 {
     $semanticData = $this->getMockBuilder('\\SMW\\SemanticData')->disableOriginalConstructor()->getMock();
     $semanticData->expects($this->atLeastOnce())->method('getProperties')->will($this->returnValue(array($this->dataItemFactory->newDIProperty('Foobar'))));
     $semanticData->expects($this->atLeastOnce())->method('getPropertyValues')->will($this->returnValue(array($this->dataItemFactory->newDIWikiPage('Bar', NS_MAIN))));
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $store->expects($this->atLeastOnce())->method('getSemanticData')->will($this->returnValue($semanticData));
     $store->expects($this->at(1))->method('getPropertyValues')->will($this->returnValue(array($this->dataItemFactory->newDIBlob('BarList1;BarList2'))));
     $this->testEnvironment->registerObject('Store', $store);
     $property = \SMW\DIProperty::newFromUserLabel('Foo');
     $property->setPropertyTypeId('_rec');
     $printRequestFactory = new \SMW\Query\PrintRequestFactory();
     $serialization = QueryResultSerializer::getSerialization(\SMW\DIWikiPage::newFromText('ABC'), $printRequestFactory->newPrintRequestByProperty($property));
     $expected = array('BarList1' => array('label' => 'BarList1', 'typeid' => '_wpg', 'item' => array(), 'key' => 'BarList1'), 'BarList2' => array('label' => 'BarList2', 'typeid' => '_wpg', 'item' => array(), 'key' => 'BarList2'));
     $this->assertEquals($expected, $serialization);
 }
 public function textProvider()
 {
     $category = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY);
     $provider['print-cats'] = array(new PrintRequest(PrintRequest::PRINT_CATS, 'Foo'), false, "?{$category}=Foo");
     $provider['print-ccat'] = array(new PrintRequest(PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText('Bar')->getTitle()), false, '?Bar=Foo');
     $provider['print-this'] = array(new PrintRequest(PrintRequest::PRINT_THIS, 'Foo'), false, '?=Foo#');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar');
     $provider['print-prop'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data), false, '?Bar#=Foo');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar');
     $provider['print-prop-output'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar'), false, '?Bar#foobar=Foo');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar');
     $provider['print-prop-output-parameters-no-show'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar', array('index' => 2)), false, '?Bar#foobar=Foo');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar');
     $provider['print-prop-output-parameters-show'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar', array('index' => 2)), true, '?Bar#foobar=Foo|+index=2');
     $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Modification date');
     $provider['predefined-property'] = array(new PrintRequest(PrintRequest::PRINT_PROP, '', $data), false, '?Modification date#');
     return $provider;
 }