65f84e8f120c4f2a76dfef7577027e599fb9ec67
3 require_once( 'PHPUnit.php' );
4 require_once( '../includes/Defines.php' );
5 require_once( '../includes/GlobalFunctions.php' );
7 class GlobalTest
extends PHPUnit_TestCase
{
8 function GlobalTest( $name ) {
9 $this->PHPUnit_TestCase( $name );
13 $this->save
= array();
14 $saveVars = array( 'wgReadOnlyFile' );
15 foreach( $saveVars as $var ) {
16 if( isset( $GLOBALS[$var] ) ) {
17 $this->save
[$var] = $GLOBALS[$var];
20 $GLOBALS['wgReadOnlyFile'] = '/tmp/testReadOnly-' . mt_rand();
24 foreach( $this->save
as $var => $data ) {
25 $GLOBALS[$var] = $data;
29 function testDecodeLatin() {
32 do_html_entity_decode( 'école', ENT_COMPAT
, 'iso-8859-1' ) );
35 function testDecodeUnicode() {
38 do_html_entity_decode( 'école', ENT_COMPAT
, 'utf-8' ) );
41 function testRandom() {
42 # This could hypothetically fail, but it shouldn't ;)
44 wfRandom() == wfRandom() );
47 function testUrlencode() {
49 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
50 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
53 function testUtf8Sequence1() {
56 wfUtf8Sequence( 65 ) );
59 function testUtf8Sequence2() {
62 wfUtf8Sequence( 0x108 ) );
65 function testUtf8Sequence3() {
68 wfUtf8Sequence( 0x304b ) );
71 function testUtf8Sequence4() {
74 wfUtf8Sequence( 0x10450 ) );
77 function testMungeToUtf8() {
79 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
80 wfMungeToUtf8( "Ĉio bonas dans l'école!" ) );
83 function testUtf8ToHTML() {
85 "Ĉio bonas dans l'école!",
86 wfUtf8ToHTML( "\xc4\x88io bonas dans l'\xc3\xa9cole!" ) );
89 function testReadOnlyEmpty() {
90 $this->assertFalse( wfReadOnly() );
93 function testReadOnlySet() {
94 $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
95 fwrite( $f, 'Message' );
97 $this->assertTrue( wfReadOnly() );
99 unlink( $GLOBALS['wgReadOnlyFile'] );
100 $this->assertFalse( wfReadOnly() );
103 function testQuotedPrintable() {
105 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
106 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
109 function testTime() {
111 $this->assertType( 'double', $start );
113 $this->assertTrue( $end > $start, "Time is running backwards!" );
116 function testArrayToCGI() {
118 "baz=AT%26T&foo=bar",
120 array( 'baz' => 'AT&T', 'ignore' => '' ),
121 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
124 /* TODO: many more! */