-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.php
156 lines (141 loc) · 5.09 KB
/
handler_test.php
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
* @version //autogentag//
* @filesource
* @package Database
* @subpackage Tests
*/
/**
* Test the handler classes.
*
* @package Database
* @subpackage Tests
*/
class ezcDatabaseHandlerTest extends ezcTestCase
{
protected function setUp()
{
try
{
$db = ezcDbInstance::get();
}
catch ( Exception $e )
{
$this->markTestSkipped();
}
}
public function testConstructorNoDatabaseName()
{
try
{
// we'll create an instance of the correct type simply by making a similar one to the default.
$db = ezcDbInstance::get();
$className = get_class( $db );
$db = new $className( array() );
$this->fail( "Instantiating a handler with no database name should not be successful" );
}
catch ( ezcDbMissingParameterException $e ) {}
}
public function testIdentifierQuotingNoEscape()
{
$db = ezcDbInstance::get();
switch ( get_class( $db ) )
{
case 'ezcDbHandlerMysql':
$quoteChars = array( '`', '`' );
break;
case 'ezcDbHandlerOracle':
case 'ezcDbHandlerPgsql':
case 'ezcDbHandlerSqlite':
$quoteChars = array( '"', '"' );
break;
case 'ezcDbHandlerMssql':
$quoteChars = array( '[', ']' );
break;
default:
$this->markTestSkipped( "No quoting test defined for handler class '{" . get_class( $db ) . "}'" );
}
$this->assertEquals(
$quoteChars[0] . 'TestIdentifier' . $quoteChars[1],
$db->quoteIdentifier( 'TestIdentifier' )
);
}
public function testIdentifierQuotingEscape()
{
$db = ezcDbInstance::get();
switch ( get_class( $db ) )
{
case 'ezcDbHandlerMysql':
$quoteChars = array( '`', '`' );
break;
case 'ezcDbHandlerMssql':
$db->setOptions( new ezcDbMssqlOptions( array('quoteIdentifier' => ezcDbMssqlOptions::QUOTES_COMPLIANT ) ));
case 'ezcDbHandlerOracle':
case 'ezcDbHandlerPgsql':
case 'ezcDbHandlerSqlite':
$quoteChars = array( '"', '"' );
break;
default:
$this->markTestSkipped( "No quoting test defined for handler class '{" . get_class( $db ) . "}'" );
}
$this->assertEquals(
$quoteChars[0] . "Test" . $quoteChars[1] . $quoteChars[1] . "Identifier" . $quoteChars[1],
$db->quoteIdentifier( "Test" . $quoteChars[1] . "Identifier" )
);
}
public function testMssqlIdentifierQuotingUntouched()
{
$db = ezcDbInstance::get();
if ( get_class( $db ) != 'ezcDbHandlerMssql' )
{
$this->markTestSkipped( 'Test defined for MS SQL handler class only.' );
}
$db->setOptions( new ezcDbMssqlOptions( array('quoteIdentifier' => ezcDbMssqlOptions::QUOTES_UNTOUCHED ) ));
$quoteChars = array( '"', '"' );
$this->assertEquals( $quoteChars[0].'ezctesttable'.$quoteChars[1], $db->quoteIdentifier( 'ezctesttable' ));
}
public function testMssqlIdentifierQuotingCompliant()
{
$db = ezcDbInstance::get();
if ( get_class( $db ) != 'ezcDbHandlerMssql' )
{
$this->markTestSkipped( 'Test defined for MS SQL handler class only.' );
}
$db->setOptions( new ezcDbMssqlOptions( array('quoteIdentifier' => ezcDbMssqlOptions::QUOTES_COMPLIANT ) ));
$this->assertEquals( '"ezctesttable"', $db->quoteIdentifier( 'ezctesttable' ));
}
public function testMssqlIdentifierQuotingLegacy()
{
$db = ezcDbInstance::get();
if ( get_class( $db ) != 'ezcDbHandlerMssql' )
{
$this->markTestSkipped( 'Test defined for MS SQL handler class only.' );
}
$db->setOptions( new ezcDbMssqlOptions( array('quoteIdentifier' => ezcDbMssqlOptions::QUOTES_LEGACY ) ));
$this->assertEquals( '[ezctesttable]', $db->quoteIdentifier( 'ezctesttable' ));
}
public function testMssqlIdentifierQuotingImpl()
{
$db = ezcDbInstance::get();
if ( get_class( $db ) != 'ezcDbHandlerMssql' )
{
$this->markTestSkipped( 'Test defined for MS SQL handler class only.' );
}
$db->setOptions( new ezcDbMssqlOptions( array('quoteIdentifier' => ezcDbMssqlOptions::QUOTES_COMPLIANT ) ));
try {
$db->query('CREATE TABLE '.$db->quoteIdentifier('group') . ' ( id INT )');
$db->query('DROP TABLE '.$db->quoteIdentifier('group') );
}
catch ( Exception $ex )
{
$this->fail( "Incorrect identifiers quoting ".$ex->getMessage() );
}
}
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcDatabaseHandlerTest" );
}
}
?>