4 * Class CRM_Utils_SQLTest
7 class CRM_Utils_SQLTest
extends CiviUnitTestCase
{
9 public function testInterpolate() {
10 // This function is a thin wrapper for `CRM_Utils_SQL_BaseParamQuery::interpolate()`, which already has
11 // lots of coverage in other test classes. This test just checks the basic wiring.
12 $sql = CRM_Utils_SQL
::interpolate('FROBNICATE some_table WITH MAX(!dynamicField) OVER #times USING (@list) OR (#ids) OR @item', [
13 '!dynamicField' => 'the(field)',
15 '@list' => ['abc def', '45'],
17 '@item' => "it's text",
19 $this->assertEquals('FROBNICATE some_table WITH MAX(the(field)) OVER 123 USING ("abc def", "45") OR (6, 7, 8) OR "it\\\'s text"', $sql);
22 public function testInterpolateBad() {
24 CRM_Utils_SQL
::interpolate("UPDATE !the_table SET !the_field = @THE_VALUE", [
25 // MISSING: 'the_table'
26 'the_field' => 'my_field',
27 'the_value' => 'ny value',
30 catch (CRM_Core_Exception
$e) {
31 $this->assertRegExp(';Cannot build query. Variable "!the_table" is unknown.;', $e->getMessage());