Merge "Remove use of BagOStuff TTL constants from unrelated code"
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryBlockInfoTraitTest.php
blob915da66575d0e0c3b1a9bd4f7426f45aef79f9b7
1 <?php
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;
13 /**
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' );
24 /**
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()
35 ->from( 'table' );
37 $mock = $this->getMockBuilder( ApiQueryBase::class )
38 ->disableOriginalConstructor()
39 ->onlyMethods( [
40 'getQueryBuilder',
41 'getDB',
42 'getAuthority'
43 ] )
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() {
56 return [
57 'unauthorized' => [
58 false,
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' ],
65 'options' => [],
66 'join_conds' => [],
69 'authorized' => [
70 true,
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' ],
76 'conds' => [],
77 'options' => [],
78 'join_conds' => []