/** * @covers WikiService::getMostLinkedPages */ public function testGetMostLinkedPages() { /* mocking MemCache */ $mockCache = $this->getMock('MemCachedClientforWiki', array('get', 'set'), array(array())); $mockCache->expects($this->any())->method('get')->will($this->returnValue(false)); $mockCache->expects($this->any())->method('set')->will($this->returnValue(false)); $this->mockGlobalVariable('wgMemc', $mockCache); /* Mocking DB response */ $row1 = new stdClass(); $row1->page_id = 100; $row1->page_title = "Abc Page 1"; $row1->backlink_cnt = 10; $row2 = new stdClass(); $row2->page_id = 200; $row2->page_title = "Abc Page 2"; $row2->backlink_cnt = 6; $mockDb = $this->getMock('DatabaseMysql', array('select', 'fetchObject')); $mockDb->expects($this->any())->method('select')->will($this->returnValue(false)); $mockDb->expects($this->at(1))->method('fetchObject')->will($this->returnValue($row1)); $mockDb->expects($this->at(2))->method('fetchObject')->will($this->returnValue($row2)); $mockDb->expects($this->at(3))->method('fetchObject')->will($this->returnValue(null)); $this->mockGlobalFunction('wfGetDb', $mockDb); $wikiService = new WikiService(); $result = $wikiService->getMostLinkedPages(); $keys = array_keys($result); $this->assertEquals(count($keys), 2); foreach ($keys as $key) { $this->assertEquals($key, $result[$key]['page_id']); } }
public function getMostLinked() { $expand = $this->request->getBool(static::PARAMETER_EXPAND, false); $nameSpace = NS_MAIN; $wikiService = new WikiService(); $mostLinked = $wikiService->getMostLinkedPages(); $mostLinkedOutput = []; if ($expand) { $params = $this->getDetailsParams(); $mostLinkedOutput = $this->getArticlesDetails(array_keys($mostLinked), $params['titleKeys'], $params['width'], $params['height'], $params['length'], true); } else { foreach ($mostLinked as $item) { $title = Title::newFromText($item['page_title'], $nameSpace); if (!empty($title) && $title instanceof Title && !$title->isMainPage()) { $mostLinkedOutput[] = ['id' => $item['page_id'], 'title' => $item['page_title'], 'url' => $title->getLocalURL(), 'ns' => $nameSpace]; } } } $this->setResponseData(['basepath' => $this->wg->Server, 'items' => $mostLinkedOutput], ['imgFields' => 'thumbnail', 'urlFields' => ['thumbnail', 'url']], self::getMetadataCacheTime()); }