/**
* Manually add and remove contacts from a smart group.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testManualAddRemove() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ public function testManualAddRemove(): void {
+ [$group, $living, $deceased] = $this->setupSmartGroup();
// Add $n1 to $g
- $this->callAPISuccess('group_contact', 'create', [
+ $this->callAPISuccess('GroupContact', 'create', [
'contact_id' => $living[0]->id,
'group_id' => $group->id,
]);
- CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($group);
$this->assertCacheMatches(
[$deceased[0]->id, $deceased[1]->id, $deceased[2]->id, $living[0]->id],
$group->id
'status' => 'Removed',
]);
- CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($group);
$this->assertCacheMatches(
[
$deceased[1]->id,
}
/**
- * Allow removing contact from a parent group even if contact is in a child group. (CRM-8858).
+ * Allow removing contact from a parent group even if contact is in a child
+ * group. (CRM-8858).
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testRemoveFromParentSmartGroup() {
+ public function testRemoveFromParentSmartGroup(): void {
+ // Create $c1, $c2, $c3
+ $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3);
+
// Create smart group $parent
$params = [
'name' => 'Deceased Contacts',
$child = CRM_Contact_BAO_Group::create($params);
$this->registerTestObjects([$child]);
- // Create $c1, $c2, $c3
- $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3);
-
// Add $c1, $c2, $c3 to $child
foreach ($deceased as $contact) {
$this->callAPISuccess('group_contact', 'create', [
]);
}
- CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($parent);
$this->assertCacheMatches(
[$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
$parent->id
);
// Remove $c1 from $parent
- $this->callAPISuccess('group_contact', 'create', [
+ $this->callAPISuccess('GroupContact', 'create', [
'contact_id' => $deceased[0]->id,
'group_id' => $parent->id,
'status' => 'Removed',
]);
// Assert $c1 not in $parent
- CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($parent);
$this->assertCacheMatches(
[
$deceased[1]->id,
* Array(int).
* @param int $groupId
*/
- public function assertCacheMatches($expectedContactIds, $groupId) {
+ public function assertCacheMatches($expectedContactIds, $groupId): void {
$sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1';
$params = [1 => [$groupId, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
* Test the opportunistic refresh cache function does not touch non-expired entries.
*/
public function testOpportunisticRefreshCacheNoChangeIfNotExpired() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->assertCacheMatches(
[$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
* Test the opportunistic refresh cache function does refresh stale entries.
*/
public function testOpportunisticRefreshChangeIfCacheDateFieldStale() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
CRM_Core_DAO::executeQuery('UPDATE civicrm_group SET cache_date = DATE_SUB(NOW(), INTERVAL 7 MINUTE) WHERE id = ' . $group->id);
$group->find(TRUE);
* Test the opportunistic refresh cache function does refresh expired entries if mode is deterministic.
*/
public function testOpportunisticRefreshNoChangeWithDeterministicSetting() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']);
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
* Test the deterministic cache function refreshes with the deterministic setting.
*/
public function testDeterministicRefreshChangeWithDeterministicSetting() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']);
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
* Test the deterministic cache function refresh doesn't mess up non-expired.
*/
public function testDeterministicRefreshChangeDoesNotTouchNonExpired() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']);
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush();
* (hey it's an opportunity!).
*/
public function testDeterministicRefreshChangeWithOpportunisticSetting() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
* Test the api job wrapper around the deterministic refresh works.
*/
public function testJobWrapper() {
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
$this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
*
* @return array
*/
- protected function setupSmartGroup() {
+ protected function setupSmartGroup(): array {
+ // Create contacts $y1, $y2, $y3 which do match $g; create $n1, $n2, $n3 which do not match $g
+ $living = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 0], 3);
+ $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3);
+ $this->assertCount(3, $deceased);
+ $this->assertCount(3, $living);
+
$params = [
'name' => 'Deceased Contacts',
'title' => 'Deceased Contacts',
$group = CRM_Contact_BAO_Group::createSmartGroup($params);
$this->registerTestObjects([$group]);
- // Create contacts $y1, $y2, $y3 which do match $g; create $n1, $n2, $n3 which do not match $g
- $living = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 0], 3);
- $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3);
- $this->assertEquals(3, count($deceased));
- $this->assertEquals(3, count($living));
-
// Assert: $g cache has exactly $y1, $y2, $y3
- CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($group);
$group->find(TRUE);
$this->assertCacheMatches(
[$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
'sort_name' => 1,
'group' => 1,
];
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$params = [
'name' => 'Living Contacts',
'sort_name' => 1,
'group' => 1,
];
- list($group, $living, $deceased) = $this->setupSmartGroup();
+ [$group, $living, $deceased] = $this->setupSmartGroup();
$params = [
'name' => 'Living Contacts',
* contact 8 : smart 5 (base)
*
* here 'contact 1 : static 0 (inc)' identified as static group $groupIDs[0]
- * that has 'contact 1' identified as $contactIDs[0] and Included in the mailing recipient list
+ * that has 'contact 1' identified as $contactIDs[0] and Included in the
+ * mailing recipient list
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \API_Exception
*/
- public function testgetRecipientsEmailGroupIncludeExclude() {
+ public function testGetRecipientsEmailGroupIncludeExclude(): void {
+ // Create contacts
+ $contactIDs = [
+ $this->individualCreate(['last_name' => 'smart5'], 0),
+ $this->individualCreate([], 1),
+ $this->individualCreate([], 2),
+ $this->individualCreate([], 3),
+ $this->individualCreate(['last_name' => 'smart3'], 4),
+ $this->individualCreate(['last_name' => 'smart3'], 5),
+ $this->individualCreate(['last_name' => 'smart4'], 6),
+ $this->individualCreate(['last_name' => 'smart4'], 7),
+ $this->individualCreate(['last_name' => 'smart5'], 8),
+ ];
+
// Set up groups; 3 standard, 4 smart
$groupIDs = [];
for ($i = 0; $i < 7; $i++) {
}
}
- // Create contacts
- $contactIDs = [
- $this->individualCreate(['last_name' => 'smart5'], 0),
- $this->individualCreate([], 1),
- $this->individualCreate([], 2),
- $this->individualCreate([], 3),
- $this->individualCreate(['last_name' => 'smart3'], 4),
- $this->individualCreate(['last_name' => 'smart3'], 5),
- $this->individualCreate(['last_name' => 'smart4'], 6),
- $this->individualCreate(['last_name' => 'smart4'], 7),
- $this->individualCreate(['last_name' => 'smart5'], 8),
- ];
-
// Add contacts to static groups
$this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[0],
$group = new CRM_Contact_DAO_Group();
$group->id = $groupIDs[$i];
$group->find(TRUE);
- CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
+ CRM_Contact_BAO_GroupContactCache::load($group);
}
// Check that we can include static groups in the mailing.