TestUser creates the user and therefore needs the database. Avoid using
it in non-database tests.
Add ApiQueryBlockInfoTraitTest to the Database group because it needs
the database.
Add DeleteUserEmailTest to the Database group because since 3bedffa8
the default user is not created any more in non-database tests
Change-Id: Iff438964dde47a47a2fa4a314d55010bd8c7fee5
75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
use Wikimedia\Timestamp\ConvertibleTimestamp;
|
|
|
|
/**
|
|
* @covers ApiQueryBlockInfoTrait
|
|
* @group Database
|
|
*/
|
|
class ApiQueryBlockInfoTraitTest extends MediaWikiIntegrationTestCase {
|
|
|
|
public function testUsesApiBlockInfoTrait() {
|
|
$this->assertTrue( method_exists( ApiQueryBlockInfoTrait::class, 'getBlockDetails' ),
|
|
'ApiQueryBlockInfoTrait::getBlockDetails exists' );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideAddBlockInfoToQuery
|
|
*/
|
|
public function testAddBlockInfoToQuery( $args, $expect ) {
|
|
// Fake timestamp to show up in the queries
|
|
$reset = ConvertibleTimestamp::setFakeTime( '20190101000000' );
|
|
|
|
$data = [];
|
|
|
|
$mock = $this->getMockForTrait( ApiQueryBlockInfoTrait::class );
|
|
$mock->method( 'getDB' )->willReturn( wfGetDB( DB_REPLICA ) );
|
|
$mock->method( 'getAuthority' )
|
|
->willReturn( $this->getMutableTestUser()->getUser() );
|
|
$mock->method( 'addTables' )->willReturnCallback( static function ( $v ) use ( &$data ) {
|
|
$data['tables'] = array_merge( $data['tables'] ?? [], (array)$v );
|
|
} );
|
|
$mock->method( 'addFields' )->willReturnCallback( static function ( $v ) use ( &$data ) {
|
|
$data['fields'] = array_merge( $data['fields'] ?? [], (array)$v );
|
|
} );
|
|
$mock->method( 'addWhere' )->willReturnCallback( static function ( $v ) use ( &$data ) {
|
|
$data['where'] = array_merge( $data['where'] ?? [], (array)$v );
|
|
} );
|
|
$mock->method( 'addJoinConds' )->willReturnCallback( static function ( $v ) use ( &$data ) {
|
|
$data['joins'] = array_merge( $data['joins'] ?? [], (array)$v );
|
|
} );
|
|
|
|
TestingAccessWrapper::newFromObject( $mock )->addBlockInfoToQuery( ...$args );
|
|
$this->assertEquals( $expect, $data );
|
|
}
|
|
|
|
public static function provideAddBlockInfoToQuery() {
|
|
$queryInfo = DatabaseBlock::getQueryInfo();
|
|
|
|
$db = wfGetDB( DB_REPLICA );
|
|
$ts = $db->addQuotes( $db->timestamp( '20190101000000' ) );
|
|
|
|
return [
|
|
[ [ false ], [
|
|
'tables' => [ 'blk' => [ 'ipblocks' ] ],
|
|
'fields' => [ 'ipb_deleted' ],
|
|
'where' => [ 'ipb_deleted' => [ 0, null ] ],
|
|
'joins' => [
|
|
'blk' => [ 'LEFT JOIN', [ 'ipb_user=user_id', "ipb_expiry > $ts" ] ]
|
|
],
|
|
] ],
|
|
|
|
[ [ true ], [
|
|
'tables' => [ 'blk' => $queryInfo['tables'] ],
|
|
'fields' => $queryInfo['fields'],
|
|
'where' => [ 'ipb_deleted' => [ 0, null ] ],
|
|
'joins' => $queryInfo['joins'] + [
|
|
'blk' => [ 'LEFT JOIN', [ 'ipb_user=user_id', "ipb_expiry > $ts" ] ]
|
|
],
|
|
] ],
|
|
];
|
|
}
|
|
|
|
}
|