summaryrefslogtreecommitdiff
path: root/t/inc/Database.t
blob: 4367fcd1121dfa4c4e5ed62c5557e0edd8a6cfeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env php
<?php

define( 'MEDIAWIKI', true );
require 't/Test.php';

require 'includes/Defines.php';
require 'StartProfiler.php';
require 'includes/AutoLoader.php';
require 'LocalSettings.php';
require 'includes/Setup.php';

plan( 9 );

$db = new Database( $wgDBserver, $wgDBuser, $wgDBpassword );

cmp_ok( $db->addQuotes( NULL ), '==',
	'NULL', 'Add quotes to NULL' );

cmp_ok( $db->addQuotes( 1234 ), '==',
	"'1234'", 'Add quotes to int' );

cmp_ok( $db->addQuotes( 1234.5678 ), '==',
	"'1234.5678'", 'Add quotes to float' );

cmp_ok( $db->addQuotes( 'string' ), '==',
	"'string'", 'Add quotes to string' );
	
cmp_ok( $db->addQuotes( "string's cause trouble" ), '==',
	"'string\'s cause trouble'", 'Add quotes to quoted string' );

$sql = $db->fillPrepared(
	'SELECT * FROM interwiki', array() );
cmp_ok( $sql, '==',
	'SELECT * FROM interwiki', 'FillPrepared empty' );

$sql = $db->fillPrepared(
	'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
	array( 4, "Snicker's_paradox" ) );
cmp_ok( $sql, '==',
	"SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'", 'FillPrepared question' );

$sql = $db->fillPrepared(
	'SELECT user_id FROM ! WHERE user_name=?',
	array( '"user"', "Slash's Dot" ) );
cmp_ok( $sql, '==',
	"SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'", 'FillPrepared quoted' );

$sql = $db->fillPrepared(
	"SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
	array( '"user"', "Slash's Dot" ) );
cmp_ok( $sql, '==',
	"SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'", 'FillPrepared raw' );