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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for sql-formatter/lib/SqlFormatter.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/sql-formatter/lib/SqlFormatter.php';
/**
* tests for SqlFormatter
*
* @package PhpMyAdmin-test
*/
class SqlFormatter_Test extends PHPUnit_Framework_TestCase
{
/**
* Data provider for testSqlFormatter_format
*
* @return array with test data
*/
public function formatDataProvider() {
return array(
array(
"SELECT * FROM `test`",
"SELECT
*
FROM
`test`",
),
array(
"SELECT customer_id, customer_name, COUNT(order_id) as total FROM customers
INNER JOIN orders ON customers.customer_id = orders.customer_id GROUP BY customer_id,
customer_name HAVING COUNT(order_id) > 5 ORDER BY COUNT(order_id) DESC;",
"SELECT
customer_id,
customer_name,
COUNT(order_id) as total
FROM
customers
INNER JOIN orders ON customers.customer_id = orders.customer_id
GROUP BY
customer_id,
customer_name
HAVING
COUNT(order_id) > 5
ORDER BY
COUNT(order_id) DESC;"
),
array(
"SELECT a,b as c FROM `ab`; UPDATE `cd` SET `col` = REPLACE(col, 'find', 'replace')
WHERE row_id in (SELECT row_id FROM new_table WHERE col = 's' AND col2 = '3') LIMIT 256",
"SELECT
a,
b as c
FROM
`ab`;
UPDATE
`cd`
SET
`col` = REPLACE(col, 'find', 'replace')
WHERE
row_id in (
SELECT
row_id
FROM
new_table
WHERE
col = 's'
AND col2 = '3'
)
LIMIT
256"
),
array(
"INSERT INTO `a_long_table_name_it_is_really_log_but_still_not_that_long`
(a, b, c, d, e, f, g, a, b, c, d, e, f, c, d, e)
VALUES (1, 0, '', 1, NOW(), NOW(), 0),
(1, 0, 'helloabcdefgijk', 1, 'hello_world_again', NOW(), 0)",
"INSERT INTO `a_long_table_name_it_is_really_log_but_still_not_that_long` (
a, b, c, d, e, f, g, a, b, c, d, e, f, c, d, e
)
VALUES
(1, 0, '', 1, NOW(), NOW(), 0),
(
1, 0, 'helloabcdefgijk', 1, 'hello_world_again',
NOW(), 0
)"
),
array(
"ALTER TABLE `PREFIX_product` DROP `reduction_price`,DROP `reduction_percent`,
DROP `reduction_from`, DROP `reduction_to`",
"ALTER TABLE
`PREFIX_product`
DROP
`reduction_price`,
DROP
`reduction_percent`,
DROP
`reduction_from`,
DROP
`reduction_to`"
),
);
}
/**
* Test for SqlFormatter::format
*
* @return void
*
* @dataProvider formatDataProvider
*/
public function testSqlFormatter_format($query, $expected)
{
SqlFormatter::$tab = "\t";
$this->assertEquals(
$expected,
SqlFormatter::format($query, false)
);
}
}
|