diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php
index d3d42b94843a..dde7c1631367 100644
--- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php
+++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php
@@ -19,9 +19,14 @@ public function setUp() {
parent::setUp();
}
+ /**
+ * Clean up after test.
+ *
+ * @throws \Exception
+ */
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_group_contact',
'civicrm_group',
'civicrm_saved_search',
@@ -29,7 +34,7 @@ public function tearDown() {
'civicrm_tag',
'civicrm_contact',
'civicrm_address',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
}
@@ -44,12 +49,89 @@ public function tearDown() {
* @param $full
*/
public function testSearch($fv, $count, $ids, $full) {
- $op = new PHPUnit_Extensions_Database_Operation_Insert();
- $op->execute($this->_dbconn,
- $this->createFlatXMLDataSet(
- dirname(__FILE__) . '/queryDataset.xml'
- )
- );
+ $this->callAPISuccess('SavedSearch', 'create', ['form_values' => 'a:9:{s:5:"qfKey";s:32:"0123456789abcdef0123456789abcdef";s:13:"includeGroups";a:1:{i:0;s:1:"3";}s:13:"excludeGroups";a:0:{}s:11:"includeTags";a:0:{}s:11:"excludeTags";a:0:{}s:4:"task";s:2:"14";s:8:"radio_ts";s:6:"ts_all";s:14:"customSearchID";s:1:"4";s:17:"customSearchClass";s:36:"CRM_Contact_Form_Search_Custom_Group";}',]);
+ $this->callAPISuccess('SavedSearch', 'create', ['form_values' => 'a:9:{s:5:"qfKey";s:32:"0123456789abcdef0123456789abcdef";s:13:"includeGroups";a:1:{i:0;s:1:"3";}s:13:"excludeGroups";a:0:{}s:11:"includeTags";a:0:{}s:11:"excludeTags";a:0:{}s:4:"task";s:2:"14";s:8:"radio_ts";s:6:"ts_all";s:14:"customSearchID";s:1:"4";s:17:"customSearchClass";s:36:"CRM_Contact_Form_Search_Custom_Group";}',]);
+
+ $tag7 = $this->ids['Tag'][7] = $this->tagCreate(['name' => 'Test Tag 7', 'description' => 'Test Tag 7'])['id'];
+ $tag9 = $this->ids['Tag'][9] = $this->tagCreate(['name' => 'Test Tag 9', 'description' => 'Test Tag 9'])['id'];
+ $this->tagCreate(['name' => 'Test Tag 10']);
+ $groups = [
+ 3 => ['name' => 'Test Group 3'],
+ 4 => ['name' => 'Test Smart Group 4', 'saved_search_id' => 1],
+ 5 => ['name' => 'Test Group 5'],
+ 6 => ['name' => 'Test Smart Group 6', 'saved_search_id' => 2],
+ ];
+
+ foreach ($groups as $id => $group) {
+ $this->ids['Group'][$id] = $this->groupCreate(array_merge($group, ['title' => $group['name']]));
+ }
+ $individuals = [
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 9', 'gender_id' => 1, 'prefix_id' => 1, 'suffix_id' => 1],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 10', 'gender_id' => 2, 'prefix_id' => 2, 'suffix_id' => 2, 'api.entity_tag.create' => ['tag_id' => $tag9],],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 11', 'gender_id' => 3, 'prefix_id' => 3, 'suffix_id' => 3, 'api.entity_tag.create' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 12', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 4, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 13', 'gender_id' => 2, 'prefix_id' => 2, 'suffix_id' => 2],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 14', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 4, 'api.entity_tag.create' => ['tag_id' => $tag9]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 15', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 5, 'api.entity_tag.create' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 16', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 6, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 17', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 7],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 18', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 4, 'api.entity_tag.create' => ['tag_id' => $tag9]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 19', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 6, 'api.entity_tag.create.2' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 20', 'gender_id' => 1, 'prefix_id' => 4, 'suffix_id' => 6, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 21', 'gender_id' => 3, 'prefix_id' => 1, 'suffix_id' => 6],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 22', 'gender_id' => 1, 'prefix_id' => 1, 'suffix_id' => 1, 'api.entity_tag.create' => ['tag_id' => $tag9]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 23', 'gender_id' => 3, 'prefix_id' => 1, 'suffix_id' => 1, 'api.entity_tag.create' => ['tag_id' => $tag7]],
+ ['first_name' => 'Test', 'last_name' => 'Test Contact 24', 'gender_id' => 3, 'prefix_id' => 3, 'suffix_id' => 2, 'api.entity_tag.create' => ['tag_id' => $tag9], 'api.entity_tag.create.2' => ['tag_id' => $tag7]],
+ ];
+ foreach ($individuals as $individual) {
+ $this->ids['Contact'][$individual['last_name']] = $this->individualCreate($individual);
+ }
+ $groupContacts = [
+ [5 => 13],
+ [5 => 14],
+ [5 => 15],
+ [5 => 16],
+ [5 => 21],
+ [5 => 22],
+ [5 => 23],
+ [5 => 24],
+ [3 => 17],
+ [3 => 18],
+ [3 => 19],
+ [3 => 20],
+ [3 => 21],
+ [3 => 22],
+ [3 => 23],
+ [3 => 24],
+ ];
+ foreach ($groupContacts as $group) {
+ $groupID = $this->ids['Group'][key($group)];
+ $contactID = $this->ids['Contact']['Test Contact ' . reset($group)];
+ $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID, 'status' => 'Added']);
+ }
+
+ // We have migrated from a hard-coded dataset to a dynamic one but are still working with the same
+ // dataprovider at this stage -> wrangle.
+ foreach ($fv as $key => $value) {
+ $entity = ucfirst($key);
+ if (!array_key_exists($entity, $this->ids)) {
+ continue;
+ }
+ if (is_numeric($value)) {
+ $fv[$key] = $this->ids[$entity][$value];
+ }
+ elseif (!empty($value[0])) {
+ foreach ($value as $index => $oldGroup) {
+ $fv[$key][$index] = $this->ids[$entity][$oldGroup];
+ }
+ }
+ else {
+ foreach (array_keys($value) as $index) {
+ unset($fv[$key][$index]);
+ $fv[$key][$this->ids[$entity][$index]] = 1;
+ }
+ }
+ }
$params = CRM_Contact_BAO_Query::convertFormValues($fv);
$obj = new CRM_Contact_BAO_Query($params);
@@ -60,14 +142,18 @@ public function testSearch($fv, $count, $ids, $full) {
$dao = $obj->searchQuery();
- $contacts = array();
+ $contacts = [];
while ($dao->fetch()) {
$contacts[] = $dao->contact_id;
}
sort($contacts, SORT_NUMERIC);
- $this->assertEquals($ids, $contacts);
+ $expectedIDs = [];
+ foreach ($ids as $id) {
+ $expectedIDs[] = $this->ids['Contact']['Test Contact ' . $id];
+ }
+ $this->assertEquals($expectedIDs, $contacts);
}
/**
diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php
index baa1cfe47e77..f99fda141bf8 100644
--- a/tests/phpunit/api/v3/ReportTemplateTest.php
+++ b/tests/phpunit/api/v3/ReportTemplateTest.php
@@ -220,20 +220,248 @@ public function testReportTemplateGetRowsContactSummary() {
*/
public function testReportTemplateGetRowsMailingUniqueOpened() {
$description = "Retrieve rows from a mailing opened report template.";
- $op = new PHPUnit_Extensions_Database_Operation_Insert();
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 9', 'gender_id' => 1, 'prefix_id' => 1, 'suffix_id' => 1]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 10', 'gender_id' => 2, 'prefix_id' => 2, 'suffix_id' => 2]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 11', 'gender_id' => 3, 'prefix_id' => 3, 'suffix_id' => 3]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 12', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 4]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 13', 'gender_id' => 2, 'prefix_id' => 2, 'suffix_id' => 2]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 14', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 4]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 15', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 5]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 16', 'gender_id' => 3, 'prefix_id' => 4, 'suffix_id' => 6]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 17', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 7]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 18', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 4]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 19', 'gender_id' => 2, 'prefix_id' => 4, 'suffix_id' => 6]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 20', 'gender_id' => 1, 'prefix_id' => 4, 'suffix_id' => 6]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 21', 'gender_id' => 3, 'prefix_id' => 1, 'suffix_id' => 6]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 22', 'gender_id' => 1, 'prefix_id' => 1, 'suffix_id' => 1]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 23', 'gender_id' => 3, 'prefix_id' => 1, 'suffix_id' => 1]);
+ $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Test Contact 24', 'gender_id' => 3, 'prefix_id' => 3, 'suffix_id' => 2]);
+
+ $this->tagCreate(['name' => 'Test Tag 7']);
+ $this->tagCreate(['name' => 'Test Tag 9']);
+ $this->tagCreate(['name' => 'Test Tag 10']);
+/**
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
$op->execute($this->_dbconn,
$this->createFlatXMLDataSet(
dirname(__FILE__) . '/../../CRM/Mailing/BAO/queryDataset.xml'
)
);
-
+*/
// Check total rows without distinct
global $_REQUEST;
$_REQUEST['distinct'] = 0;
- $result = $this->callAPIAndDocument('report_template', 'getrows', array(
+ $result = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'Mailing/opened',
- 'options' => array('metadata' => array('labels', 'title')),
- ), __FUNCTION__, __FILE__, $description, 'Getrows');
+ 'options' => ['metadata' => array('labels', 'title')],
+ ]);
$this->assertEquals(14, $result['count']);
// Check total rows with distinct
@@ -396,6 +624,11 @@ public static function getMembershipReportTemplates() {
return array(array('member/detail'));
}
+ /**
+ * Get the membership and contribution reports to test.
+ *
+ * @return array
+ */
public static function getMembershipAndContributionReportTemplatesForGroupTests() {
$templates = array_merge(self::getContributionReportTemplates(), self::getMembershipReportTemplates());
foreach ($templates as $key => $value) {
@@ -1202,14 +1435,14 @@ public function testPcpReportTotals() {
);
$c3 = $this->contributionCreate($contribution3params);
// Now the soft contribution.
- $p = array(
+ $p = [
'contribution_id' => $c3,
'pcp_id' => $pcp2->id,
'contact_id' => $pcpOwnerContact2Id,
'amount' => 200.00,
'currency' => 'USD',
'soft_credit_type_id' => $pcp_soft_credit_type_id,
- );
+ ];
$this->callAPISuccess('contribution_soft', 'create', $p);
$template = 'contribute/pcp';
@@ -1231,7 +1464,7 @@ public function testPcpReportTotals() {
*/
public function testGetAddressColumns() {
$template = 'event/participantlisting';
- $rows = $this->callAPISuccess('report_template', 'getrows', [
+ $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
'fields' => [
'sort_name' => '1',