From 0c627c6fee02686f50f10316e206ee8956ed6a37 Mon Sep 17 00:00:00 2001
From: Tim Otten <totten@civicrm.org>
Date: Wed, 3 Jul 2013 11:08:14 -0700
Subject: [PATCH] CRM-12976 - CRM_Core_DAOTest - Add tests for composeQuery
 bugs

----------------------------------------
* CRM-12976: In field of type Notes - TextArea, data Input of a $  (dollar sign) followed by one or two digits between 1 and 9 will result in deletion of the numbers.
  http://issues.civicrm.org/jira/browse/CRM-12976
---
 tests/phpunit/CRM/Core/DAOTest.php | 74 ++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 tests/phpunit/CRM/Core/DAOTest.php

diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php
new file mode 100644
index 0000000000..5989a9e42b
--- /dev/null
+++ b/tests/phpunit/CRM/Core/DAOTest.php
@@ -0,0 +1,74 @@
+<?php
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+class CRM_Core_DAOTest extends CiviUnitTestCase {
+  function composeQueryExamples() {
+    $cases = array();
+    // $cases[] = array('Input-SQL', 'Input-Params', 'Expected-SQL');
+
+    // CASE: No params
+    $cases[] = array(
+      'SELECT * FROM whatever',
+      array(),
+      'SELECT * FROM whatever',
+    );
+
+    // CASE: Integer param
+    $cases[] = array(
+      'SELECT * FROM whatever WHERE id = %1',
+      array(
+        1 => array(10, 'Integer'),
+      ),
+      'SELECT * FROM whatever WHERE id = 10',
+    );
+
+    // CASE: String param
+    $cases[] = array(
+      'SELECT * FROM whatever WHERE name = %1',
+      array(
+        1 => array('Alice', 'String'),
+      ),
+      'SELECT * FROM whatever WHERE name = \'Alice\'',
+    );
+
+    // CASE: Two params
+    $cases[] = array(
+      'SELECT * FROM whatever WHERE name = %1 AND title = %2',
+      array(
+        1 => array('Alice', 'String'),
+        2 => array('Bob', 'String'),
+      ),
+      'SELECT * FROM whatever WHERE name = \'Alice\' AND title = \'Bob\'',
+    );
+
+    // CASE: Two params with special character (%1)
+    $cases[] = array(
+      'SELECT * FROM whatever WHERE name = %1 AND title = %2',
+      array(
+        1 => array('Alice %2', 'String'),
+        2 => array('Bob', 'String'),
+      ),
+      'SELECT * FROM whatever WHERE name = \'Alice %2\' AND title = \'Bob\'',
+    );
+
+    // CASE: Two params with special character ($1)
+    $cases[] = array(
+      'SELECT * FROM whatever WHERE name = %1 AND title = %2',
+      array(
+        1 => array('Alice $1', 'String'),
+        2 => array('Bob', 'String'),
+      ),
+      'SELECT * FROM whatever WHERE name = \'Alice $1\' AND title = \'Bob\'',
+    );
+
+    return $cases;
+  }
+
+  /**
+   * @dataProvider composeQueryExamples
+   */
+  function testComposeQuery($inputSql, $inputParams, $expectSql) {
+    $actualSql = CRM_Core_DAO::composeQuery($inputSql, $inputParams);
+    $this->assertEquals($expectSql, $actualSql);
+  }
+}
-- 
2.25.1