~ubuntu-branches/ubuntu/trusty/mediawiki/trusty

« back to all changes in this revision

Viewing changes to tests/phpunit/includes/api/ApiBlockTest.php

  • Committer: Package Import Robot
  • Author(s): Thorsten Glaser
  • Date: 2014-03-28 09:56:29 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20140328095629-1526y9tchdd507id
Tags: 1:1.19.14+dfsg-1
* New upstream security fix release (Closes: #742857):
  - (bug 62497) SECURITY: Add CSRF token on Special:ChangePassword
  - (bug 62467) Set a title for the context during import on the cli
* Use upstream-provided signing key bundle

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * @group Database
 
5
 */
 
6
class ApiBlockTest extends ApiTestCase {
 
7
 
 
8
        function setUp() {
 
9
                parent::setUp();
 
10
                $this->doLogin();
 
11
        }
 
12
 
 
13
        function getTokens() {
 
14
                return $this->getTokenList( self::$users['sysop'] );
 
15
        }
 
16
 
 
17
        function addDBData() {
 
18
                $user = User::newFromName( 'UTApiBlockee' );
 
19
 
 
20
                if ( $user->getId() == 0 ) {
 
21
                        $user->addToDatabase();
 
22
                        $user->setPassword( 'UTApiBlockeePassword' );
 
23
 
 
24
                        $user->saveSettings();
 
25
                }
 
26
        }
 
27
 
 
28
        /**
 
29
         * This test has probably always been broken and use an invalid token
 
30
         * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
 
31
         *
 
32
         * Root cause is https://gerrit.wikimedia.org/r/3434
 
33
         * Which made the Block/Unblock API to actually verify the token
 
34
         * previously always considered valid (bug 34212).
 
35
         *
 
36
         * @group Broken
 
37
         */
 
38
        function testMakeNormalBlock() {
 
39
 
 
40
                $data = $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( !isset( $data[0]['query']['pages'] ) ) {
 
49
                        $this->markTestIncomplete( "No block token found" );
 
50
                }
 
51
 
 
52
                $keys = array_keys( $data[0]['query']['pages'] );
 
53
                $key = array_pop( $keys );
 
54
                $pageinfo = $data[0]['query']['pages'][$key];
 
55
 
 
56
                $data = $this->doApiRequest( array(
 
57
                        'action' => 'block',
 
58
                        'user' => 'UTApiBlockee',
 
59
                        'reason' => 'Some reason',
 
60
                        'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user );
 
61
 
 
62
                $block = Block::newFromTarget('UTApiBlockee');
 
63
 
 
64
                $this->assertTrue( !is_null( $block ), 'Block is valid' );
 
65
 
 
66
                $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
 
67
                $this->assertEquals( 'Some reason', $block->mReason );
 
68
                $this->assertEquals( 'infinity', $block->mExpiry );
 
69
 
 
70
        }
 
71
 
 
72
}