* @package CiviCRM
* @group headless
*/
-class CRM_Contact_Form_SelectorTest extends CiviUnitTestCase {
+class CRM_Contact_SelectorTest extends CiviUnitTestCase {
public function tearDown() {
$selector->setKey($key);
// fetch row and check the result
- $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, TRUE, NULL);
+ $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 1, NULL);
$this->assertEquals(1, count($rows));
$this->assertEquals($contactID, key($rows));
// build cache key and use to it to fetch prev-next cache record
$cacheKey = 'civicrm search ' . $key;
$contacts = CRM_Utils_SQL_Select::from('civicrm_prevnext_cache')
- ->select(['entity_table', 'entity_id1', 'cacheKey'])
- ->where("cacheKey = '!key'")
- ->param('!key', $cacheKey)
+ ->select(['entity_id1', 'cacheKey'])
+ ->where("cacheKey = @key")
+ ->param('key', $cacheKey)
->execute()
->fetchAll();
$this->assertEquals(1, count($contacts));
// check the prevNext record matches
$expectedEntry = [
- 'entity_table' => 'civicrm_contact',
'entity_id1' => $contactID,
'cacheKey' => $cacheKey,
];
'expected_query' => array(
0 => 'default',
1 => 'default',
- 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' AND ( ( ( contact_a.sort_name LIKE '%mouse%' ) OR ( civicrm_email.email LIKE '%mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)",
+ 2 => "WHERE ( civicrm_email.email LIKE '%mickey@mouseville.com%' AND ( ( ( contact_a.sort_name LIKE '%Mouse%' ) OR ( civicrm_email.email LIKE '%Mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)",
),
),
),
'expected_query' => array(
0 => 'default',
1 => 'default',
- 2 => "WHERE ( civicrm_email.email LIKE 'mickey@mouseville.com%' AND ( ( ( contact_a.sort_name LIKE 'mouse%' ) OR ( civicrm_email.email LIKE 'mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)",
+ 2 => "WHERE ( civicrm_email.email LIKE 'mickey@mouseville.com%' AND ( ( ( contact_a.sort_name LIKE 'Mouse%' ) OR ( civicrm_email.email LIKE 'Mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)",
),
),
),
'expected_query' => array(
0 => 'default',
1 => 'default',
- 2 => "WHERE ( civicrm_email.email = 'mickey@mouseville.com' AND ( ( ( contact_a.sort_name LIKE 'mouse%' ) OR ( civicrm_email.email LIKE 'mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)",
+ 2 => "WHERE ( civicrm_email.email = 'mickey@mouseville.com' AND ( ( ( contact_a.sort_name LIKE 'Mouse%' ) OR ( civicrm_email.email LIKE 'Mouse%' ) ) ) ) AND (contact_a.is_deleted = 0)",
),
),
),
$expectedQuery = [
0 => "SELECT contact_a.id as contact_id, contact_a.contact_type as `contact_type`, contact_a.contact_sub_type as `contact_sub_type`, contact_a.sort_name as `sort_name`, `Non_ASCII_Location_Type-location_type`.id as `Non_ASCII_Location_Type-location_type_id`, `Non_ASCII_Location_Type-location_type`.name as `Non_ASCII_Location_Type-location_type`, `Non_ASCII_Location_Type-email`.id as `Non_ASCII_Location_Type-email_id`, `Non_ASCII_Location_Type-email`.email as `Non_ASCII_Location_Type-email`",
// @TODO these FROM clause doesn't matches due to extra spaces or special character
- 2 => "WHERE ( ( LOWER(`Non_ASCII_Location_Type-email`.email) IS NOT NULL ) ) AND (contact_a.is_deleted = 0)",
+ 2 => "WHERE ( ( `Non_ASCII_Location_Type-email`.email IS NOT NULL ) ) AND (contact_a.is_deleted = 0)",
];
foreach ($expectedQuery as $index => $queryString) {
$this->assertEquals($this->strWrangle($queryString), $this->strWrangle($sql[$index]));
}
- $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, TRUE, NULL);
+ $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 1, NULL);
$this->assertEquals(1, count($rows));
$this->assertEquals($contactID, key($rows));
$this->assertEquals('test@test.com', $rows[$contactID]['Non_ASCII_Location_Type-email']);
$filtersByWhereClause = [
'IS NOT NULL' => '( contact_a.first_name IS NOT NULL )', // doesn't matter
'=' => "( contact_a.first_name = 'Adam' )", // case sensitive check
- 'LIKE' => "( contact_a.first_name LIKE '%ad%' )", // case insensitive check
+ 'LIKE' => "( contact_a.first_name LIKE '%Ad%' )", // case insensitive check
'RLIKE' => "( contact_a.first_name RLIKE BINARY '^A[a-z]{3}$' )", // case sensitive check
'IN' => '( contact_a.first_name IN ("Adam") )', // case sensitive check
];
$sql = $selector->getQueryObject()->query();
$this->assertEquals(TRUE, strpos($sql[2], $filtersByWhereClause[$op]));
- $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, TRUE, NULL);
+ $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 1, NULL);
$this->assertEquals(1, count($rows));
$this->assertEquals($contactID, key($rows));
}
$this->assertTrue(in_array($cgTableName, array_keys($query->_tables)));
//Assert if from clause joins the custom table.
$this->assertTrue(strpos($query->_fromClause, $cgTableName) !== FALSE);
+ $this->callAPISuccess('CustomField', 'delete', ['id' => $customField['id']]);
+ $this->callAPISuccess('CustomGroup', 'delete', ['id' => $customGroup['id']]);
}
/**
'title' => "test custom group",
'extends' => "Individual",
));
- $customTableName = $this->callAPISuccess('CustomGroup', 'getValue', ['id' => $customGroup, 'return' => 'table_name']);
+ $customTableName = $this->callAPISuccess('CustomGroup', 'getValue', ['id' => $customGroup['id'], 'return' => 'table_name']);
$customGroupTableName = $customGroup['values'][$customGroup['id']]['table_name'];
$createdField = $this->callAPISuccess('customField', 'create', [
// test the presence of expected date clause
$this->assertEquals(TRUE, strpos($whereClause, $expectedClause));
- $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, TRUE, NULL);
+ $rows = $selector->getRows(CRM_Core_Action::VIEW, 0, 1, NULL);
$this->assertEquals(1, count($rows));
}