/**
  * @dataProvider provideContentObjs
  */
 public function testGetParsedFooter(CollaborationHubContent $content, $id)
 {
     $expected = ["<p><b>Test</b> content footer\n</p>", '', ''];
     $wc = TestingAccessWrapper::newFromObject($content);
     $actual = $wc->getParsedFooter(Title::newMainPage(), new ParserOptions());
     $this->assertEquals($expected[$id], $actual, $id);
 }
 protected function makeBlobStore($methods = null, $rl = null)
 {
     $blobStore = $this->getMockBuilder('MessageBlobStore')->setConstructorArgs([$rl])->setMethods($methods)->getMock();
     $access = TestingAccessWrapper::newFromObject($blobStore);
     $access->wanCache = $this->wanCache;
     return $blobStore;
 }
 function setUp()
 {
     parent::setUp();
     require_once __DIR__ . '/../data/helpers/WellProtectedClass.php';
     $this->raw = new WellProtectedClass();
     $this->wrapped = TestingAccessWrapper::newFromObject($this->raw);
 }
 public function testConstructor()
 {
     try {
         $provider = new BotPasswordSessionProvider();
         $this->fail('Expected exception not thrown');
     } catch (\InvalidArgumentException $ex) {
         $this->assertSame('MediaWiki\\Session\\BotPasswordSessionProvider::__construct: priority must be specified', $ex->getMessage());
     }
     try {
         $provider = new BotPasswordSessionProvider(array('priority' => SessionInfo::MIN_PRIORITY - 1));
         $this->fail('Expected exception not thrown');
     } catch (\InvalidArgumentException $ex) {
         $this->assertSame('MediaWiki\\Session\\BotPasswordSessionProvider::__construct: Invalid priority', $ex->getMessage());
     }
     try {
         $provider = new BotPasswordSessionProvider(array('priority' => SessionInfo::MAX_PRIORITY + 1));
         $this->fail('Expected exception not thrown');
     } catch (\InvalidArgumentException $ex) {
         $this->assertSame('MediaWiki\\Session\\BotPasswordSessionProvider::__construct: Invalid priority', $ex->getMessage());
     }
     $provider = new BotPasswordSessionProvider(array('priority' => 40));
     $priv = \TestingAccessWrapper::newFromObject($provider);
     $this->assertSame(40, $priv->priority);
     $this->assertSame('_BPsession', $priv->sessionCookieName);
     $this->assertSame(array(), $priv->sessionCookieOptions);
     $provider = new BotPasswordSessionProvider(array('priority' => 40, 'sessionCookieName' => null));
     $priv = \TestingAccessWrapper::newFromObject($provider);
     $this->assertSame('_BPsession', $priv->sessionCookieName);
     $provider = new BotPasswordSessionProvider(array('priority' => 40, 'sessionCookieName' => 'Foo', 'sessionCookieOptions' => array('Bar')));
     $priv = \TestingAccessWrapper::newFromObject($provider);
     $this->assertSame('Foo', $priv->sessionCookieName);
     $this->assertSame(array('Bar'), $priv->sessionCookieOptions);
 }
 public function testConstructor()
 {
     $provider = new ThrottlePreAuthenticationProvider();
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $config = new \HashConfig(['AccountCreationThrottle' => 123, 'PasswordAttemptThrottle' => [['count' => 5, 'seconds' => 300]]]);
     $provider->setConfig($config);
     $this->assertSame(['accountCreationThrottle' => [['count' => 123, 'seconds' => 86400]], 'passwordAttemptThrottle' => [['count' => 5, 'seconds' => 300]]], $providerPriv->throttleSettings);
     $accountCreationThrottle = \TestingAccessWrapper::newFromObject($providerPriv->accountCreationThrottle);
     $this->assertSame([['count' => 123, 'seconds' => 86400]], $accountCreationThrottle->conditions);
     $passwordAttemptThrottle = \TestingAccessWrapper::newFromObject($providerPriv->passwordAttemptThrottle);
     $this->assertSame([['count' => 5, 'seconds' => 300]], $passwordAttemptThrottle->conditions);
     $provider = new ThrottlePreAuthenticationProvider(['accountCreationThrottle' => [['count' => 43, 'seconds' => 10000]], 'passwordAttemptThrottle' => [['count' => 11, 'seconds' => 100]]]);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $config = new \HashConfig(['AccountCreationThrottle' => 123, 'PasswordAttemptThrottle' => [['count' => 5, 'seconds' => 300]]]);
     $provider->setConfig($config);
     $this->assertSame(['accountCreationThrottle' => [['count' => 43, 'seconds' => 10000]], 'passwordAttemptThrottle' => [['count' => 11, 'seconds' => 100]]], $providerPriv->throttleSettings);
     $cache = new \HashBagOStuff();
     $provider = new ThrottlePreAuthenticationProvider(['cache' => $cache]);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $provider->setConfig(new \HashConfig(['AccountCreationThrottle' => [['count' => 1, 'seconds' => 1]], 'PasswordAttemptThrottle' => [['count' => 1, 'seconds' => 1]]]));
     $accountCreationThrottle = \TestingAccessWrapper::newFromObject($providerPriv->accountCreationThrottle);
     $this->assertSame($cache, $accountCreationThrottle->cache);
     $passwordAttemptThrottle = \TestingAccessWrapper::newFromObject($providerPriv->passwordAttemptThrottle);
     $this->assertSame($cache, $passwordAttemptThrottle->cache);
 }
 protected function getInstance(array $args = [])
 {
     $req = new RememberMeAuthenticationRequest();
     $reqWrapper = \TestingAccessWrapper::newFromObject($req);
     $reqWrapper->expiration = $args[0];
     return $req;
 }
Example #7
0
 protected function setUp()
 {
     parent::setUp();
     $this->cache = new WANObjectCache(['cache' => new HashBagOStuff(), 'pool' => 'testcache-hash', 'relayer' => new EventRelayerNull([])]);
     $wanCache = TestingAccessWrapper::newFromObject($this->cache);
     /** @noinspection PhpUndefinedFieldInspection */
     $this->internalCache = $wanCache->cache;
 }
Example #8
0
 public function testMatch()
 {
     $token = \TestingAccessWrapper::newFromObject(new Token('sekret', 'salty', false));
     $test = $token->toStringAtTimestamp(time() - 10);
     $this->assertTrue($token->match($test));
     $this->assertTrue($token->match($test, 12));
     $this->assertFalse($token->match($test, 8));
     $this->assertFalse($token->match('ee2f7a2488dea9176c224cfb400d43be5644fdea-\\'));
 }
 public function testConstructor()
 {
     $config = new \HashConfig(['EnableEmail' => true, 'EmailAuthentication' => true]);
     $provider = new EmailNotificationSecondaryAuthenticationProvider();
     $provider->setConfig($config);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $this->assertTrue($providerPriv->sendConfirmationEmail);
     $provider = new EmailNotificationSecondaryAuthenticationProvider(['sendConfirmationEmail' => false]);
     $provider->setConfig($config);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $this->assertFalse($providerPriv->sendConfirmationEmail);
 }
Example #10
0
 public function testForcePrimaryAuthenticationProviders()
 {
     $mockA = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
     $mockB = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
     $mockB2 = $this->getMockForAbstractClass(PrimaryAuthenticationProvider::class);
     $mockA->expects($this->any())->method('getUniqueId')->will($this->returnValue('A'));
     $mockB->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
     $mockB2->expects($this->any())->method('getUniqueId')->will($this->returnValue('B'));
     $this->primaryauthMocks = [$mockA];
     $this->logger = new \TestLogger(true);
     // Test without first initializing the configured providers
     $this->initializeManager();
     $this->manager->forcePrimaryAuthenticationProviders([$mockB], 'testing');
     $this->assertSame(['B' => $mockB], $this->managerPriv->getPrimaryAuthenticationProviders());
     $this->assertSame(null, $this->managerPriv->getAuthenticationProvider('A'));
     $this->assertSame($mockB, $this->managerPriv->getAuthenticationProvider('B'));
     $this->assertSame([[LogLevel::WARNING, 'Overriding AuthManager primary authn because testing']], $this->logger->getBuffer());
     $this->logger->clearBuffer();
     // Test with first initializing the configured providers
     $this->initializeManager();
     $this->assertSame($mockA, $this->managerPriv->getAuthenticationProvider('A'));
     $this->assertSame(null, $this->managerPriv->getAuthenticationProvider('B'));
     $this->request->getSession()->setSecret('AuthManager::authnState', 'test');
     $this->request->getSession()->setSecret('AuthManager::accountCreationState', 'test');
     $this->manager->forcePrimaryAuthenticationProviders([$mockB], 'testing');
     $this->assertSame(['B' => $mockB], $this->managerPriv->getPrimaryAuthenticationProviders());
     $this->assertSame(null, $this->managerPriv->getAuthenticationProvider('A'));
     $this->assertSame($mockB, $this->managerPriv->getAuthenticationProvider('B'));
     $this->assertNull($this->request->getSession()->getSecret('AuthManager::authnState'));
     $this->assertNull($this->request->getSession()->getSecret('AuthManager::accountCreationState'));
     $this->assertSame([[LogLevel::WARNING, 'Overriding AuthManager primary authn because testing'], [LogLevel::WARNING, 'PrimaryAuthenticationProviders have already been accessed! I hope nothing breaks.']], $this->logger->getBuffer());
     $this->logger->clearBuffer();
     // Test duplicate IDs
     $this->initializeManager();
     try {
         $this->manager->forcePrimaryAuthenticationProviders([$mockB, $mockB2], 'testing');
         $this->fail('Expected exception not thrown');
     } catch (\RuntimeException $ex) {
         $class1 = get_class($mockB);
         $class2 = get_class($mockB2);
         $this->assertSame("Duplicate specifications for id B (classes {$class2} and {$class1})", $ex->getMessage());
     }
     // Wrong classes
     $mock = $this->getMockForAbstractClass(AuthenticationProvider::class);
     $mock->expects($this->any())->method('getUniqueId')->will($this->returnValue('X'));
     $class = get_class($mock);
     try {
         $this->manager->forcePrimaryAuthenticationProviders([$mock], 'testing');
         $this->fail('Expected exception not thrown');
     } catch (\RuntimeException $ex) {
         $this->assertSame("Expected instance of MediaWiki\\Auth\\PrimaryAuthenticationProvider, got {$class}", $ex->getMessage());
     }
 }
 protected function setUp()
 {
     parent::setUp();
     if ($this->getCliArg('use-wanobjectcache')) {
         $name = $this->getCliArg('use-wanobjectcache');
         $this->cache = ObjectCache::getWANInstance($name);
     } else {
         $this->cache = new WANObjectCache(['cache' => new HashBagOStuff(), 'pool' => 'testcache-hash', 'relayer' => new EventRelayerNull([])]);
     }
     $wanCache = TestingAccessWrapper::newFromObject($this->cache);
     $this->internalCache = $wanCache->cache;
 }
 function testGCFraudFilters()
 {
     $this->setMwGlobals(array('wgGlobalCollectGatewayEnableMinfraud' => true));
     $options = $this->getDonorTestData();
     $options['email'] = '*****@*****.**';
     $class = $this->testAdapterClass;
     $gateway = $this->getFreshGatewayObject($options);
     $gateway->runAntifraudFilters();
     $this->assertEquals('reject', $gateway->getValidationAction(), 'Validation action is not as expected');
     $exposed = TestingAccessWrapper::newFromObject($gateway);
     $this->assertEquals(157.5, $exposed->risk_score, 'RiskScore is not as expected');
 }
 /**
  * @covers ResourceLoaderClientHtml::__construct
  * @covers ResourceLoaderClientHtml::setModules
  * @covers ResourceLoaderClientHtml::setModuleStyles
  * @covers ResourceLoaderClientHtml::setModuleScripts
  * @covers ResourceLoaderClientHtml::getData
  * @covers ResourceLoaderClientHtml::getContext
  */
 public function testGetData()
 {
     $context = self::makeContext();
     $context->getResourceLoader()->register(self::makeSampleModules());
     $client = new ResourceLoaderClientHtml($context);
     $client->setModules(['test', 'test.private.bottom', 'test.private.top', 'test.top', 'test.unregistered']);
     $client->setModuleStyles(['test.styles.mixed', 'test.styles.mixed.user.empty', 'test.styles.private', 'test.styles.pure', 'test.unregistered.styles']);
     $client->setModuleScripts(['test.scripts', 'test.scripts.mixed.user.empty', 'test.scripts.top', 'test.unregistered.scripts']);
     $expected = ['states' => ['test.private.top' => 'loading', 'test.private.bottom' => 'loading', 'test.styles.pure' => 'ready', 'test.styles.mixed.user.empty' => 'ready', 'test.styles.private' => 'ready', 'test.scripts' => 'loading', 'test.scripts.top' => 'loading', 'test.scripts.mixed.user.empty' => 'ready'], 'general' => ['top' => ['test.top'], 'bottom' => ['test']], 'styles' => ['test.styles.mixed', 'test.styles.pure'], 'scripts' => ['top' => ['test.scripts.top'], 'bottom' => ['test.scripts']], 'embed' => ['styles' => ['test.styles.private'], 'general' => ['top' => ['test.private.top'], 'bottom' => ['test.private.bottom']]]];
     $access = TestingAccessWrapper::newFromObject($client);
     $this->assertEquals($expected, $access->getData());
 }
 public function testConstructor()
 {
     $provider = new CheckBlocksSecondaryAuthenticationProvider();
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $config = new \HashConfig(['BlockDisablesLogin' => false]);
     $provider->setConfig($config);
     $this->assertSame(false, $providerPriv->blockDisablesLogin);
     $provider = new CheckBlocksSecondaryAuthenticationProvider(['blockDisablesLogin' => true]);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $config = new \HashConfig(['BlockDisablesLogin' => false]);
     $provider->setConfig($config);
     $this->assertSame(true, $providerPriv->blockDisablesLogin);
 }
 private function compareMessages($msg, $msg2)
 {
     $this->assertSame($msg->getKey(), $msg2->getKey(), 'getKey');
     $this->assertSame($msg->getKeysToTry(), $msg2->getKeysToTry(), 'getKeysToTry');
     $this->assertSame($msg->getParams(), $msg2->getParams(), 'getParams');
     $this->assertSame($msg->getFormat(), $msg2->getFormat(), 'getFormat');
     $this->assertSame($msg->getLanguage(), $msg2->getLanguage(), 'getLanguage');
     $msg = TestingAccessWrapper::newFromObject($msg);
     $msg2 = TestingAccessWrapper::newFromObject($msg2);
     foreach (array('interface', 'useDatabase', 'title') as $key) {
         $this->assertSame($msg->{$key}, $msg2->{$key}, $key);
     }
 }
 private function compareMessages($msg, $msg2)
 {
     $this->assertSame($msg->getKey(), $msg2->getKey(), 'getKey');
     $this->assertSame($msg->getKeysToTry(), $msg2->getKeysToTry(), 'getKeysToTry');
     $this->assertSame($msg->getParams(), $msg2->getParams(), 'getParams');
     $this->assertSame($msg->getFormat(), $msg2->getFormat(), 'getFormat');
     $this->assertSame($msg->getLanguage(), $msg2->getLanguage(), 'getLanguage');
     $msg = TestingAccessWrapper::newFromObject($msg);
     $msg2 = TestingAccessWrapper::newFromObject($msg2);
     $this->assertSame($msg->interface, $msg2->interface, 'interface');
     $this->assertSame($msg->useDatabase, $msg2->useDatabase, 'useDatabase');
     $this->assertSame($msg->title ? $msg->title->getFullText() : null, $msg2->title ? $msg2->title->getFullText() : null, 'title');
 }
 /**
  * @dataProvider provideHandlers
  * @param ContentHandler $handler
  */
 public function testMakeEmptyContent(ContentHandler $handler)
 {
     $content = $handler->makeEmptyContent();
     $this->assertInstanceOf(Content::class, $content);
     if ($handler instanceof TextContentHandler) {
         // TextContentHandler::getContentClass() is protected, so bypass
         // that restriction
         $testingWrapper = TestingAccessWrapper::newFromObject($handler);
         $this->assertInstanceOf($testingWrapper->getContentClass(), $content);
     }
     $handlerClass = get_class($handler);
     $contentClass = get_class($content);
     $this->assertTrue($content->isValid(), "{$handlerClass}::makeEmptyContent() did not return a valid content ({$contentClass}::isValid())");
 }
Example #18
0
 /**
  * @covers HashBagOStuff::doGet
  * @covers HashBagOStuff::expire
  */
 public function testExpire()
 {
     $cache = new HashBagOStuff();
     $cacheInternal = TestingAccessWrapper::newFromObject($cache);
     $cache->set('foo', 1);
     $cache->set('bar', 1, 10);
     $cache->set('baz', 1, -10);
     $this->assertEquals(0, $cacheInternal->bag['foo'][$cache::KEY_EXP], 'Indefinite');
     // 2 seconds tolerance
     $this->assertEquals(time() + 10, $cacheInternal->bag['bar'][$cache::KEY_EXP], 'Future', 2);
     $this->assertEquals(time() - 10, $cacheInternal->bag['baz'][$cache::KEY_EXP], 'Past', 2);
     $this->assertEquals(1, $cache->get('bar'), 'Key not expired');
     $this->assertEquals(false, $cache->get('baz'), 'Key expired');
 }
Example #19
0
 /**
  * If you need a Session for testing but don't want to create a backend to
  * construct one, use this.
  * @param object $backend Object to serve as the SessionBackend
  * @param int $index Index
  * @return Session
  */
 public static function getDummySession($backend = null, $index = -1)
 {
     $rc = new \ReflectionClass('MediaWiki\\Session\\Session');
     if (!method_exists($rc, 'newInstanceWithoutConstructor')) {
         \PHPUnit_Framework_Assert::markTestSkipped('ReflectionClass::newInstanceWithoutConstructor isn\'t available');
     }
     if ($backend === null) {
         $backend = new DummySessionBackend();
     }
     $session = $rc->newInstanceWithoutConstructor();
     $priv = \TestingAccessWrapper::newFromObject($session);
     $priv->backend = $backend;
     $priv->index = $index;
     return $session;
 }
 public function testAbstractAuthenticationProvider()
 {
     $provider = $this->getMockForAbstractClass(AbstractAuthenticationProvider::class);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $obj = $this->getMockForAbstractClass('Psr\\Log\\LoggerInterface');
     $provider->setLogger($obj);
     $this->assertSame($obj, $providerPriv->logger, 'setLogger');
     $obj = AuthManager::singleton();
     $provider->setManager($obj);
     $this->assertSame($obj, $providerPriv->manager, 'setManager');
     $obj = $this->getMockForAbstractClass('Config');
     $provider->setConfig($obj);
     $this->assertSame($obj, $providerPriv->config, 'setConfig');
     $this->assertType('string', $provider->getUniqueId(), 'getUniqueId');
 }
 public function testCheckAudience()
 {
     $mock = TestingAccessWrapper::newFromObject($this->getMockForAbstractClass('CentralIdLookup'));
     $user = static::getTestSysop()->getUser();
     $this->assertSame($user, $mock->checkAudience($user));
     $user = $mock->checkAudience(CentralIdLookup::AUDIENCE_PUBLIC);
     $this->assertInstanceOf('User', $user);
     $this->assertSame(0, $user->getId());
     $this->assertNull($mock->checkAudience(CentralIdLookup::AUDIENCE_RAW));
     try {
         $mock->checkAudience(100);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Invalid audience', $ex->getMessage());
     }
 }
 public function testPurgeMergeWeb()
 {
     $this->setMwGlobals('wgCommandLineMode', false);
     $urls1 = array();
     $title = Title::newMainPage();
     $urls1[] = $title->getCanonicalURL('?x=1');
     $urls1[] = $title->getCanonicalURL('?x=2');
     $urls1[] = $title->getCanonicalURL('?x=3');
     $update1 = new CdnCacheUpdate($urls1);
     DeferredUpdates::addUpdate($update1);
     $urls2 = array();
     $urls2[] = $title->getCanonicalURL('?x=2');
     $urls2[] = $title->getCanonicalURL('?x=3');
     $urls2[] = $title->getCanonicalURL('?x=4');
     $update2 = new CdnCacheUpdate($urls2);
     DeferredUpdates::addUpdate($update2);
     $wrapper = TestingAccessWrapper::newFromObject($update1);
     $this->assertEquals(array_merge($urls1, $urls2), $wrapper->urls);
 }
Example #23
0
 /**
  * @dataProvider provideGetParameterFromSettings
  * @param string|null $input
  * @param array $paramSettings
  * @param mixed $expected
  * @param string[] $warnings
  */
 public function testGetParameterFromSettings($input, $paramSettings, $expected, $warnings)
 {
     $mock = new MockApi();
     $wrapper = TestingAccessWrapper::newFromObject($mock);
     $context = new DerivativeContext($mock);
     $context->setRequest(new FauxRequest($input !== null ? ['foo' => $input] : []));
     $wrapper->mMainModule = new ApiMain($context);
     if ($expected instanceof UsageException) {
         try {
             $wrapper->getParameterFromSettings('foo', $paramSettings, true);
         } catch (UsageException $ex) {
             $this->assertEquals($expected, $ex);
         }
     } else {
         $result = $wrapper->getParameterFromSettings('foo', $paramSettings, true);
         $this->assertSame($expected, $result);
         $this->assertSame($warnings, $mock->warnings);
     }
 }
 /**
  * Make sure language is staged correctly when qs param is uppercase
  */
 function testLanguageCaseSensitivity()
 {
     $init = $this->getDonorTestData();
     $init['language'] = 'FR';
     $gateway = $this->getFreshGatewayObject($init);
     $gateway->do_transaction('donate');
     $exposed = TestingAccessWrapper::newFromObject($gateway);
     $ret = $exposed->buildRequestParams();
     $expected = array('allowedMethods' => 'card', 'billingAddress.street' => $init['street'], 'billingAddress.city' => $init['city'], 'billingAddress.postalCode' => $init['zip'], 'billingAddress.stateOrProvince' => $init['state'], 'billingAddress.country' => $init['country'], 'billingAddress.houseNumberOrName' => 'NA', 'billingAddressType' => 2, 'card.cardHolderName' => $init['fname'] . ' ' . $init['lname'], 'currencyCode' => $init['currency_code'], 'merchantAccount' => 'wikitest', 'merchantReference' => $exposed->getData_Staged('order_id'), 'merchantSig' => $exposed->getData_Staged('hpp_signature'), 'paymentAmount' => $init['amount'] * 100, 'skinCode' => 'testskin', 'shopperLocale' => 'fr_US', 'shopperEmail' => '*****@*****.**', 'offset' => '52');
     //deal with problem keys.
     //@TODO: Refactor gateway so these are more testable
     $problems = array('sessionValidity', 'shipBeforeDate');
     foreach ($problems as $oneproblem) {
         if (isset($ret[$oneproblem])) {
             unset($ret[$oneproblem]);
         }
     }
     $this->assertEquals($expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL');
     $this->assertNotNull($gateway->getData_Unstaged_Escaped('order_id'), "Adyen order_id is null, and we need one for 'merchantReference'");
 }
Example #25
0
    public function testPreferences()
    {
        $prefs = array();
        $repo = TestingAccessWrapper::newFromObject(new MediaWikiGadgetsDefinitionRepo());
        // Force usage of a MediaWikiGadgetsDefinitionRepo
        GadgetRepo::setSingleton($repo);
        $gadgets = $repo->fetchStructuredList('* foo | foo.js
==keep-section1==
* bar| bar.js
==remove-section==
* baz [rights=embezzle] |baz.js
==keep-section2==
* quux [rights=read] | quux.js');
        $this->assertGreaterThanOrEqual(2, count($gadgets), "Gadget list parsed");
        $repo->definitionCache = $gadgets;
        $this->assertTrue(GadgetHooks::getPreferences(new User(), $prefs), 'GetPrefences hook should return true');
        $options = $prefs['gadgets']['options'];
        $this->assertFalse(isset($options['&lt;gadget-section-remove-section&gt;']), 'Must not show empty sections');
        $this->assertTrue(isset($options['&lt;gadget-section-keep-section1&gt;']));
        $this->assertTrue(isset($options['&lt;gadget-section-keep-section2&gt;']));
    }
Example #26
0
 public function testClear()
 {
     $session = TestUtils::getDummySession();
     $priv = \TestingAccessWrapper::newFromObject($session);
     $backend = $this->getMock('MediaWiki\\Session\\DummySessionBackend', array('canSetUser', 'setUser', 'save'));
     $backend->expects($this->once())->method('canSetUser')->will($this->returnValue(true));
     $backend->expects($this->once())->method('setUser')->with($this->callback(function ($user) {
         return $user instanceof User && $user->isAnon();
     }));
     $backend->expects($this->once())->method('save');
     $priv->backend = $backend;
     $session->clear();
     $this->assertSame(array(), $backend->data);
     $this->assertTrue($backend->dirty);
     $backend = $this->getMock('MediaWiki\\Session\\DummySessionBackend', array('canSetUser', 'setUser', 'save'));
     $backend->data = array();
     $backend->expects($this->once())->method('canSetUser')->will($this->returnValue(true));
     $backend->expects($this->once())->method('setUser')->with($this->callback(function ($user) {
         return $user instanceof User && $user->isAnon();
     }));
     $backend->expects($this->once())->method('save');
     $priv->backend = $backend;
     $session->clear();
     $this->assertFalse($backend->dirty);
     $backend = $this->getMock('MediaWiki\\Session\\DummySessionBackend', array('canSetUser', 'setUser', 'save'));
     $backend->expects($this->once())->method('canSetUser')->will($this->returnValue(false));
     $backend->expects($this->never())->method('setUser');
     $backend->expects($this->once())->method('save');
     $priv->backend = $backend;
     $session->clear();
     $this->assertSame(array(), $backend->data);
     $this->assertTrue($backend->dirty);
 }
Example #27
0
 /**
  * Test conditional headers output
  * @dataProvider provideConditionalRequestHeadersOutput
  * @param array $conditions Return data for ApiBase::getConditionalRequestData
  * @param array $headers Expected output headers
  * @param bool $isError $isError flag
  * @param bool $post Request is a POST
  */
 public function testConditionalRequestHeadersOutput($conditions, $headers, $isError = false, $post = false)
 {
     $request = new FauxRequest(array('action' => 'query', 'meta' => 'siteinfo'), $post);
     $response = $request->response();
     $api = new ApiMain($request);
     $priv = TestingAccessWrapper::newFromObject($api);
     $priv->mInternalMode = false;
     $module = $this->getMockBuilder('ApiBase')->setConstructorArgs(array($api, 'mock'))->setMethods(array('getConditionalRequestData'))->getMockForAbstractClass();
     $module->expects($this->any())->method('getConditionalRequestData')->will($this->returnCallback(function ($condition) use($conditions) {
         return isset($conditions[$condition]) ? $conditions[$condition] : null;
     }));
     $priv->mModule = $module;
     $priv->sendCacheHeaders($isError);
     foreach (array('Last-Modified', 'ETag') as $header) {
         $this->assertEquals(isset($headers[$header]) ? $headers[$header] : null, $response->getHeader($header), $header);
     }
 }
Example #28
0
 public function testGetAllowedUserRights()
 {
     $provider = $this->getMockForAbstractClass('MediaWiki\\Session\\SessionProvider');
     $backend = TestUtils::getDummySessionBackend();
     try {
         $provider->getAllowedUserRights($backend);
         $this->fail('Expected exception not thrown');
     } catch (\InvalidArgumentException $ex) {
         $this->assertSame('Backend\'s provider isn\'t $this', $ex->getMessage());
     }
     \TestingAccessWrapper::newFromObject($backend)->provider = $provider;
     $this->assertNull($provider->getAllowedUserRights($backend));
 }
 public function tearDown()
 {
     parent::tearDown();
     TestingAccessWrapper::newFromClass('Hooks')->handlers = $this->originalHandlers;
     SpecialPageFactory::resetList();
 }
 function testStageFiscalNumber()
 {
     $init = $this->getDonorTestData('BR');
     $init['fiscal_number'] = '000.034.567-89';
     $gateway = $this->getFreshGatewayObject($init);
     $gateway->doPayment();
     $exposed = TestingAccessWrapper::newFromObject($gateway);
     $staged = $exposed->getData_Staged('fiscal_number');
     $this->assertEquals('00003456789', $staged, 'Not stripping fiscal_number punctuation in doPayment');
 }