aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Sarabadani <ladsgroup@gmail.com>2023-07-14 14:37:00 +0200
committerAmir Sarabadani <ladsgroup@gmail.com>2023-07-14 15:40:11 +0200
commit77342327ee23b4c02ddb1baa1fcdf0aa31862a2c (patch)
tree69180419370511b5faab86db3082f2972b58bb6a
parent5551326fa05cdff429cde8b048b0ec9973c4e9bd (diff)
downloadmediawikicore-77342327ee23b4c02ddb1baa1fcdf0aa31862a2c.tar.gz
mediawikicore-77342327ee23b4c02ddb1baa1fcdf0aa31862a2c.zip
tests: Migrate calls to Database::update to UpdateQueryBuilder
Bug: T330640 Change-Id: I30f9e84658fbd996b5512e96dda3f6412ebf3a20
-rw-r--r--tests/phpunit/includes/EditPageConstraintsTest.php25
-rw-r--r--tests/phpunit/includes/EditPageTest.php8
-rw-r--r--tests/phpunit/includes/api/ApiEditPageTest.php35
-rw-r--r--tests/phpunit/includes/api/ApiStashEditTest.php11
-rw-r--r--tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php96
-rw-r--r--tests/phpunit/includes/filerepo/file/LocalFileTest.php7
-rw-r--r--tests/phpunit/includes/specials/SpecialRecentchangesTest.php11
-rw-r--r--tests/phpunit/includes/user/BotPasswordTest.php11
8 files changed, 103 insertions, 101 deletions
diff --git a/tests/phpunit/includes/EditPageConstraintsTest.php b/tests/phpunit/includes/EditPageConstraintsTest.php
index f99963f67986..476a44c843a4 100644
--- a/tests/phpunit/includes/EditPageConstraintsTest.php
+++ b/tests/phpunit/includes/EditPageConstraintsTest.php
@@ -89,11 +89,11 @@ class EditPageConstraintsTest extends MediaWikiLangTestCase {
// Set the latest timestamp back a while
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'revision',
- [ 'rev_timestamp' => $dbw->timestamp( '20120101000000' ) ],
- [ 'rev_id' => $page->getLatest() ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'revision' )
+ ->set( [ 'rev_timestamp' => $dbw->timestamp( '20120101000000' ) ] )
+ ->where( [ 'rev_id' => $page->getLatest() ] )
+ ->execute();
$page->clear();
$content = $page->getContent();
@@ -167,17 +167,16 @@ class EditPageConstraintsTest extends MediaWikiLangTestCase {
// edit before it. Since the constraint will query for the most recent timestamp,
// update *all* deletion logs for the page to the same timestamp (1 January 2020)
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'logging',
- [ 'log_timestamp' => $dbw->timestamp( '20200101000000' ) ],
- [
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'logging' )
+ ->set( [ 'log_timestamp' => $dbw->timestamp( '20200101000000' ) ] )
+ ->where( [
'log_namespace' => $title->getNamespace(),
'log_title' => $title->getDBkey(),
'log_type' => 'delete',
- 'log_action' => 'delete'
- ],
- __METHOD__
- );
+ 'log_action' => 'delete',
+ ] )
+ ->caller( __METHOD__ )->execute();
$user = $this->getTestUser()->getUser();
diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php
index 1e5acb02f7cd..7447582a0469 100644
--- a/tests/phpunit/includes/EditPageTest.php
+++ b/tests/phpunit/includes/EditPageTest.php
@@ -74,9 +74,11 @@ class EditPageTest extends MediaWikiLangTestCase {
protected function forceRevisionDate( WikiPage $page, $timestamp ) {
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update( 'revision',
- [ 'rev_timestamp' => $dbw->timestamp( $timestamp ) ],
- [ 'rev_id' => $page->getLatest() ] );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'revision' )
+ ->set( [ 'rev_timestamp' => $dbw->timestamp( $timestamp ) ] )
+ ->where( [ 'rev_id' => $page->getLatest() ] )
+ ->execute();
$page->clear();
}
diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php
index 3cb94a3ac712..dcdbbac68aab 100644
--- a/tests/phpunit/includes/api/ApiEditPageTest.php
+++ b/tests/phpunit/includes/api/ApiEditPageTest.php
@@ -696,11 +696,13 @@ class ApiEditPageTest extends ApiTestCase {
* @param string|int $timestamp
*/
protected function forceRevisionDate( WikiPage $page, $timestamp ) {
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
- $dbw->update( 'revision',
- [ 'rev_timestamp' => $dbw->timestamp( $timestamp ) ],
- [ 'rev_id' => $page->getLatest() ] );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'revision' )
+ ->set( [ 'rev_timestamp' => $dbw->timestamp( $timestamp ) ] )
+ ->where( [ 'rev_id' => $page->getLatest() ] )
+ ->caller( __METHOD__ )->execute();
$page->clear();
}
@@ -887,13 +889,16 @@ class ApiEditPageTest extends ApiTestCase {
$revId3 = $this->editPage( $page, '3' )->getNewRevision()->getId();
// Make the middle revision disappear
- $dbw = wfGetDB( DB_PRIMARY );
+ $dbw = $this->getDb();
$dbw->newDeleteQueryBuilder()
->delete( 'revision' )
->where( [ 'rev_id' => $revId2 ] )
->caller( __METHOD__ )->execute();
- $dbw->update( 'revision', [ 'rev_parent_id' => $revId1 ],
- [ 'rev_id' => $revId3 ], __METHOD__ );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'revision' )
+ ->set( [ 'rev_parent_id' => $revId1 ] )
+ ->where( [ 'rev_id' => $revId3 ] )
+ ->caller( __METHOD__ )->execute();
$this->expectApiErrorCode( 'nosuchrevid' );
@@ -954,13 +959,12 @@ class ApiEditPageTest extends ApiTestCase {
$revId1 = $this->editPage( $page, '1' )->getNewRevision()->getId();
// Now monkey with the timestamp
- $dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'revision',
- [ 'rev_timestamp' => $dbw->timestamp( time() - 86400 ) ],
- [ 'rev_id' => $revId1 ],
- __METHOD__
- );
+ $dbw = $this->getDb();
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'revision' )
+ ->set( [ 'rev_timestamp' => $dbw->timestamp( time() - 86400 ) ] )
+ ->where( [ 'rev_id' => $revId1 ] )
+ ->caller( __METHOD__ )->execute();
$this->doApiRequestWithToken( [
'action' => 'edit',
@@ -1565,8 +1569,7 @@ class ApiEditPageTest extends ApiTestCase {
'tags' => 'custom tag',
] )[0]['edit']['newrevid'];
- $dbw = wfGetDB( DB_PRIMARY );
- $this->assertSame( 'custom tag', $dbw->selectField(
+ $this->assertSame( 'custom tag', $this->getDb()->selectField(
[ 'change_tag', 'change_tag_def' ],
'ctd_name',
[ 'ct_rev_id' => $revId ],
diff --git a/tests/phpunit/includes/api/ApiStashEditTest.php b/tests/phpunit/includes/api/ApiStashEditTest.php
index 274bc88bfd2d..de8a0ac964bc 100644
--- a/tests/phpunit/includes/api/ApiStashEditTest.php
+++ b/tests/phpunit/includes/api/ApiStashEditTest.php
@@ -193,12 +193,11 @@ class ApiStashEditTest extends ApiTestCase {
// Corrupt the database. @todo Does the API really need to fail gracefully for this case?
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'page',
- [ 'page_latest' => 0 ],
- [ 'page_id' => $revRecord->getPageId() ],
- __METHOD__
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'page' )
+ ->set( [ 'page_latest' => 0 ] )
+ ->where( [ 'page_id' => $revRecord->getPageId() ] )
+ ->caller( __METHOD__ )->execute();
$this->doStash( [ 'title' => $name, 'baserevid' => $revRecord->getId() ] );
}
diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
index cf7f74bbe4b0..4d051c355f2b 100644
--- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
@@ -177,48 +177,42 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$this->assertFalse( $provider->testUserCanAuthenticate( '<invalid>' ) );
$this->assertFalse( $provider->testUserCanAuthenticate( 'DoesNotExist' ) );
- $dbw->update(
- 'user',
- [
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [
'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
'user_newpass_time' => null,
- ],
- [ 'user_id' => $user->getId() ]
- );
+ ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
$this->assertFalse( $provider->testUserCanAuthenticate( $user->getName() ) );
- $dbw->update(
- 'user',
- [
- 'user_newpassword' => $pwhash,
- 'user_newpass_time' => null,
- ],
- [ 'user_id' => $user->getId() ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpassword' => $pwhash, 'user_newpass_time' => null, ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
$this->assertTrue( $provider->testUserCanAuthenticate( $user->getName() ) );
$this->assertTrue( $provider->testUserCanAuthenticate( lcfirst( $user->getName() ) ) );
- $dbw->update(
- 'user',
- [
- 'user_newpassword' => $pwhash,
- 'user_newpass_time' => $dbw->timestamp( time() - 10 ),
- ],
- [ 'user_id' => $user->getId() ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpassword' => $pwhash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
$providerPriv->newPasswordExpiry = 100;
$this->assertTrue( $provider->testUserCanAuthenticate( $user->getName() ) );
$providerPriv->newPasswordExpiry = 1;
$this->assertFalse( $provider->testUserCanAuthenticate( $user->getName() ) );
- $dbw->update(
- 'user',
- [
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [
'user_newpassword' => \PasswordFactory::newInvalidPassword()->toString(),
'user_newpass_time' => null,
- ],
- [ 'user_id' => $user->getId() ]
- );
+ ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
}
/**
@@ -276,11 +270,11 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$password = 'TemporaryPassword';
$hash = ':A:' . md5( $password );
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'user',
- [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ],
- [ 'user_id' => $user->getId() ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() - 10 ) ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
$req = new PasswordAuthenticationRequest();
$req->action = AuthManager::ACTION_LOGIN;
@@ -454,15 +448,19 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$dbw = wfGetDB( DB_PRIMARY );
$oldHash = $dbw->selectField( 'user', 'user_newpassword', [ 'user_name' => $cuser ] );
$cb = new ScopedCallback( static function () use ( $dbw, $cuser, $oldHash ) {
- $dbw->update( 'user', [ 'user_newpassword' => $oldHash ], [ 'user_name' => $cuser ] );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpassword' => $oldHash ] )
+ ->where( [ 'user_name' => $cuser ] )
+ ->execute();
} );
$hash = ':A:' . md5( $oldpass );
- $dbw->update(
- 'user',
- [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() + 10 ) ],
- [ 'user_name' => $cuser ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpassword' => $hash, 'user_newpass_time' => $dbw->timestamp( time() + 10 ) ] )
+ ->where( [ 'user_name' => $cuser ] )
+ ->execute();
$provider = $this->getProvider();
@@ -543,11 +541,11 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$user = self::getMutableTestUser()->getUser();
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'user',
- [ 'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ],
- [ 'user_id' => $user->getId() ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpass_time' => $dbw->timestamp( time() - 5 * 3600 ) ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
$req = TemporaryPasswordAuthenticationRequest::newRandom();
$req->username = $user->getName();
@@ -569,11 +567,11 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiInteg
$status = $provider->providerAllowsAuthenticationDataChange( $req, true );
$this->assertFalse( $status->hasMessage( 'throttled-mailpassword' ) );
- $dbw->update(
- 'user',
- [ 'user_newpass_time' => $dbw->timestamp( time() + 5 * 3600 ) ],
- [ 'user_id' => $user->getId() ]
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'user' )
+ ->set( [ 'user_newpass_time' => $dbw->timestamp( time() + 5 * 3600 ) ] )
+ ->where( [ 'user_id' => $user->getId() ] )
+ ->execute();
$provider = $this->getProvider( [
'emailEnabled' => true, 'passwordReminderResendTime' => 0
] );
diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
index 1e5348c4f393..2f1d68cefa43 100644
--- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php
+++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php
@@ -636,8 +636,11 @@ class LocalFileTest extends MediaWikiIntegrationTestCase {
// Test cache by corrupting DB
// Don't wipe img_metadata though since that will be loaded by loadExtraFromDB()
- $dbw->update( 'image', [ 'img_size' => 0 ],
- [ 'img_name' => 'Random-11m.png' ], __METHOD__ );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'image' )
+ ->set( [ 'img_size' => 0 ] )
+ ->where( [ 'img_name' => 'Random-11m.png' ] )
+ ->caller( __METHOD__ )->execute();
$file = LocalFile::newFromTitle( $title, $repo );
$this->assertFileProperties( $expectedProps, $file );
diff --git a/tests/phpunit/includes/specials/SpecialRecentchangesTest.php b/tests/phpunit/includes/specials/SpecialRecentchangesTest.php
index d5f51983b7ff..136b7f5cae8d 100644
--- a/tests/phpunit/includes/specials/SpecialRecentchangesTest.php
+++ b/tests/phpunit/includes/specials/SpecialRecentchangesTest.php
@@ -98,12 +98,11 @@ class SpecialRecentchangesTest extends AbstractChangesListSpecialPageTestCase {
$db = wfGetDB( DB_PRIMARY );
$queryConds = [ 'wl_namespace' => $testPage->getNamespace(), 'wl_title' => $testPage->getDBkey() ];
$watchedItemId = $db->selectField( 'watchlist', 'wl_id', $queryConds, __METHOD__ );
- $db->update(
- 'watchlist_expiry',
- [ 'we_expiry' => $db->timestamp( '20200101000000' ) ],
- [ 'we_item' => $watchedItemId ],
- __METHOD__
- );
+ $db->newUpdateQueryBuilder()
+ ->update( 'watchlist_expiry' )
+ ->set( [ 'we_expiry' => $db->timestamp( '20200101000000' ) ] )
+ ->where( [ 'we_item' => $watchedItemId ] )
+ ->caller( __METHOD__ )->execute();
// Check that the page is still in RC, but that it's no longer watched.
$rc3 = $this->getPage();
diff --git a/tests/phpunit/includes/user/BotPasswordTest.php b/tests/phpunit/includes/user/BotPasswordTest.php
index db89b9af0b5b..822bb84e6c24 100644
--- a/tests/phpunit/includes/user/BotPasswordTest.php
+++ b/tests/phpunit/includes/user/BotPasswordTest.php
@@ -190,12 +190,11 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase {
$bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
$dbw = wfGetDB( DB_PRIMARY );
- $dbw->update(
- 'bot_passwords',
- [ 'bp_password' => 'garbage' ],
- [ 'bp_user' => 42, 'bp_app_id' => 'BotPassword' ],
- __METHOD__
- );
+ $dbw->newUpdateQueryBuilder()
+ ->update( 'bot_passwords' )
+ ->set( [ 'bp_password' => 'garbage' ] )
+ ->where( [ 'bp_user' => 42, 'bp_app_id' => 'BotPassword' ] )
+ ->caller( __METHOD__ )->execute();
$password = $bp->getPassword();
$this->assertInstanceOf( InvalidPassword::class, $password );
}