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

« back to all changes in this revision

Viewing changes to tests/phpunit/includes/TitleTest.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
class TitleTest extends MediaWikiTestCase {
 
4
 
 
5
        function testLegalChars() {
 
6
                $titlechars = Title::legalChars();
 
7
 
 
8
                foreach ( range( 1, 255 ) as $num ) {
 
9
                        $chr = chr( $num );
 
10
                        if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
 
11
                                $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
 
12
                        } else {
 
13
                                $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
 
14
                        }
 
15
                }
 
16
        }
 
17
 
 
18
        /**
 
19
         * @dataProvider dataBug31100
 
20
         */
 
21
        function testBug31100FixSpecialName( $text, $expectedParam ) {
 
22
                $title = Title::newFromText( $text );
 
23
                $fixed = $title->fixSpecialName();
 
24
                $stuff = explode( '/', $fixed->getDbKey(), 2 );
 
25
                if ( count( $stuff ) == 2 ) {
 
26
                        $par = $stuff[1];
 
27
                } else {
 
28
                        $par = null;
 
29
                }
 
30
                $this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" );
 
31
        }
 
32
 
 
33
        function dataBug31100() {
 
34
                return array(
 
35
                        array( 'Special:Version', null ),
 
36
                        array( 'Special:Version/', '' ),
 
37
                        array( 'Special:Version/param', 'param' ),
 
38
                );
 
39
        }
 
40
        
 
41
        /**
 
42
         * Auth-less test of Title::isValidMoveOperation
 
43
         * 
 
44
         * @group Database
 
45
         * @param string $source
 
46
         * @param string $target
 
47
         * @param array|string|true $expected Required error
 
48
         * @dataProvider dataTestIsValidMoveOperation
 
49
         */
 
50
        function testIsValidMoveOperation( $source, $target, $expected ) {
 
51
                $title = Title::newFromText( $source );
 
52
                $nt = Title::newFromText( $target );
 
53
                $errors = $title->isValidMoveOperation( $nt, false );
 
54
                if ( $expected === true ) {
 
55
                        $this->assertTrue( $errors );
 
56
                } else {
 
57
                        $errors = $this->flattenErrorsArray( $errors );
 
58
                        foreach ( (array)$expected as $error ) {
 
59
                                $this->assertContains( $error, $errors );
 
60
                        }
 
61
                }
 
62
        }
 
63
        
 
64
        function flattenErrorsArray( $errors ) {
 
65
                $result = array();
 
66
                foreach ( $errors as $error ) {
 
67
                        $result[] = $error[0];
 
68
                }
 
69
                return $result;
 
70
        }
 
71
        
 
72
        function dataTestIsValidMoveOperation() {
 
73
                return array( 
 
74
                        array( 'Test', 'Test', 'selfmove' ),
 
75
                        array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
 
76
                );
 
77
        }
 
78
        
 
79
        
 
80
}