function __construct()
 {
     $this->app = F::app();
     $this->logger = F::build('PathFinderLogger');
     //singleton
     F::setInstance(__CLASS__, $this);
 }
 protected function setUp()
 {
     global $wgCityId;
     $this->wgCityId = $wgCityId;
     $this->setupFile = dirname(__FILE__) . '/../FounderProgressBar.setup.php';
     parent::setUp();
     // Mock response using $this->getValCallBack()
     $mockR = $this->getMock('WikiaResponse', array('getVal'), array('raw'));
     $mockR->expects($this->any())->method('getVal')->will($this->returnCallback(array($this, "getValCallback")));
     $mock_result = $this->getMock('ResultWrapper', array(), array(), '', false);
     $this->mock_db = $this->getMock('DatabaseMysql', array('select', 'query', 'update', 'commit', 'fetchObject', 'fetchRow'));
     $this->mock_db->expects($this->any())->method('select')->will($this->returnValue($mock_result));
     $this->mock_db->expects($this->any())->method('query');
     $this->mock_db->expects($this->any())->method('update');
     $this->mock_db->expects($this->any())->method('commit');
     $cache = $this->getMock('stdClass', array('get', 'set', 'delete'));
     $cache->expects($this->any())->method('get')->will($this->returnValue(null));
     $cache->expects($this->any())->method('set');
     $cache->expects($this->any())->method('delete');
     $mock = $this->getMock('FounderProgressBarController', array('sendSelfRequest', 'getDb', 'getMCache'));
     $mock->expects($this->any())->method('sendSelfRequest')->will($this->returnValue($mockR));
     $mock->expects($this->any())->method('getDb')->will($this->returnValue($this->mock_db));
     $mock->expects($this->any())->method('getMCache')->will($this->returnValue($cache));
     F::setInstance("FounderProgressBarController", $mock);
     $this->object = F::build('FounderProgressBarController');
     $this->task_id = 0;
 }
 /**
  * constructor
  * @param $globalRegistry WikiaGlobalRegistry
  * @param $localRegistry WikiaLocalRegistry
  * @param $hookDispatcher WikiaHookDispatcher
  */
 public function __construct(WikiaGlobalRegistry $globalRegistry = null, WikiaLocalRegistry $localRegistry = null, WikiaHookDispatcher $hookDispatcher = null, WikiaFunctionWrapper $functionWrapper = null)
 {
     if (!is_object($globalRegistry)) {
         F::setInstance('WikiaGlobalRegistry', new WikiaGlobalRegistry());
         $globalRegistry = F::build('WikiaGlobalRegistry');
     }
     if (!is_object($localRegistry)) {
         F::setInstance('WikiaLocalRegistry', new WikiaLocalRegistry());
         $localRegistry = F::build('WikiaLocalRegistry');
     }
     if (!is_object($hookDispatcher)) {
         F::setInstance('WikiaHookDispatcher', new WikiaHookDispatcher());
         $hookDispatcher = F::build('WikiaHookDispatcher');
     }
     if (!is_object($functionWrapper)) {
         $functionWrapper = F::build('WikiaFunctionWrapper');
     }
     $this->localRegistry = $localRegistry;
     $this->hookDispatcher = $hookDispatcher;
     // set helper accessors
     $this->wg = $globalRegistry;
     $this->wf = $functionWrapper;
     // register ajax dispatcher
     if (is_object($this->wg)) {
         $this->wg->append('wgAjaxExportList', 'WikiaApp::ajax');
     } else {
         Wikia::log(__METHOD__, false, 'WikiaGlobalRegistry not set in ' . __CLASS__ . ' ' . __METHOD__);
         Wikia::logBacktrace(__METHOD__);
     }
 }
 private function setStubsForImageReviewSpecialControllerTests($error)
 {
     //our test have all needed rights ;)
     $specialPageStub = $this->getMock('SpecialPage', array('userCanExecute'));
     $specialPageStub->expects($this->any())->method('userCanExecute')->will($this->returnValue(true));
     F::setInstance('SpecialPage', $specialPageStub);
     //to prevent fatal error
     $wgTitleStub = $this->getMock('Title', array('getFullUrl'));
     $wgTitleStub->expects($this->any())->method('getFullUrl')->will($this->returnValue($this->fakeUrl));
     $this->mockGlobalVariable('wgTitle', $wgTitleStub);
     //not to stop ImageSpecialController() 'cause ts parameter not given
     $wgRequestStub = $this->getMock('Request', array('getVal', 'wasPosted'));
     $wgRequestStub->expects($this->any())->method('getVal')->will($this->returnValue($this->fakeTimestamp));
     $wgRequestStub->expects($this->any())->method('wasPosted')->will($this->returnValue(false));
     $this->mockGlobalVariable('wgRequest', $wgRequestStub);
     if (!$error) {
         $memcTs = $this->fakeUserTs + 1;
         $imageReviewHelperStub = $this->getMock('ImageReviewHelper', array('refetchImageListByTimestamp'));
         $imageReviewHelperStub->expects($this->once())->method('refetchImageListByTimestamp')->will($this->returnValue($this->fakeCorrectImages));
     } else {
         $memcTs = $this->fakeUserTs - 1;
         $imageReviewHelperStub = $this->getMock('ImageReviewHelper', array('getImageList'));
         $imageReviewHelperStub->expects($this->once())->method('getImageList')->will($this->returnValue($this->fakeWrongImages));
     }
     F::setInstance('ImageReviewHelper', $imageReviewHelperStub);
     $wgMemcStub = $this->getMock('wgMemc', array('get', 'set'));
     $wgMemcStub->expects($this->any())->method('get')->will($this->returnValue($memcTs));
     $this->mockGlobalVariable('wgMemc', $wgMemcStub);
 }
 function __construct()
 {
     $this->app = F::app();
     $this->magicWords = array_keys($this->app->wg->LandingPagesAsContentMagicWords);
     //singleton
     F::setInstance(__CLASS__, $this);
 }
 /**
  * @group hyun
  */
 public function testCreateWikiSuccess()
 {
     $wikiName = 'Muppet is great';
     $wikiDomain = 'muppet';
     $wikiLanguage = 'en';
     $wikiCategory = '3';
     $wikiId = 322389;
     $wikiAnswer = 12345;
     $siteName = 'asdfasdf';
     $mainPageUrl = 'muppet.wikia.com/wiki/Main_page';
     $requestParams = array("wName" => $wikiName, "wDomain" => $wikiDomain, "wLanguage" => $wikiLanguage, "wCategory" => $wikiCategory, "wAnswer" => $wikiAnswer);
     $wgRequest = $this->getMock('WebRequest');
     $wgRequest->expects($this->once())->method('getArray')->will($this->returnValue($requestParams));
     $wgDevelDomains = array();
     $wgUser = $this->getMock('User');
     $wgUser->expects($this->once())->method('getId')->will($this->returnValue(6));
     $app = $this->getMock('WikiaApp', array('getGlobal', 'runFunction'));
     $app->expects($this->exactly(3))->method('getGlobal')->will($this->onConsecutiveCalls($wgRequest, $wgDevelDomains, $wgUser));
     $createWiki = $this->getMock('CreateWiki', array('create', 'getWikiInfo'), array(), '', false);
     $createWiki->expects($this->once())->method('create');
     $createWiki->expects($this->exactly(2))->method('getWikiInfo')->will($this->onConsecutiveCalls($wikiId, $siteName));
     $mainPageTitle = $this->getMock('GlobalTitle', array(), array(), '', false);
     $mainPageTitle->expects($this->once())->method('getFullURL')->will($this->returnValue($mainPageUrl));
     F::setInstance('CreateWiki', $createWiki);
     F::setInstance('GlobalTitle', $mainPageTitle);
     $wgUser = $this->getMock('User');
     $response = $app->sendRequest('CreateNewWiki', 'CreateWiki');
     $this->assertEquals("ok", $response->getVal('status'));
     $this->assertEquals($siteName, $response->getVal('siteName'));
     $this->assertEquals($mainPageUrl, $response->getval('finishCreateUrl'));
 }
 function __construct()
 {
     parent::__construct();
     if (!self::$initialized) {
         //singleton
         F::setInstance(__CLASS__, $this);
         self::$initialized = true;
     }
 }
 public function __construct($name = null, $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false)
 {
     if ($name == null) {
         throw new WikiaException('First parameter of WikiaSpecialPage constructor must not be null');
     }
     $this->specialPage = F::build('SpecialPage', array($name, $restriction, $listed, $function, $file, $includable));
     F::setInstance(get_class($this), $this);
     parent::__construct();
 }
 function __construct()
 {
     parent::__construct();
     if (!self::$initialized) {
         // Nirvana singleton, please use F::build
         F::setInstance(__CLASS__, $this);
         self::$initialized = true;
     }
 }
 /**
  * Returns the singleton instance
  *
  * @return PathFinderLogger singleton instance
  */
 public static function getInstance()
 {
     $class = get_called_class();
     $instance = F::getInstance($class);
     if (empty($instance)) {
         $instance = F::build($class);
         F::setInstance($class, $instance);
     }
     return $instance;
 }
 /**
  * @dataProvider isConfigSetupDataProvider
  */
 public function testIsConfigSetup($expected, $fbAppId, $fbAppSecret)
 {
     $this->fbAppId = $fbAppId;
     $this->fbAppSecret = $fbAppSecret;
     $app = $this->getMock('WikiaApp', array('getGlobal'));
     $app->expects($this->any())->method('getGlobal')->will($this->returnCallback(array($this, 'isConfigSetupGlobalsCallback')));
     F::setInstance('App', $app);
     $result = FBConnectAPI::isConfigSetup();
     $this->assertEquals($expected, $result);
 }
 protected function setUpToggleFeature($is_allow)
 {
     global $wgWikicitiesReadOnly;
     $this->wgWikicitiesReadOnly_org = $wgWikicitiesReadOnly;
     $wgWikicitiesReadOnly = true;
     $mock_log = $this->getMock('LogPage', array('addEntry'), array(), '', false);
     $mock_log->expects($this->any())->method('addEntry');
     F::setInstance('LogPage', $mock_log);
     $mock_user = $this->getMock('User', array('isAllowed'));
     $mock_user->expects($this->any())->method('isAllowed')->will($this->returnValue($is_allow));
     $this->mockGlobalVariable('wgUser', $mock_user);
 }
 public function mockDatabaseResponse($isEmpty = false)
 {
     $fakeRow = $isEmpty ? array() : $this->getFakeRow();
     $db = $this->getMock('DatabaseMysql');
     $db->expects($this->any())->method('selectRow')->will($this->returnValue($fakeRow));
     $games = $this->getMock('ScavengerHuntGames', array('getDb'), array($this->app));
     $games->expects($this->any())->method('getDb')->will($this->returnValue($db));
     $this->mockClass('ScavengerHuntGames', $games);
     // This is necessary because Game->setLandingTitle is called during construction
     // and it resets the landingArticleWikiId and landingArticleName to bogus values otherwise
     F::setInstance('GlobalTitle', array('wikiId' => self::LANDING_WIKI_ID, 'articleName' => self::MOCK_TEXT));
     return $games;
 }
 function __construct()
 {
     if (empty(self::$instanciated)) {
         self::$instanciated = true;
         F::setInstance(__CLASS__, $this);
         $this->register('FacebookSharing');
         $this->register('TwitterSharing');
         $this->register('PlusoneSharing');
         $this->register('StumbleuponSharing');
         $this->register('RedditSharing');
         $this->register('EmailSharing');
     }
 }
 protected function setupGetStatsMock($cache_value, $fetch_obj)
 {
     $mock_cache = $this->getMock('stdClass', array('get', 'set', 'delete'));
     $mock_cache->expects($this->any())->method('get')->will($this->returnValue($cache_value));
     $mock_cache->expects($this->any())->method('set');
     $mock_cache->expects($this->any())->method('delete');
     if (!is_null($fetch_obj)) {
         $this->setMockDb($fetch_obj);
     }
     $mock = $this->getMock('QuickStatsController', array('getDailyLikes'));
     $mock->expects($this->any())->method('getDailyLikes')->will($this->returnValue(false));
     F::setInstance('QuickStatsController', $mock);
     $this->mockGlobalVariable('wgCityId', self::TEST_CITY_ID);
     $this->mockGlobalVariable('wgMemc', $mock_cache, 0);
     $this->mockGlobalFunction('wfMemcKey', null, 0);
     $this->mockApp();
 }
 public function init()
 {
     $wikiaAppArgs = array();
     $globalRegistryMock = null;
     $functionWrapperMock = null;
     $globalRegistryMock = $this->testCase->getMock('WikiaGlobalRegistry', array('get', 'set'));
     $globalRegistryMock->expects($this->testCase->any())->method('get')->will($this->testCase->returnCallback(array($this, 'getGlobalCallback')));
     if (in_array('runFunction', $this->methods)) {
         $functionWrapperMock = $this->testCase->getMock('WikiaFunctionWrapper', array_keys($this->mockedFunctions));
         foreach ($this->mockedFunctions as $functionName => $functionData) {
             $functionWrapperMock->expects($this->testCase->exactly($functionData['calls']))->method($functionName)->will($this->testCase->returnValue($functionData['value']));
         }
     }
     $wikiaAppArgs[] = $globalRegistryMock;
     $wikiaAppArgs[] = null;
     // WikiaLocalRegistry
     $wikiaAppArgs[] = null;
     // WikiaHookDispatcher
     $wikiaAppArgs[] = $functionWrapperMock;
     $this->mock = $this->testCase->getMock('WikiaApp', array('ajax'), $wikiaAppArgs, '');
     F::setInstance('App', $this->mock);
 }
Exemple #17
0
 /**
  * @dataProvider testRenderingFormatsDataProvider
  */
 public function testRenderingFormats($format, $responseValueName, $responseValueData, $expectedResult)
 {
     $response = F::build('WikiaResponse', array($format));
     $response->setVal($responseValueName, $responseValueData);
     $this->object->setResponse($response);
     if ($format == WikiaResponse::FORMAT_HTML) {
         $appMock = $this->getMock('WikiaApp', array('ajax'));
         /* @var $appMock WikiaApp */
         $registryMock = $this->getMock('WikiaGlobalRegistry', array('get'));
         $registryMock->expects($this->any())->method('get')->with($this->equalTo('wgAutoloadClasses'))->will($this->returnValue(array('Test' . 'Controller' => dirname(__FILE__) . '/_fixtures/TestController.php')));
         $appMock->setGlobalRegistry($registryMock);
         F::setInstance('App', $appMock);
         $this->object->setTemplate('Test', 'formatHTML');
     }
     $this->assertEquals($expectedResult, $this->object->render());
 }
 /**
  * @covers WikiaSearchConfig::setQuery
  * @covers WikiaSearchConfig::getQuery
  * @covers WikiaSearchConfig::getNamespaces
  * @covers WikiaSearchConfig::getQueryNoQuotes
  */
 public function testQueryAndNamespaceMethods()
 {
     $config = F::build('WikiaSearchConfig');
     $noNsQuery = 'foo';
     $nsQuery = 'File:foo';
     $searchEngineMock = $this->getMock('SearchEngine', array('DefaultNamespaces'), array());
     $expectedDefaultNamespaces = array(NS_MAIN);
     $searchEngineMock->staticExpects($this->any())->method('DefaultNamespaces')->will($this->returnValue($expectedDefaultNamespaces));
     $this->mockClass('SearchEngine', $searchEngineMock);
     $this->mockApp();
     F::setInstance('SearchEngine', $searchEngineMock);
     $originalNamespaces = $config->getNamespaces();
     $this->assertEquals($expectedDefaultNamespaces, $originalNamespaces, 'WikiaSearchConfig::getNamespaces should return SearchEngine::DefaultNamespaces if namespaces are not initialized.');
     $this->assertFalse($config->getQuery(), 'WikiaSearchConfig::getQuery should return false if the query has not been set.');
     $this->assertEquals($config, $config->setQuery($noNsQuery), 'WikiaSearchConfig::setQuery should provide a fluent interface');
     $this->assertEquals($noNsQuery, $config->getQuery(), 'Calling setQuery for a basic query should store the query value, accessible using getQuery.');
     $this->assertEquals($config->getQuery(), $config->getOriginalQuery(), 'The original query and the actual query should match for non-namespaced queries.');
     $this->assertEquals($originalNamespaces, $config->getNamespaces(), 'A query without a valid namespace prefix should not mutate the namespaces stored in the search config.');
     $this->assertEquals($config, $config->setQuery($nsQuery), 'WikiaSearchConfig::setQuery should provide a fluent interface');
     $this->assertEquals($nsQuery, $config->getOriginalQuery(), 'The original query should be stored under the "originalQuery" key regardless of prefix.');
     $this->assertEquals($noNsQuery, $config->getQuery(), 'The namespace prefix for a query should be stripped from the main query value.');
     $this->assertNotEquals($config->getQuery(), $config->getOriginalQuery(), 'The actual query and the original query should not be equivalent when passed a valid namespace prefix query.');
     $this->assertEquals(array_merge($originalNamespaces, array(NS_FILE)), $config->getNamespaces(), 'Setting a namespace-prefixed query should result in the appropriate namespace being appended.');
     $tildeQuery = 'foo~';
     $this->assertEquals('foo\\~', $config->setQuery($tildeQuery)->getQuery(), 'A query with a tilde should be escaped in getQuery.');
     $quoteQuery = '"foo bar"';
     $this->assertEquals('\\"foo bar\\"', $config->setQuery($quoteQuery)->getQuery(), 'A query with quotes should have the quotes escaped by default in getQuery.');
     $this->assertEquals('"foo bar"', $config->setQuery($quoteQuery)->getQuery(true), 'A query with quotes should have its quotes left alone if the first parameter of getQuery is passed as true.');
     $this->assertEquals('foo bar', $config->setQuery($quoteQuery)->getQueryNoQuotes(), 'A query with double quotes should have its quotes stripped in the default versoin of getQueryNoQuotes.');
     $this->assertEquals('foo bar\\~', $config->setQuery($quoteQuery . '~')->getQueryNoQuotes(), 'Tildes should be escaped in the default versoin of getQueryNoQuotes.');
     $this->assertEquals('foo bar~', $config->setQuery($quoteQuery . '~')->getQueryNoQuotes(true), 'Tildes should not be escaped in the raw versoin of getQueryNoQuotes.');
     $xssQuery = "foo'<script type='javascript'>alert('xss');</script>";
     $this->assertEquals("foo'alert\\('xss'\\);", $config->setQuery($xssQuery)->getQuery(), 'Setting a query should result in the sanitization and html entity decoding of that query.');
     $this->assertEquals("foo alert\\(xss\\);", $config->getQueryNoQuotes(), "Queries with quotes or apostrophes between two letters should be replaced with spaces with getQueryNoQuotes.");
     $htmlEntityQuery = "'foo & bar &amp; baz' &quot;";
     $this->assertEquals("'foo & bar & baz' \\\"", $config->setQuery($htmlEntityQuery)->getQuery(), "HTML entities in queries should be decoded when being set.");
     $this->assertEquals($config->setQuery($htmlEntityQuery)->getQuery(WikiaSearchConfig::QUERY_DEFAULT), $config->setQuery($htmlEntityQuery)->getQuery(), "The default behavior of the getQuery method should be identical to passing the WikiaSearchConfig::QUERY_DEFAULT constant.");
     $this->assertEquals("'foo & bar & baz' \"", $config->setQuery($htmlEntityQuery)->getQuery(WikiaSearchConfig::QUERY_RAW), "HTML entities in queries should be decoded when being set. Raw-strategy queries shouldn't escape anything.");
     $this->assertEquals("'foo &amp; bar &amp; baz' &quot;", $config->setQuery($htmlEntityQuery)->getQuery(WikiaSearchConfig::QUERY_ENCODED), "HTML entities in queries should be decoded when being set. HTML-decoded queries should properly HTML-encode all entities on access if using encoded strategy.");
     $utf8Query = '"аВатаР"';
     $this->assertEquals('\\"аВатаР\\"', $config->setQuery($utf8Query)->getQuery(WikiaSearchConfig::QUERY_DEFAULT), 'WikiaSearch::setQuery should not unnecessarily mutate UTF-8 characters. Retrieving them should return those characters, properly encoded.');
     $this->assertEquals('"аВатаР"', $config->setQuery($utf8Query)->getQuery(WikiaSearchConfig::QUERY_RAW), 'WikiaSearch::getQuery() should not unnecessarily mutate UTF-8 characters, and should not escape quotes when asking for raw query.');
     $this->assertEquals(htmlentities('"аВатаР"', ENT_COMPAT, 'UTF-8'), $config->setQuery($utf8Query)->getQuery(WikiaSearchConfig::QUERY_ENCODED), 'WikiaSearch::getQuery() should properly HTML-encode UTF-8 characters when using the encoded query strategy.');
 }
 /**
  * @covers WikiaSearchController::advancedBox
  */
 public function testAdvancedBox()
 {
     $mockResponse = $this->getMock('WikiaResponse', array('redirect', 'setVal'), array('html'));
     $mockRequest = $this->getMock('WikiaRequest', array('getVal'), array(array()));
     $mockSearchConfig = $this->getMock('WikiaSearchConfig', array('getNamespaces', 'getIncludeRedirects', 'getAdvanced'));
     $mockSearchEngine = $this->getMock('SearchEngine', array('searchableNamespaces'));
     $searchableNamespaces = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
     try {
         $this->searchController->advancedBox();
         $this->assertFalse(true, 'WikiaSearchController::advancedBox should throw an exception if the "config" is not set in the request.');
     } catch (Exception $e) {
     }
     $this->searchController->getRequest()->setVal('config', 'foo');
     try {
         $this->searchController->advancedBox();
         $this->assertFalse(true, 'WikiaSearchController::advancedBox should throw an exception if the "config" is set in the request, but is not an instance of WikiaSearchConfig.');
     } catch (Exception $e) {
     }
     $mockRequest->expects($this->any())->method('getVal')->with('config', false)->will($this->returnValue($mockSearchConfig));
     $this->searchController->setRequest($mockRequest);
     $mockSearchEngine->staticExpects($this->any())->method('searchableNamespaces')->will($this->returnValue($searchableNamespaces));
     $mockResponse->expects($this->at(0))->method('setVal')->with('namespaces', array(0, 14));
     $mockResponse->expects($this->at(1))->method('setVal')->with('searchableNamespaces', $searchableNamespaces);
     $mockResponse->expects($this->at(2))->method('setVal')->with('redirs', true);
     $mockResponse->expects($this->at(3))->method('setVal')->with('advanced', true);
     $mockSearchConfig->expects($this->any())->method('getNamespaces')->will($this->returnValue(array(0, 14)));
     $mockSearchConfig->expects($this->any())->method('getIncludeRedirects')->will($this->returnValue(true));
     $mockSearchConfig->expects($this->any())->method('getAdvanced')->will($this->returnValue(true));
     $this->mockClass('SearchEngine', $mockSearchEngine);
     $this->mockApp();
     F::setInstance('SearchEngine', $mockSearchEngine);
     $this->searchController->setResponse($mockResponse);
     $this->searchController->advancedBox();
     /**
      * @todo write tests for template evaluation
      */
 }
Exemple #20
0
 public function testWikiaPollAjax()
 {
     $this->markTestSkipped('Randomly failing due to master/slave lag');
     // FIXME
     $poll = WF::build('WikiaPollAjax');
     /* @var $poll WikiaPollAjax */
     // Sometimes the tear down doesn't execute?  Delete any old data before running create...
     $title = Title::newFromText("Unit Testing", NS_WIKIA_POLL);
     $article = new Article($title, NS_WIKIA_POLL);
     /* @var $article WikiPage */
     if ($article->exists()) {
         $article->doDelete("Unit Testing", true);
     }
     /* TODO: mock these objects more agressively
      * for now, just use a "real" title and article, as an integration test
      */
     $title = Title::newFromText("Unit Testing", NS_WIKIA_POLL);
     F::setInstance('Title', $title);
     $this->mockGlobalVariable("wgTitle", $title);
     $wgRequest = $this->getMock('WebRequest', array('getVal', 'getArray'));
     $wgRequest->expects($this->at(0))->method('getVal')->with($this->equalTo('question'))->will($this->returnValue("Unit Testing"));
     $wgRequest->expects($this->any())->method('getArray')->with($this->equalTo('answer'))->will($this->returnValue(array("One", "Two", "Three")));
     $wgRequest->expects($this->any())->method('getIP')->will($this->returnValue('127.0.0.1'));
     $this->mockGlobalVariable('wgRequest', $wgRequest);
     $this->mockApp();
     $result = $poll->create();
     $this->assertType("array", $result, "Create result is array");
     $this->assertEquals(true, $result["success"], "Create result is not success, error: " . (isset($result['error']) ? $result['error'] : 'unknown - error message not set'));
     $this->assertEquals('Poll:Unit Testing', $result['question'], 'Create Question matches input');
     $this->assertType("int", $result['pollId'], "Create returned a valid pollId");
     $title = Title::newFromText("Unit Testing", NS_WIKIA_POLL);
     $this->assertNotNull($title);
     $this->assertEquals($title->getText(), 'Unit Testing');
     // Second part of test is to see if we can "get" the same poll we created
     $pollId = $result['pollId'];
     $wgRequest = $this->getMock('WebRequest', array('getVal'));
     $wgRequest->expects($this->at(0))->method('getVal')->with($this->equalTo('pollId'))->will($this->returnValue($pollId));
     $this->mockGlobalVariable('wgRequest', $wgRequest);
     $result = $poll->get();
     $this->assertType("array", $result, "Get result is an array");
     $this->assertEquals(true, $result["exists"], "Get a poll that exists");
     $this->assertEquals('Poll:Unit Testing', $result['question'], 'Get Question matches original');
     $this->assertStringStartsWith('*One', $result['answer'], "Get answer was transformed correctly");
     // Third part of test is to update the poll we've got and see if that works too
     $wgRequest = $this->getMock('WebRequest', array('getVal', 'getArray'));
     $wgRequest->expects($this->at(0))->method('getVal')->with($this->equalTo('pollId'))->will($this->returnValue($pollId));
     $wgRequest->expects($this->any())->method('getArray')->with($this->equalTo('answer'))->will($this->returnValue(array("Three", "Two", "One")));
     $this->mockGlobalVariable('wgRequest', $wgRequest);
     $result = $poll->update();
     $this->assertType("array", $result, "Update result is array");
     $this->assertEquals(true, $result["success"], "Update result is success");
     $this->assertEquals('Poll:Unit Testing', $result['question'], 'Update Question matches input');
     // Fourth part of test is to register a vote for an item
     $wgRequest = $this->getMock('WebRequest', array('getVal'));
     $wgRequest->expects($this->at(0))->method('getVal')->with($this->equalTo('pollId'))->will($this->returnValue($pollId));
     $wgRequest->expects($this->at(1))->method('getVal')->with($this->equalTo('answer'))->will($this->returnValue(2));
     $this->mockGlobalVariable('wgRequest', $wgRequest);
     $result = $poll->vote();
     $this->assertType("array", $result, "Vote result is array");
     $this->assertType("string", $result["html"], "Vote result[html] is a block of HTML");
     $this->assertRegExp('/1 person voted/', $result["html"], "Vote result[html] says someone voted");
     // Fifth part of test is for checking to see if the user has voted
     $wgRequest = $this->getMock('WebRequest', array('getVal'));
     $wgRequest->expects($this->at(0))->method('getVal')->with($this->equalTo('pollId'))->will($this->returnValue($pollId));
     $this->mockGlobalVariable('wgRequest', $wgRequest);
     $result = $poll->hasVoted();
     $this->assertType("array", $result, "HasVoted result is array");
     $this->assertEquals(true, $result['hasVoted'], "HasVoted result is true");
     // clean up
     if ($article->exists()) {
         $article->doDelete("Unit Testing", true);
     }
 }
$wgAutoloadClasses['WikiaService'] = $IP . '/includes/wikia/nirvana/WikiaService.class.php';
$wgAutoloadClasses['WikiaModel'] = $IP . '/includes/wikia/nirvana/WikiaModel.class.php';
$wgAutoloadClasses['WikiaSpecialPageController'] = $IP . '/includes/wikia/nirvana/WikiaSpecialPageController.class.php';
$wgAutoloadClasses['WikiaErrorController'] = $IP . '/includes/wikia/nirvana/WikiaErrorController.class.php';
$wgAutoloadClasses['WikiaRequest'] = $IP . '/includes/wikia/nirvana/WikiaRequest.class.php';
$wgAutoloadClasses['WikiaResponse'] = $IP . '/includes/wikia/nirvana/WikiaResponse.class.php';
$wgAutoloadClasses['WikiaView'] = $IP . '/includes/wikia/nirvana/WikiaView.class.php';
$wgAutoloadClasses['WikiaSkin'] = $IP . '/includes/wikia/nirvana/WikiaSkin.class.php';
$wgAutoloadClasses['WikiaBaseTemplate'] = $IP . '/includes/wikia/nirvana/WikiaBaseTemplate.class.php';
$wgAutoloadClasses['WikiaFunctionWrapper'] = $IP . '/includes/wikia/nirvana/WikiaFunctionWrapper.class.php';
$wgAutoloadClasses['WikiaException'] = $IP . '/includes/wikia/nirvana/WikiaException.php';
$wgAutoloadClasses['WikiaDispatchedException'] = $IP . '/includes/wikia/nirvana/WikiaDispatchedException.class.php';
$wgAutoloadClasses['WikiaBaseTest'] = $IP . '/includes/wikia/tests/WikiaBaseTest.class.php';
$wgAutoloadClasses['WikiaAppMock'] = $IP . '/includes/wikia/tests/WikiaAppMock.class.php';
// Since we use this everywhere, we will just set up a global app reference now.
F::setInstance('App', new WikiaApp());
$app = F::app();
$wgAutoloadClasses['AssetsManager'] = $IP . '/extensions/wikia/AssetsManager/AssetsManager.class.php';
$wgAutoloadClasses['AssetsConfig'] = $IP . '/extensions/wikia/AssetsManager/AssetsConfig.class.php';
/**
 * Wikia API
 * (based on Nirvana)
 */
//holds a list of all the registered API controllers
//@see WikiaApp::registerApiController
$wgWikiaAPIControllers = array();
//ApiGate dependencies
include_once "{$IP}/lib/ApiGate/config.php";
//Wikia API base controller, all the others extend this class
$app->registerClass('WikiaApiController', "{$IP}/includes/wikia/api/WikiaApiController.class.php");
//Wikia API controllers
 protected function mockClass($className, $mock)
 {
     F::setInstance($className, $mock);
     $this->mockedClasses[] = $className;
 }
 public function testMoreLikeThis()
 {
     $mockClient = $this->getMock('Solarium_Client', array('createMoreLikeThis', 'moreLikeThis'));
     $defaultMltMethods = array('setMltFields', 'setFields', 'addParam', 'setStart', 'setRows', 'setDocumentClass');
     $addtlMltMethods = array('setInterestingTerms', 'addFilterQuery', 'setQuery', 'addParam');
     $mockMoreLikeThis = $this->getMock('Solarium_Query_MoreLikeThis', $defaultMltMethods + $addtlMltMethods);
     $mockResponse = $this->getMock('Solarium_Client_Response', array(), array('', array()));
     $mockMltResult = $this->getMock('Solarium_Result_MoreLikeThis', array(), array($mockClient, $mockMoreLikeThis, $mockResponse));
     $wikiaSearch = F::build('WikiaSearch', array($mockClient));
     $searchConfig = F::build('WikiaSearchConfig');
     $mockResultSet = $this->getMock('stdClass', array(), array(), 'WikiaSearchResultSet');
     $method = new ReflectionMethod('WikiaSearch', 'moreLikeThis');
     $method->setAccessible(true);
     $searchConfig->setMltFields(array('title', 'html'));
     $e = null;
     try {
         $method->invoke($wikiaSearch, $searchConfig);
     } catch (Exception $e) {
     }
     $this->assertNotNull($e, 'WikiaSearch::moreLikeThis should throw an exception if a query, stream body, or stream url has not been set.');
     $mockClient->expects($this->any())->method('createMoreLikeThis')->will($this->returnValue($mockMoreLikeThis));
     foreach ($defaultMltMethods as $mltMethod) {
         $mockMoreLikeThis->expects($this->any())->method($mltMethod)->will($this->returnValue($mockMoreLikeThis));
     }
     $this->mockClass('Solarium_Query_MoreLikeThis', $mockMoreLikeThis);
     $this->mockClass('WikiaSearchResultSet', $mockResultSet);
     $this->mockClass('Solarium_Client_Response', $mockResponse);
     $this->mockClass('Solarium_Result_MoreLikeThis', $mockMltResult);
     $this->mockApp();
     F::setInstance('WikiaSearchResultSet', $mockResultSet);
     F::setInstance('Solarium_Client', $mockClient);
     F::addClassConstructor('WikiaSearch', array('client' => $mockClient));
     $wikiaSearch = F::build('WikiaSearch');
     $searchConfig->setStreamBody('foo')->setInterestingTerms('list');
     $this->assertInstanceOf('WikiaSearchResultSet', $method->invoke($wikiaSearch, $searchConfig), 'WikiaSearch::moreLikeThis should return an instance of WikiaSearchResultSet');
     $searchConfig->setStreamBody(false)->setQuery('foo')->setInterestingTerms(false);
     $this->assertInstanceOf('WikiaSearchResultSet', $method->invoke($wikiaSearch, $searchConfig), 'WikiaSearch::moreLikeThis should return an instance of WikiaSearchResultSet, even if the client throws an exception.');
     $searchConfig->setStreamUrl('http://foo.com')->setMltFilterQuery('foo:bar');
     $this->assertInstanceOf('WikiaSearchResultSet', $method->invoke($wikiaSearch, $searchConfig), 'WikiaSearch::moreLikeThis should return an instance of WikiaSearchResultSet, even if the client throws an exception.');
     // lots more to do for this one, but the dependencies are really hard.
 }
<?php

/**
 * Adds support for MW messages in JS code
 *
 * Provides a way to register and use packages of messages in JavaScript via $.msg() function
 *
 * @see https://internal.wikia-inc.com/wiki/JSMessages
 * @author macbre
 */
$wgExtensionCredits['other'][] = array('name' => 'JSMessages', 'version' => '1.1', 'author' => 'Maciej Brencz', 'description' => 'Adds support for MW messages in JS code');
$dir = dirname(__FILE__);
// WikiaApp
$app = F::app();
// classes
$app->registerClass('JSMessages', $dir . '/JSMessages.class.php');
$app->registerClass('JSMessagesHelper', $dir . '/JSMessagesHelper.class.php');
$app->registerClass('JSMessagesController', $dir . '/JSMessagesController.class.php');
// hooks
$app->registerHook('WikiaSkinTopScripts', 'JSMessages', 'onWikiaSkinTopScripts');
$app->registerHook('MessageCacheReplace', 'JSMessagesHelper', 'onMessageCacheReplace');
// register instances
F::setInstance('JSMessages', new JSMessages());
F::setInstance('JSMessagesHelper', new JSMessagesHelper());
 function __construct()
 {
     parent::__construct();
     F::setInstance(__CLASS__, $this);
 }
<?php

/**
 * @brief JSSnippets simplify loading and execution of on demand JS files
 * @details Allows to specify list of JS dependencies to be loaded and callback function to be executed
 *
 * MW1.19 ResourceLoader provides an interface for defining list of modules to be loaded for a given article
 * TODO: use ResourceLoader instead of JSSnippets
 *
 * @ingroup Extensions
 *
 * @author Maciej Brencz (macbre) <macbre at wikia-inc.com>
 * @author Maciej Błaszkowski (Marooned) <marooned at wikia-inc.com>
 */
$dir = dirname(__FILE__);
// WikiaApp
$app = F::app();
// classes
$app->registerClass('JSSnippets', $dir . '/JSSnippets.class.php');
// hooks
$app->registerHook('EditPageLayoutModifyPreview', 'JSSnippets', 'onEditPageLayoutModifyPreview');
$app->registerHook('WikiaSkinTopScripts', 'JSSnippets', 'onMakeGlobalVariablesScript');
$app->registerHook('SkinAfterBottomScripts', 'JSSnippets', 'onSkinAfterBottomScripts');
// register instance of JSSnippets
F::setInstance('JSSnippets', new JSSnippets());
 protected function tearDown()
 {
     F::setInstance('App', $this->app);
 }