Commit 5d8bb7d0 by Scott

Add tests for applyTableSub

parent 09c048cc
......@@ -14,12 +14,16 @@ class DbQueryHelperTest extends PHPUnit_Framework_TestCase
public function test__expandParameters_success()
{
$result = $this->helper->expandParameters('SELECT * FROM table WHERE field = 1', []);
$expected = ['SELECT * FROM table WHERE field = 1', []];
$result = $this->helper->expandParameters('SELECT * FROM table WHERE field=1', []);
$expected = ['SELECT * FROM table WHERE field=1', []];
$this->assertSame($expected, $result);
$result = $this->helper->expandParameters('SELECT * FROM table WHERE field = ?', [1]);
$expected = ['SELECT * FROM table WHERE field = ?', [1]];
$result = $this->helper->expandParameters('SELECT * FROM table WHERE field=?', [1]);
$expected = ['SELECT * FROM table WHERE field=?', [1]];
$this->assertSame($expected, $result);
$result = $this->helper->expandParameters('SELECT * FROM table WHERE field=#', [1]);
$expected = ['SELECT * FROM table WHERE field=?', [1]];
$this->assertSame($expected, $result);
$result = $this->helper->expandParameters('SELECT * FROM table WHERE field IN (?)', [[1]]);
......@@ -52,4 +56,24 @@ class DbQueryHelperTest extends PHPUnit_Framework_TestCase
$this->setExpectedException('Q2A\Database\Exceptions\SelectSpecException');
$this->helper->expandParameters('INSERT INTO table(field1, field2) VALUES ?', [[ [1, 2], [3] ]]);
}
public function test__applyTableSub()
{
$result = $this->helper->applyTableSub('SELECT * FROM ^options');
$this->assertSame('SELECT * FROM qa_options', $result);
$result = $this->helper->applyTableSub('SELECT * FROM ^users WHERE userid=?');
$this->assertSame('SELECT * FROM qa_users WHERE userid=?', $result);
}
public function test__applyTableSub_users_prefix()
{
define('QA_MYSQL_USERS_PREFIX', 'base_');
$result = $this->helper->applyTableSub('SELECT * FROM ^options');
$this->assertSame('SELECT * FROM qa_options', $result);
$result = $this->helper->applyTableSub('SELECT * FROM ^users WHERE userid=?');
$this->assertSame('SELECT * FROM base_users WHERE userid=?', $result);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment