]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - t/inc/Global.t
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / t / inc / Global.t
1 #!/usr/bin/env php
2 <?php
3
4 define( 'MEDIAWIKI', true );
5 require 't/Test.php';
6
7 require 'includes/Defines.php';
8 require 'StartProfiler.php';
9 require 'includes/AutoLoader.php';
10 require 'LocalSettings.php';
11 require 'includes/Setup.php';
12
13 plan( 46 );
14
15 $wgReadOnly = null;
16 $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
17 unlink( $wgReadOnlyFile );
18
19 isnt( wfRandom(), wfRandom(), "Two differents random" );
20
21 is( wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ),
22         "%E7%89%B9%E5%88%A5:Contributions/Foobar", 'Urlencode' );
23
24 is( wfReadOnly(), false, 'Empty read only' );
25
26 is( wfReadOnly(), false, 'Empty read only, second time' );
27
28 $f = fopen( $wgReadOnlyFile, "wt" );
29 fwrite( $f, 'Message' );
30 fclose( $f );
31 $wgReadOnly = null;
32
33 is( wfReadOnly(), true, 'Read only file set' );
34
35 is( wfReadOnly(), true, 'Read only file set, second time' );
36
37 unlink( $wgReadOnlyFile );
38 $wgReadOnly = null;
39
40 is( wfReadOnly(), false, 'Read only reset' );
41
42 is( wfReadOnly(), false, 'Read only reset, second time' );
43
44
45 is( wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ), 
46         "=?UTF-8?Q?=C4=88u=20legebla=3F?=", 'Quoted printable' );
47
48 $start = wfTime();
49 is( gettype( $start ), 'float', 'Time (type)' );
50 $end = wfTime();
51 cmp_ok( $end, '>', $start, 'Time (compare)' );
52
53 $arr = wfArrayToCGI(
54         array( 'baz' => 'AT&T', 'ignore' => '' ),
55         array( 'foo' => 'bar', 'baz' => 'overridden value' ) );
56 is( $arr, "baz=AT%26T&foo=bar", 'Array to CGI' );
57
58 $mime = mimeTypeMatch( 'text/html', array(
59         'application/xhtml+xml' => 1.0,
60         'text/html'  => 0.7,
61         'text/plain' => 0.3
62 ) );
63 is( $mime, 'text/html', 'Mime (1)' );
64
65 $mime = mimeTypeMatch( 'text/html', array(
66         'image/*' => 1.0,
67         'text/*'  => 0.5
68 ) );
69 is( $mime, 'text/*', 'Mime (2)' );
70
71 $mime = mimeTypeMatch( 'text/html', array( '*/*' => 1.0 ) );
72 is( $mime, '*/*', 'Mime (3)' );
73
74 $mime = mimeTypeMatch( 'text/html', array(
75         'image/png'     => 1.0,
76         'image/svg+xml' => 0.5
77 ) );
78 is( $mime, null, 'Mime (4)' );
79
80 $mime = wfNegotiateType(
81         array( 'application/xhtml+xml' => 1.0,
82                'text/html'             => 0.7,
83                'text/plain'            => 0.5,
84                'text/*'                => 0.2 ),
85         array( 'text/html'             => 1.0 ) );
86 is( $mime, 'text/html', 'Negotiate Mime (1)' );
87
88 $mime = wfNegotiateType(
89         array( 'application/xhtml+xml' => 1.0,
90                'text/html'             => 0.7,
91                'text/plain'            => 0.5,
92                'text/*'                => 0.2 ),
93         array( 'application/xhtml+xml' => 1.0,
94                'text/html'             => 0.5 ) );
95 is( $mime, 'application/xhtml+xml', 'Negotiate Mime (2)' );
96
97 $mime = wfNegotiateType(
98         array( 'text/html'             => 1.0,
99                'text/plain'            => 0.5,
100                'text/*'                => 0.5,
101                'application/xhtml+xml' => 0.2 ),
102         array( 'application/xhtml+xml' => 1.0,
103                'text/html'             => 0.5 ) );
104 is( $mime, 'text/html', 'Negotiate Mime (3)' );
105
106 $mime = wfNegotiateType(
107         array( 'text/*'                => 1.0,
108                'image/*'               => 0.7,
109                '*/*'                   => 0.3 ),
110         array( 'application/xhtml+xml' => 1.0,
111                'text/html'             => 0.5 ) );
112 is( $mime, 'text/html', 'Negotiate Mime (4)' );
113
114 $mime = wfNegotiateType(
115         array( 'text/*'                => 1.0 ),
116         array( 'application/xhtml+xml' => 1.0 ) );
117 is( $mime, null, 'Negotiate Mime (5)' );
118
119 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
120 is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_UNIX to TS_MW' );
121 is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_UNIX to TS_UNIX' );
122 is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_UNIX to TS_DB' );
123 $t = '20010115123456';
124 is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_MW to TS_MW' );
125 is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_MW to TS_UNIX' );
126 is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_MW to TS_DB' );
127 $t = '2001-01-15 12:34:56';
128 is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_DB to TS_MW' );
129 is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_DB to TS_UNIX' );
130 is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_DB to TS_DB' );
131
132 $sets = array(
133         '' => '',
134         '/' => '',
135         '\\' => '',
136         '//' => '',
137         '\\\\' => '',
138         'a' => 'a',
139         'aaaa' => 'aaaa',
140         '/a' => 'a',
141         '\\a' => 'a',
142         '/aaaa' => 'aaaa',
143         '\\aaaa' => 'aaaa',
144         '/aaaa/' => 'aaaa',
145         '\\aaaa\\' => 'aaaa',
146         '\\aaaa\\' => 'aaaa',
147         '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
148         'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
149         'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
150 );
151 foreach( $sets as $from => $to ) {
152         is( $to, wfBaseName( $from ),
153                 "wfBaseName('$from') => '$to'");
154 }