/** * @covers lw_getSearchResults */ public function test_lw_getSearchResults() { $mockConfig = $this->getMockBuilder('Wikia\\Search\\Config')->disableOriginalConstructor()->setMethods(['setNamespaces', 'setQuery', 'setLimit'])->getMock(); $mockFactory = $this->getMock('Wikia\\Search\\QueryService\\Factory', ['getFromConfig']); $mockSearch = $this->getMockBuilder('Wikia\\Search\\QueryService\\Select\\OnWiki')->disableOriginalConstructor()->setMethods(['search'])->getMock(); $mockResultSet = $this->getMockBuilder('Wikia\\Search\\ResultSet\\Base')->disableOriginalConstructor()->getMock(); $query = 'foo'; $limit = 20; $mockConfig->expects($this->once())->method('setNamespaces')->with([NS_MAIN])->will($this->returnValue($mockConfig)); $mockConfig->expects($this->once())->method('setQuery')->with($query)->will($this->returnValue($mockConfig)); $mockConfig->expects($this->once())->method('setLimit')->with($limit)->will($this->returnValue($mockConfig)); $mockFactory->expects($this->once())->method('getFromConfig')->will($this->returnValue($mockSearch)); $mockSearch->expects($this->once())->method('search')->will($this->returnValue($mockResultSet)); // @todo handle the transformation from result set to array of titles $this->mockClass('Wikia\\Search\\Config', $mockConfig); $this->mockClass('Wikia\\Search\\QueryService\\Factory', $mockFactory); $this->assertTrue(is_array(lw_getSearchResults($query, $limit))); }
function getArtist($artist) { $id = requestStarted(__METHOD__, "{$artist}"); // For now the regex makes it only read the first disc and ignore beyond that (since it assumes the track listing is over). $albums = array(); global $amazonRoot, $wgRequest; $debug = false; $debugSuffix = "_debug"; if (strlen($artist) >= strlen($debugSuffix) && substr($artist, 0 - strlen($debugSuffix)) == $debugSuffix) { $artist = substr($artist, 0, strlen($artist) - strlen($debugSuffix)); $debug = true; } else { $debugSuffix = " debug"; if (strlen($artist) >= strlen($debugSuffix) && substr($artist, 0 - strlen($debugSuffix)) == $debugSuffix) { $artist = substr($artist, 0, strlen($artist) - strlen($debugSuffix)); $debug = true; } } $artist = trim(rawurldecode($artist)); $isUTF = utf8_compliant("{$artist}"); $title = lw_getTitle($artist, '', !$isUTF); // if isUTF, skips the utf8 encoding (that is only for the values from the db... from the URL they should be fine already). global $SHUT_DOWN_API; $correctArtist = $artist; // this will be overwritten (by reference) in lw_getPage(). if (!$SHUT_DOWN_API && lw_pageExists($title)) { $content = lw_getPage($title, $correctArtist, $debug); // Some artists with a ton of albums have a "split catalog" which just links to the other albums. if (strpos($content, "SplitCatalog") !== false) { // Find all of the albums on the page. $matches = array(); if (0 < preg_match_all("/[^\n]*\\[\\[([^\n]*?):([^\n\\|]*)\\(([0-9]{4})\\)(\\||\\]\\])[^\n]*/", $content, $matches)) { $lines = $matches[0]; $artists = $matches[1]; $albums = $matches[2]; $years = $matches[3]; for ($index = 0; $index < count($artists); $index++) { $albumPageTitle = $artists[$index] . ":" . $albums[$index] . " (" . $years[$index] . ")"; // Grab the content of the album page and stuff it in where the link was. $line = $lines[$index]; $albumContent = lw_getPage($albumPageTitle); // Strip out headings from the album page (the discogrphy parser expects headings to be the album names). $albumContent = preg_replace("/==[^\n]*==/", "", $albumContent); $albumContent = "== {$line} ==\n{$albumContent}"; // needs to have the album header there so that it can be parsed. $content = str_replace($line, $albumContent, $content); } } } $albums = parseDiscographies($content, $correctArtist); if ($debug) { $albums[] = array("album" => "Raw Wikitext", "year" => 2008, "amazonLink" => "http://www.amazon.com", "songs" => array($content)); } } $correctArtist = str_replace("_", " ", $correctArtist); $retVal = array('artist' => $correctArtist, 'albums' => $albums); // Make encoding work with UTF8. $isUTF = utf8_compliant("{$correctArtist}"); if ($isUTF === false) { $retVal['artist'] = utf8_encode($retVal['artist']); } // If configured to do so, fallback to full wiki search. if ($wgRequest->getBool('fallbackSearch') && count($retVal['albums']) == 0) { $retVal['searchResults'] = lw_getSearchResults("{$artist}"); } requestFinished($id); return $retVal; }