/** * Does a little prep on a result oject, applies highlighting if exists, and adds to result array. * @param WikiaSearchResult $result * @throws WikiaException * @return WikiaSearchResultSet provides fluent interface */ private function addResult(WikiaSearchResult $result) { if ($this->isValidResult($result)) { $id = $result['id']; if ($this->highlightingObject !== null && ($hlResult = $this->highlightingObject->getResult($id)) && ($field = $hlResult->getField(WikiaSearch::field('html')))) { $result->setText($field[0]); } if ($result['created'] !== null && $this->wg->Lang) { $result->setVar('created', $result['created'])->setVar('fmt_timestamp', $this->wg->Lang->date(wfTimestamp(TS_MW, $result['created']))); if ($result->getVar('fmt_timestamp')) { $result->setVar('created_30daysago', time() - strtotime($result['created']) > 2592000); } } $result->setVar('categories', $result[WikiaSearch::field('categories')] ?: 'NONE')->setVar('cityArticlesNum', $result['wikiarticles'])->setVar('wikititle', $result[WikiaSearch::field('wikititle')]); $this->results[$id] = $result; } else { throw new WikiaException('Invalid result in set'); } return $this; }
public function testGetInvalidResult() { $this->assertEquals(null, $this->_result->getResult('invalid')); }