MediaWiki  1.27.2
ApiBlockTest.php
Go to the documentation of this file.
1 <?php
2 
10 class ApiBlockTest extends ApiTestCase {
11  protected function setUp() {
12  parent::setUp();
13  $this->doLogin();
14  }
15 
16  protected function getTokens() {
17  return $this->getTokenList( self::$users['sysop'] );
18  }
19 
20  function addDBDataOnce() {
21  $user = User::newFromName( 'UTApiBlockee' );
22 
23  if ( $user->getId() == 0 ) {
24  $user->addToDatabase();
25  TestUser::setPasswordForUser( $user, 'UTApiBlockeePassword' );
26 
27  $user->saveSettings();
28  }
29  }
30 
39  public function testMakeNormalBlock() {
40  $tokens = $this->getTokens();
41 
42  $user = User::newFromName( 'UTApiBlockee' );
43 
44  if ( !$user->getId() ) {
45  $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
46  }
47 
48  if ( !array_key_exists( 'blocktoken', $tokens ) ) {
49  $this->markTestIncomplete( "No block token found" );
50  }
51 
52  $this->doApiRequest( [
53  'action' => 'block',
54  'user' => 'UTApiBlockee',
55  'reason' => 'Some reason',
56  'token' => $tokens['blocktoken'] ], null, false, self::$users['sysop']->getUser() );
57 
58  $block = Block::newFromTarget( 'UTApiBlockee' );
59 
60  $this->assertTrue( !is_null( $block ), 'Block is valid' );
61 
62  $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
63  $this->assertEquals( 'Some reason', $block->mReason );
64  $this->assertEquals( 'infinity', $block->mExpiry );
65  }
66 
71  public function testBlockingActionWithNoToken() {
72  $this->doApiRequest(
73  [
74  'action' => 'block',
75  'user' => 'UTApiBlockee',
76  'reason' => 'Some reason',
77  ],
78  null,
79  false,
80  self::$users['sysop']->getUser()
81  );
82  }
83 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
testBlockingActionWithNoToken()
UsageException The token parameter must be set.
testMakeNormalBlock()
This test has probably always been broken and use an invalid token Bug tracking brokenness is https:/...
getTokenList($user, $session=null)
static setPasswordForUser(User $user, $password)
Set the password on a testing user.
Definition: TestUser.php:127
static newFromTarget($specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
Definition: Block.php:1077
$tokens
doLogin($user= 'sysop')
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:86
API Database medium.