3 namespace MediaWiki\Tests\Api\Query
;
5 use MediaWiki\Api\ApiQueryBase
;
6 use MediaWiki\Api\ApiQueryBlockInfoTrait
;
7 use MediaWiki\Tests\MockDatabase
;
8 use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait
;
9 use MediaWikiIntegrationTestCase
;
10 use Wikimedia\TestingAccessWrapper
;
11 use Wikimedia\Timestamp\ConvertibleTimestamp
;
14 * @covers \MediaWiki\Api\ApiQueryBlockInfoTrait
16 class ApiQueryBlockInfoTraitTest
extends MediaWikiIntegrationTestCase
{
17 use MockAuthorityTrait
;
19 public function testUsesApiBlockInfoTrait() {
20 $this->assertTrue( method_exists( ApiQueryBlockInfoTrait
::class, 'getBlockDetails' ),
21 'ApiQueryBlockInfoTrait::getBlockDetails exists' );
25 * @dataProvider provideAddDeletedUserFilter
27 public function testAddDeletedUserFilter( $isAllowed, $expect ) {
28 // Fake timestamp to show up in the queries
29 ConvertibleTimestamp
::setFakeTime( '20190101000000' );
31 $authority = $this->mockRegisteredAuthorityWithPermissions(
32 $isAllowed ?
[ 'hideuser' ] : [] );
33 $db = new MockDatabase
;
34 $queryBuilder = $db->newSelectQueryBuilder()
37 $mock = $this->getMockBuilder( ApiQueryBase
::class )
38 ->disableOriginalConstructor()
44 ->getMockForAbstractClass();
46 $mock->method( 'getQueryBuilder' )->willReturn( $queryBuilder );
47 $mock->method( 'getDB' )->willReturn( new MockDatabase
);
48 $mock->method( 'getAuthority' )->willReturn( $authority );
50 TestingAccessWrapper
::newFromObject( $mock )->addDeletedUserFilter();
51 $data = $queryBuilder->getQueryInfo();
52 $this->assertSame( $expect, $data );
55 public static function provideAddDeletedUserFilter() {
60 'tables' => [ 'table' ],
61 'fields' => [ 'hu_deleted' => '1=0' ],
62 'conds' => [ '(SELECT 1 FROM "block_target" "hu_block_target" ' .
63 'JOIN "block" "hu_block" ON ((hu_block.bl_target=hu_block_target.bt_id)) ' .
64 'WHERE (hu_block_target.bt_user=user_id) AND hu_block.bl_deleted = 1 ) IS NULL' ],
72 'tables' => [ 'table' ],
73 'fields' => [ 'hu_deleted' => '(SELECT 1 FROM "block_target" "hu_block_target" ' .
74 'JOIN "block" "hu_block" ON ((hu_block.bl_target=hu_block_target.bt_id)) ' .
75 'WHERE (hu_block_target.bt_user=user_id) AND hu_block.bl_deleted = 1 ) IS NOT NULL' ],