/** * Formulates ID queries for each page ID * @return array */ protected function getIdQueries() { $idQueries = []; $wid = $this->getMwService()->getWikiId(); foreach (array_keys($this->getMappedIds()) as $canonicalId) { $idQueries[] = Wikia\Search\Utilities::valueForField('id', sprintf('%s_%s', $wid, $canonicalId)); } return $idQueries; }
/** * @covers InfoboxesService::getIdQueries */ public function testGetIdQueries() { $mwService = $this->getMock('Wikia\\Search\\MediaWikiService', ['getWikiId']); $service = $this->getMock('InfoboxesService', ['getMappedIds', 'getMwService']); $mappedIds = [456 => [789, 234]]; $service->expects($this->once())->method('getMwService')->will($this->returnValue($mwService)); $mwService->expects($this->once())->method('getWikiId')->will($this->returnValue(123)); $service->expects($this->once())->method('getMappedIds')->will($this->returnValue($mappedIds)); $get = new ReflectionMethod('InfoboxesService', 'getIdQueries'); $get->setAccessible(true); $this->assertEquals([Wikia\Search\Utilities::valueForField('id', '123_456')], $get->invoke($service)); }
/** * Returns the result object, or null if it doesn't exist * @return Wikia\Search\Result|null; */ public function getResult() { $docId = $this->getDocumentId(); if (isset(self::$documentCache[$docId])) { $result = self::$documentCache[$docId]; } else { $config = $this->getConfig(); $config->setQuery(Wikia\Search\Utilities::valueForField('id', $docId)); $queryService = $this->getFactory()->getFromConfig($config); $resultSet = $queryService->search(); $result = isset($resultSet[$docId]) ? $resultSet[$docId] : null; if ($result !== null) { self::$documentCache[$docId] = $result; } } return $result; }
/** * @group Slow * @slowExecutionTime 0.01169 ms */ public function testGetDocumentWithResult() { $service = $this->getMock('SolrDocumentService', ['getConfig', 'getFactory', 'getDocumentId']); $factory = $this->getMock('Wikia\\Search\\QueryService\\Factory', ['getFromConfig']); $config = $this->getMock('Wikia\\Search\\Config', ['setQuery']); $queryService = $this->getMock('Wikia\\Search\\QueryService\\Lucene\\Lucene', ['search']); $resultSet = $this->getMockBuilder('Wikia\\Search\\ResultSet\\Base')->disableOriginalConstructor()->setMethods(['offsetGet', 'offsetExists'])->getMock(); $result = $this->getMock('Wikia\\Search\\Result'); $service->expects($this->once())->method('getConfig')->will($this->returnValue($config)); $service->expects($this->once())->method('getDocumentId')->will($this->returnValue('123_456')); $config->expects($this->once())->method('setQuery')->with(Wikia\Search\Utilities::valueForField('id', '123_456')); $service->expects($this->once())->method('getFactory')->will($this->returnValue($factory)); $factory->expects($this->once())->method('getFromConfig')->with($config)->will($this->returnValue($queryService)); $queryService->expects($this->once())->method('search')->will($this->returnValue($resultSet)); $resultSet->expects($this->once())->method('offsetExists')->with('123_456')->will($this->returnValue(true)); $resultSet->expects($this->once())->method('offsetGet')->with('123_456')->will($this->returnValue($result)); $this->assertEquals($result, $service->getResult()); $this->assertArrayHasKey('123_456', SolrDocumentService::$documentCache); }