public function testUnsaved() { $user = $this->testUser->getUser(); $bp = BotPassword::newUnsaved(['user' => $user, 'appId' => 'DoesNotExist']); $this->assertInstanceOf('BotPassword', $bp); $this->assertFalse($bp->isSaved()); $this->assertSame(42, $bp->getUserCentralId()); $this->assertSame('DoesNotExist', $bp->getAppId()); $this->assertEquals(MWRestrictions::newDefault(), $bp->getRestrictions()); $this->assertSame([], $bp->getGrants()); $bp = BotPassword::newUnsaved(['username' => 'UTDummy', 'appId' => 'DoesNotExist2', 'restrictions' => MWRestrictions::newFromJson('{"IPAddresses":["127.0.0.0/8"]}'), 'grants' => ['test']]); $this->assertInstanceOf('BotPassword', $bp); $this->assertFalse($bp->isSaved()); $this->assertSame(43, $bp->getUserCentralId()); $this->assertSame('DoesNotExist2', $bp->getAppId()); $this->assertEquals('{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson()); $this->assertSame(['test'], $bp->getGrants()); $user = $this->testUser->getUser(); $bp = BotPassword::newUnsaved(['centralId' => 45, 'appId' => 'DoesNotExist']); $this->assertInstanceOf('BotPassword', $bp); $this->assertFalse($bp->isSaved()); $this->assertSame(45, $bp->getUserCentralId()); $this->assertSame('DoesNotExist', $bp->getAppId()); $user = $this->testUser->getUser(); $bp = BotPassword::newUnsaved(['user' => $user, 'appId' => 'BotPassword']); $this->assertInstanceOf('BotPassword', $bp); $this->assertFalse($bp->isSaved()); $this->assertNull(BotPassword::newUnsaved(['user' => $user, 'appId' => ''])); $this->assertNull(BotPassword::newUnsaved(['user' => $user, 'appId' => str_repeat('X', BotPassword::APPID_MAXLENGTH + 1)])); $this->assertNull(BotPassword::newUnsaved(['user' => $this->testUserName, 'appId' => 'Ok'])); $this->assertNull(BotPassword::newUnsaved(['username' => 'UTInvalid', 'appId' => 'Ok'])); $this->assertNull(BotPassword::newUnsaved(['appId' => 'Ok'])); }
public function testGetEntityParserOutputGenerator_noParserOptionLanguage() { $parserOutputGeneratorFactory = $this->getEntityParserOutputGeneratorFactory(); $testUser = new \TestUser('Wikibase User'); $instance = $parserOutputGeneratorFactory->getEntityParserOutputGenerator(new ParserOptions($testUser->getUser())); $this->assertInstanceOf('Wikibase\\Repo\\ParserOutput\\EntityParserOutputGenerator', $instance); }
protected function setUp() { parent::setUp(); $testUser = new \TestUser('ActionTestUser'); $user = $testUser->getUser(); $user->setId(123456789); $this->setMwGlobals(array('wgUser' => $user, 'wgLang' => Language::factory($this->languageCode), 'wgRequest' => new FauxRequest(), 'wgGroupPermissions' => array('*' => array('edit' => true, 'read' => true)))); ApiQueryInfo::resetTokenCache(); }
/** * Get a TestUser object that the caller may not modify. * * Whenever possible, unit tests should use immutable users, because * immutable users can be reused in multiple tests, which helps keep * the unit tests fast. * * @since 1.28 * * @param string[] $groups Groups the test user should be added to. * @return TestUser */ public static function getImmutableTestUser($groups = []) { $groups = array_unique($groups); sort($groups); $key = implode(',', $groups); $testUser = isset(self::$testUsers[$key]) ? self::$testUsers[$key] : false; if (!$testUser || !$testUser->getUser()->isLoggedIn()) { $id = self::getNextId(); // Hack! If this is the primary sysop account, make the username // be 'UTSysop', for back-compat, and for the sake of PHPUnit data // provider methods, which are executed before the test database // is set up. See T136348. if ($groups === ['bureaucrat', 'sysop']) { $username = '******'; $password = '******'; } else { $username = "******"; $password = wfRandomString(20); } self::$testUsers[$key] = $testUser = new TestUser($username, "Name {$id}", "{$id}@mediawiki.test", $groups, $password); } $testUser->getUser()->clearInstanceCache(); return self::$testUsers[$key]; }
public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() { $user = new TestUser(__METHOD__); list($html, ) = $this->executeSpecialPage('', null, 'qqx', $user->getUser()); $this->assertContains('(nowatchlist)', $html); }
protected function getTokenList(TestUser $user, $session = null) { $data = $this->doApiRequest(['action' => 'tokens', 'type' => 'edit|delete|protect|move|block|unblock|watch'], $session, false, $user->getUser()); if (!array_key_exists('tokens', $data[0])) { throw new MWException('Api failed to return a token list'); } return $data[0]['tokens']; }
public function testEditRawPage_hasTitlesBox() { $user = new TestUser(__METHOD__); list($html, ) = $this->executeSpecialPage('raw', null, 'qqx', $user->getUser()); $this->assertContains('<textarea id="mw-input-wpTitles"', $html); }