Fix 12384 : comment on maintenance/*php files
[lhc/web/wiklou.git] / t / inc / Database.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 'LocalSettings.php';
9
10 plan( 13 );
11
12 require_ok( 'includes/ProfilerStub.php' );
13 require_ok( 'includes/GlobalFunctions.php' );
14 require_ok( 'includes/Exception.php' );
15 require_ok( 'includes/Database.php' );
16
17 $db = new Database( $wgDBserver, $wgDBuser, $wgDBpassword );
18
19 cmp_ok( $db->addQuotes( NULL ), '==',
20 'NULL', 'Add quotes to NULL' );
21
22 cmp_ok( $db->addQuotes( 1234 ), '==',
23 "'1234'", 'Add quotes to int' );
24
25 cmp_ok( $db->addQuotes( 1234.5678 ), '==',
26 "'1234.5678'", 'Add quotes to float' );
27
28 cmp_ok( $db->addQuotes( 'string' ), '==',
29 "'string'", 'Add quotes to string' );
30
31 cmp_ok( $db->addQuotes( "string's cause trouble" ), '==',
32 "'string\'s cause trouble'", 'Add quotes to quoted string' );
33
34 $sql = $db->fillPrepared(
35 'SELECT * FROM interwiki', array() );
36 cmp_ok( $sql, '==',
37 'SELECT * FROM interwiki', 'FillPrepared empty' );
38
39 $sql = $db->fillPrepared(
40 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
41 array( 4, "Snicker's_paradox" ) );
42 cmp_ok( $sql, '==',
43 "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'", 'FillPrepared question' );
44
45 $sql = $db->fillPrepared(
46 'SELECT user_id FROM ! WHERE user_name=?',
47 array( '"user"', "Slash's Dot" ) );
48 cmp_ok( $sql, '==',
49 "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'", 'FillPrepared quoted' );
50
51 $sql = $db->fillPrepared(
52 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
53 array( '"user"', "Slash's Dot" ) );
54 cmp_ok( $sql, '==',
55 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'", 'FillPrepared raw' );