/** * @dataProvider provideAccountCreationLogging * @param bool $isAnon * @param string|null $logSubtype */ public function testAccountCreationLogging($isAnon, $logSubtype) { $creator = $isAnon ? new \User() : \User::newFromName('UTSysop'); $username = self::usernameForCreation(); $this->initializeManager(); // Set up lots of mocks... $mock = $this->getMockForAbstractClass("MediaWiki\\Auth\\PrimaryAuthenticationProvider", []); $mock->expects($this->any())->method('getUniqueId')->will($this->returnValue('primary')); $mock->expects($this->any())->method('testUserForCreation')->will($this->returnValue(StatusValue::newGood())); $mock->expects($this->any())->method('testForAccountCreation')->will($this->returnValue(StatusValue::newGood())); $mock->expects($this->any())->method('accountCreationType')->will($this->returnValue(PrimaryAuthenticationProvider::TYPE_CREATE)); $mock->expects($this->any())->method('testUserExists')->will($this->returnValue(false)); $mock->expects($this->any())->method('beginPrimaryAccountCreation')->will($this->returnValue(AuthenticationResponse::newPass($username))); $mock->expects($this->any())->method('finishAccountCreation')->will($this->returnValue($logSubtype)); $this->primaryauthMocks = [$mock]; $this->initializeManager(true); $this->logger->setCollect(true); $this->config->set('NewUserLog', true); $dbw = wfGetDB(DB_MASTER); $maxLogId = $dbw->selectField('logging', 'MAX(log_id)', ['log_type' => 'newusers']); $userReq = new UsernameAuthenticationRequest(); $userReq->username = $username; $reasonReq = new CreationReasonAuthenticationRequest(); $reasonReq->reason = $this->toString(); $ret = $this->manager->beginAccountCreation($creator, [$userReq, $reasonReq], 'http://localhost/'); $this->assertSame(AuthenticationResponse::PASS, $ret->status); $user = \User::newFromName($username); $this->assertNotEquals(0, $user->getId(), 'sanity check'); $this->assertNotEquals($creator->getId(), $user->getId(), 'sanity check'); $data = \DatabaseLogEntry::getSelectQueryData(); $rows = iterator_to_array($dbw->select($data['tables'], $data['fields'], ['log_id > ' . (int) $maxLogId, 'log_type' => 'newusers'] + $data['conds'], __METHOD__, $data['options'], $data['join_conds'])); $this->assertCount(1, $rows); $entry = \DatabaseLogEntry::newFromRow(reset($rows)); $this->assertSame($logSubtype ?: ($isAnon ? 'create' : 'create2'), $entry->getSubtype()); $this->assertSame($isAnon ? $user->getId() : $creator->getId(), $entry->getPerformer()->getId()); $this->assertSame($isAnon ? $user->getName() : $creator->getName(), $entry->getPerformer()->getName()); $this->assertSame($user->getUserPage()->getFullText(), $entry->getTarget()->getFullText()); $this->assertSame(['4::userid' => $user->getId()], $entry->getParameters()); $this->assertSame($this->toString(), $entry->getComment()); }