Skip to content

Commit f5337d3

Browse files
committed
Userland tests for ODBC connection string funcs
The primary reason for these functions oother than for i.e. database frameworks and libraries. It's much easier to test them outside of the context of needing a full ODBC driver.
1 parent 622f676 commit f5337d3

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--TEST--
2+
Test common ODBC string functionality
3+
--FILE--
4+
<?php
5+
6+
// 1. No, it's not quoted.
7+
// 2. Yes, it should be quoted because of the special character in the middle.
8+
$with_end_curly1 = "foo}bar";
9+
// 1. No, the unescaped special character in the middle breaks what would be quoted.
10+
// 2. Yes, it should be quoted because of the special character in the middle.
11+
// Note that should_quote doesn't care about if the string is already quoted.
12+
// That's why you should check if it is quoted first.
13+
$with_end_curly2 = "{foo}bar}";
14+
// 1. Yes, the special characters are escaped, so it's quoted.
15+
// 2. See $with_end_curly2; should_quote doesn't care about if the string is already quoted.
16+
$with_end_curly3 = "{foo}}bar}";
17+
// 1. No, it's not quoted.
18+
// 2. It doesn't need to be quoted because of no s
19+
$with_no_end_curly1 = "foobar";
20+
// 1. Yes, it is quoted and any characters are properly escaped.
21+
// 2. See $with_end_curly2.
22+
$with_no_end_curly2 = "{foobar}";
23+
24+
echo "# Is quoted?\n";
25+
echo "With end curly brace 1: ";
26+
var_dump(odbc_connection_string_is_quoted($with_end_curly1));
27+
echo "With end curly brace 2: ";
28+
var_dump(odbc_connection_string_is_quoted($with_end_curly2));
29+
echo "With end curly brace 3: ";
30+
var_dump(odbc_connection_string_is_quoted($with_end_curly3));
31+
echo "Without end curly brace 1: ";
32+
var_dump(odbc_connection_string_is_quoted($with_no_end_curly1));
33+
echo "Without end curly brace 2: ";
34+
var_dump(odbc_connection_string_is_quoted($with_no_end_curly2));
35+
36+
echo "# Should quote?\n";
37+
echo "With end curly brace 1: ";
38+
var_dump(odbc_connection_string_should_quote($with_end_curly1));
39+
echo "With end curly brace 2: ";
40+
var_dump(odbc_connection_string_should_quote($with_end_curly2));
41+
echo "With end curly brace 3: ";
42+
var_dump(odbc_connection_string_should_quote($with_end_curly3));
43+
echo "Without end curly brace 1: ";
44+
var_dump(odbc_connection_string_should_quote($with_no_end_curly1));
45+
echo "Without end curly brace 2: ";
46+
var_dump(odbc_connection_string_should_quote($with_no_end_curly2));
47+
48+
echo "# Quote?\n";
49+
echo "With end curly brace 1: ";
50+
var_dump(odbc_connection_string_quote($with_end_curly1));
51+
echo "With end curly brace 2: ";
52+
var_dump(odbc_connection_string_quote($with_end_curly2));
53+
echo "With end curly brace 3: ";
54+
var_dump(odbc_connection_string_quote($with_end_curly3));
55+
echo "Without end curly brace 1: ";
56+
var_dump(odbc_connection_string_quote($with_no_end_curly1));
57+
echo "Without end curly brace 2: ";
58+
var_dump(odbc_connection_string_quote($with_no_end_curly2));
59+
60+
?>
61+
--EXPECTF--
62+
# Is quoted?
63+
With end curly brace 1: bool(false)
64+
With end curly brace 2: bool(false)
65+
With end curly brace 3: bool(true)
66+
Without end curly brace 1: bool(false)
67+
Without end curly brace 2: bool(true)
68+
# Should quote?
69+
With end curly brace 1: bool(true)
70+
With end curly brace 2: bool(true)
71+
With end curly brace 3: bool(true)
72+
Without end curly brace 1: bool(false)
73+
Without end curly brace 2: bool(true)
74+
# Quote?
75+
With end curly brace 1: string(10) "{foo}}bar}"
76+
With end curly brace 2: string(13) "{{foo}}bar}}}"
77+
With end curly brace 3: string(15) "{{foo}}}}bar}}}"
78+
Without end curly brace 1: string(8) "{foobar}"
79+
Without end curly brace 2: string(11) "{{foobar}}}"

0 commit comments

Comments
 (0)