Merge "tests: Migrate Database::select usages to SelectQueryBuilder"
This commit is contained in:
commit
6853d8b390
6 changed files with 66 additions and 43 deletions
|
|
@ -210,12 +210,11 @@ class ApiBlockTest extends ApiTestCase {
|
|||
$res = $this->doBlock( [ 'expiry' => '1 day' ] );
|
||||
|
||||
$dbw = wfGetDB( DB_PRIMARY );
|
||||
$expiry = $dbw->selectField(
|
||||
'ipblocks',
|
||||
'ipb_expiry',
|
||||
[ 'ipb_id' => $res[0]['block']['id'] ],
|
||||
__METHOD__
|
||||
);
|
||||
$expiry = $dbw->newSelectQueryBuilder()
|
||||
->select( 'ipb_expiry' )
|
||||
->from( 'ipblocks' )
|
||||
->where( [ 'ipb_id' => $res[0]['block']['id'] ] )
|
||||
->caller( __METHOD__ )->fetchField();
|
||||
|
||||
$this->assertSame( (int)wfTimestamp( TS_UNIX, $expiry ), $fakeTime + 86400 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,11 +225,11 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
|
|||
] );
|
||||
|
||||
$db = wfGetDB( DB_REPLICA );
|
||||
$result = $db->select(
|
||||
[ 'ipblocks_restrictions' ],
|
||||
[ '*' ],
|
||||
[ 'ir_ipb_id' => $block->getId() ]
|
||||
);
|
||||
$result = $db->newSelectQueryBuilder()
|
||||
->select( [ '*' ] )
|
||||
->from( 'ipblocks_restrictions' )
|
||||
->where( [ 'ir_ipb_id' => $block->getId() ] )
|
||||
->fetchResultSet();
|
||||
|
||||
$this->assertEquals( 2, $result->numRows() );
|
||||
$row = $result->fetchObject();
|
||||
|
|
@ -251,11 +251,11 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
|
|||
] );
|
||||
|
||||
$db = wfGetDB( DB_REPLICA );
|
||||
$result = $db->select(
|
||||
[ 'ipblocks_restrictions' ],
|
||||
[ '*' ],
|
||||
[ 'ir_ipb_id' => $block->getId() ]
|
||||
);
|
||||
$result = $db->newSelectQueryBuilder()
|
||||
->select( [ '*' ] )
|
||||
->from( 'ipblocks_restrictions' )
|
||||
->where( [ 'ir_ipb_id' => $block->getId() ] )
|
||||
->fetchResultSet();
|
||||
|
||||
$this->assertSame( 1, $result->numRows() );
|
||||
$row = $result->fetchObject();
|
||||
|
|
@ -274,11 +274,11 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
|
|||
$this->blockRestrictionStore->update( [] );
|
||||
|
||||
$db = wfGetDB( DB_REPLICA );
|
||||
$result = $db->select(
|
||||
[ 'ipblocks_restrictions' ],
|
||||
[ '*' ],
|
||||
[ 'ir_ipb_id' => $block->getId() ]
|
||||
);
|
||||
$result = $db->newSelectQueryBuilder()
|
||||
->select( [ '*' ] )
|
||||
->from( 'ipblocks_restrictions' )
|
||||
->where( [ 'ir_ipb_id' => $block->getId() ] )
|
||||
->fetchResultSet();
|
||||
|
||||
$this->assertSame( 0, $result->numRows() );
|
||||
}
|
||||
|
|
@ -300,11 +300,11 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase {
|
|||
] );
|
||||
|
||||
$db = wfGetDB( DB_REPLICA );
|
||||
$result = $db->select(
|
||||
[ 'ipblocks_restrictions' ],
|
||||
[ '*' ],
|
||||
[ 'ir_ipb_id' => $block->getId() ]
|
||||
);
|
||||
$result = $db->newSelectQueryBuilder()
|
||||
->select( [ '*' ] )
|
||||
->from( 'ipblocks_restrictions' )
|
||||
->where( [ 'ir_ipb_id' => $block->getId() ] )
|
||||
->fetchResultSet();
|
||||
|
||||
$this->assertSame( 1, $result->numRows() );
|
||||
$row = $result->fetchObject();
|
||||
|
|
|
|||
|
|
@ -26,14 +26,11 @@ class LinkTargetStoreTest extends MediaWikiIntegrationTestCase {
|
|||
$linkTargetStore = $this->getServiceContainer()->getLinkTargetLookup();
|
||||
$db = $this->getServiceContainer()->getDBLoadBalancer()->getConnection( DB_PRIMARY );
|
||||
$id = $linkTargetStore->acquireLinkTargetId( $target, $db );
|
||||
$row = $db->selectRow(
|
||||
'linktarget',
|
||||
[ 'lt_id', 'lt_namespace', 'lt_title' ],
|
||||
[
|
||||
'lt_namespace' => $target->getNamespace(),
|
||||
'lt_title' => $target->getDBkey()
|
||||
]
|
||||
);
|
||||
$row = $db->newSelectQueryBuilder()
|
||||
->select( [ 'lt_id','lt_namespace','lt_title' ] )
|
||||
->from( 'linktarget' )
|
||||
->where( [ 'lt_namespace' => $target->getNamespace(), 'lt_title' => $target->getDBkey() ] )
|
||||
->fetchRow();
|
||||
$this->assertSame( (int)$row->lt_id, $id );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -125,11 +125,19 @@ class PageArchiveTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertEquals( $this->ipEditor, $row->ar_user_text );
|
||||
|
||||
// Should not be in revision
|
||||
$row = $dbr->selectRow( 'revision', '1', [ 'rev_id' => $this->ipRev->getId() ] );
|
||||
$row = $dbr->newSelectQueryBuilder()
|
||||
->select( '1' )
|
||||
->from( 'revision' )
|
||||
->where( [ 'rev_id' => $this->ipRev->getId() ] )
|
||||
->fetchRow();
|
||||
$this->assertFalse( $row );
|
||||
|
||||
// Should not be in ip_changes
|
||||
$row = $dbr->selectRow( 'ip_changes', '1', [ 'ipc_rev_id' => $this->ipRev->getId() ] );
|
||||
$row = $dbr->newSelectQueryBuilder()
|
||||
->select( '1' )
|
||||
->from( 'ip_changes' )
|
||||
->where( [ 'ipc_rev_id' => $this->ipRev->getId() ] )
|
||||
->fetchRow();
|
||||
$this->assertFalse( $row );
|
||||
|
||||
// Restore the page
|
||||
|
|
@ -150,7 +158,11 @@ class PageArchiveTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertEquals( $this->ipEditor, $row->rev_user_text );
|
||||
|
||||
// Should be back in ip_changes
|
||||
$row = $dbr->selectRow( 'ip_changes', [ 'ipc_hex' ], [ 'ipc_rev_id' => $this->ipRev->getId() ] );
|
||||
$row = $dbr->newSelectQueryBuilder()
|
||||
->select( [ 'ipc_hex' ] )
|
||||
->from( 'ip_changes' )
|
||||
->where( [ 'ipc_rev_id' => $this->ipRev->getId() ] )
|
||||
->fetchRow();
|
||||
$this->assertNotFalse( $row, 'row exists in ip_changes table' );
|
||||
$this->assertEquals( IPUtils::toHex( $this->ipEditor ), $row->ipc_hex );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,11 +99,19 @@ class UndeletePageTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertEquals( $this->ipEditor, $row->ar_user_text );
|
||||
|
||||
// Should not be in revision
|
||||
$row = $dbr->selectRow( 'revision', '1', [ 'rev_id' => $this->pages[$key]['revId'] ] );
|
||||
$row = $dbr->newSelectQueryBuilder()
|
||||
->select( '1' )
|
||||
->from( 'revision' )
|
||||
->where( [ 'rev_id' => $this->pages[$key]['revId'] ] )
|
||||
->fetchRow();
|
||||
$this->assertFalse( $row );
|
||||
|
||||
// Should not be in ip_changes
|
||||
$row = $dbr->selectRow( 'ip_changes', '1', [ 'ipc_rev_id' => $this->pages[$key]['revId'] ] );
|
||||
$row = $dbr->newSelectQueryBuilder()
|
||||
->select( '1' )
|
||||
->from( 'ip_changes' )
|
||||
->where( [ 'ipc_rev_id' => $this->pages[$key]['revId'] ] )
|
||||
->fetchRow();
|
||||
$this->assertFalse( $row );
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +139,11 @@ class UndeletePageTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertEquals( $this->ipEditor, $row->rev_user_text );
|
||||
|
||||
// Should be back in ip_changes
|
||||
$row = $dbr->selectRow( 'ip_changes', [ 'ipc_hex' ], [ 'ipc_rev_id' => $this->pages[$key]['revId'] ] );
|
||||
$row = $dbr->newSelectQueryBuilder()
|
||||
->select( [ 'ipc_hex' ] )
|
||||
->from( 'ip_changes' )
|
||||
->where( [ 'ipc_rev_id' => $this->pages[$key]['revId'] ] )
|
||||
->fetchRow();
|
||||
$this->assertNotFalse( $row, 'row exists in ip_changes table' );
|
||||
$this->assertEquals( IPUtils::toHex( $this->ipEditor ), $row->ipc_hex );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,9 +95,12 @@ class SpecialRecentchangesTest extends AbstractChangesListSpecialPageTestCase {
|
|||
$this->assertStringContainsString( 'mw-changeslist-line-watched', $rc2->getOutput()->getHTML() );
|
||||
|
||||
// Force a past expiry date on the watchlist item.
|
||||
$db = wfGetDB( DB_PRIMARY );
|
||||
$queryConds = [ 'wl_namespace' => $testPage->getNamespace(), 'wl_title' => $testPage->getDBkey() ];
|
||||
$watchedItemId = $db->selectField( 'watchlist', 'wl_id', $queryConds, __METHOD__ );
|
||||
$db = $this->getDb();
|
||||
$watchedItemId = $db->newSelectQueryBuilder()
|
||||
->select( 'wl_id' )
|
||||
->from( 'watchlist' )
|
||||
->where( [ 'wl_namespace' => $testPage->getNamespace(), 'wl_title' => $testPage->getDBkey() ] )
|
||||
->caller( __METHOD__ )->fetchField();
|
||||
$db->newUpdateQueryBuilder()
|
||||
->update( 'watchlist_expiry' )
|
||||
->set( [ 'we_expiry' => $db->timestamp( '20200101000000' ) ] )
|
||||
|
|
|
|||
Loading…
Reference in a new issue