silverstripe-postgresql/tests/PostgreSQLConnectorTest.php

52 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* Description of PostgreSQLConnectorTest
*
* @author Damian
*/
2015-12-17 19:18:01 +01:00
class PostgreSQLConnectorTest extends SapphireTest
{
2015-12-17 19:18:01 +01:00
public function testSubstitutesPlaceholders()
{
$connector = new PostgreSQLConnector();
2015-12-17 19:18:01 +01:00
// basic case
$this->assertEquals(
"SELECT * FROM Table WHERE ID = $1",
$connector->replacePlaceholders("SELECT * FROM Table WHERE ID = ?")
);
2015-12-17 19:18:01 +01:00
// Multiple variables
$this->assertEquals(
"SELECT * FROM Table WHERE ID = $1 AND Name = $2",
$connector->replacePlaceholders("SELECT * FROM Table WHERE ID = ? AND Name = ?")
);
2015-12-17 19:18:01 +01:00
// Ignoring question mark placeholders within string literals
$this->assertEquals(
"SELECT * FROM Table WHERE ID = $1 AND Name = $2 AND Content = '<p>What is love?</p>'",
$connector->replacePlaceholders(
"SELECT * FROM Table WHERE ID = ? AND Name = ? AND Content = '<p>What is love?</p>'"
)
);
2015-12-17 19:18:01 +01:00
// Ignoring question mark placeholders within string literals with escaped slashes
$this->assertEquals(
"SELECT * FROM Table WHERE ID = $1 AND Title = '\\'' AND Content = '<p>What is love?</p>' AND Name = $2",
$connector->replacePlaceholders(
"SELECT * FROM Table WHERE ID = ? AND Title = '\\'' AND Content = '<p>What is love?</p>' AND Name = ?"
)
);
2015-12-17 19:18:01 +01:00
// same as above, but use double single quote escape syntax
$this->assertEquals(
"SELECT * FROM Table WHERE ID = $1 AND Title = '''' AND Content = '<p>What is love?</p>' AND Name = $2",
$connector->replacePlaceholders(
"SELECT * FROM Table WHERE ID = ? AND Title = '''' AND Content = '<p>What is love?</p>' AND Name = ?"
)
);
}
}