Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit 8d86a0f

Browse files
author
Rich Lott / Artful Robot
committed
Fix #1
1 parent 378bbb6 commit 8d86a0f

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ discuss any improvements. Please also note that a more general nuts-and-bolts
5454
solution to your problem may be found in using CiviRules instead.
5555

5656
Enjoy :-)
57+
58+
## Version 1.1
59+
60+
This used to just work when adding Individuals, but now works for Households and
61+
Organisations (Issue #1)

autogroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function autogroup_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
127127
* Ensure newly created contacts are added to the same groups as the creator.
128128
*/
129129
function autogroup_civicrm_post($op, $objectName, $objectId, &$objectRef) {
130-
if ($op == 'create' && $objectName == 'Individual') {
130+
if ($op === 'create' && in_array($objectName, ['Individual', 'Organization', 'Household'])) {
131131

132132
// Which groups do we consider for adding?
133133
$groups = Civi::settings()->get('autogroup_groups_to_copy');

info.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
<url desc="Licensing">http://www.gnu.org/licenses/gpl-3.0.html</url>
1919
</urls>
2020
<releaseDate>2017-11-30</releaseDate>
21-
<version>1.0.0</version>
21+
<version>1.1.0</version>
2222
<develStage>beta</develStage>
2323
<compatibility>
2424
<ver>4.7</ver>
25+
<ver>5.0</ver>
26+
<ver>5.13</ver>
2527
</compatibility>
2628
<comments></comments>
2729
<civix>

tests/phpunit/AutoGroupTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class AutoGroupTest extends \PHPUnit_Framework_TestCase implements HeadlessInter
3232
'last_name' => 'Added',
3333
'contact_type' => 'Individual',
3434
],
35+
'new_org' => [
36+
'display_name' => 'Caves and Stones Ltd.',
37+
'contact_type' => 'Individual',
38+
],
39+
'new_household' => [
40+
'display_name' => 'The Rubble-Flintstones',
41+
'contact_type' => 'Individual',
42+
],
3543
],
3644
'groups' => [
3745
'addable1' => [
@@ -104,6 +112,52 @@ public function testAddingIndividualCopiesCorrectGroups() {
104112
}
105113
}
106114

115+
/**
116+
* Test that the correct groups are copied.
117+
*/
118+
public function testAddingOrganizationCopiesCorrectGroups() {
119+
120+
// Configure the extension.
121+
$groups = Civi::settings()->set('autogroup_groups_to_copy', [
122+
$this->fixtures['groups']['addable1']['group_id'],
123+
$this->fixtures['groups']['addable2']['group_id'],
124+
]);
125+
126+
127+
$result = civicrm_api3('Contact', 'create', $this->fixtures['contacts']['new_org']);
128+
$this->fixtures['contacts']['new_org']['contact_id'] = $result['id'];
129+
130+
foreach (['addable1', 'addable2'] as $_) {
131+
$this->assertContactInGroup($result['id'], $this->fixtures['groups'][$_]['group_id']);
132+
}
133+
foreach (['notaddable'] as $_) {
134+
$this->assertContactNotInGroup($result['id'], $this->fixtures['groups'][$_]['group_id']);
135+
}
136+
}
137+
138+
/**
139+
* Test that the correct groups are copied.
140+
*/
141+
public function testAddingHouseholdCopiesCorrectGroups() {
142+
143+
// Configure the extension.
144+
$groups = Civi::settings()->set('autogroup_groups_to_copy', [
145+
$this->fixtures['groups']['addable1']['group_id'],
146+
$this->fixtures['groups']['addable2']['group_id'],
147+
]);
148+
149+
150+
$result = civicrm_api3('Contact', 'create', $this->fixtures['contacts']['new_household']);
151+
$this->fixtures['contacts']['new_household']['contact_id'] = $result['id'];
152+
153+
foreach (['addable1', 'addable2'] as $_) {
154+
$this->assertContactInGroup($result['id'], $this->fixtures['groups'][$_]['group_id']);
155+
}
156+
foreach (['notaddable'] as $_) {
157+
$this->assertContactNotInGroup($result['id'], $this->fixtures['groups'][$_]['group_id']);
158+
}
159+
}
160+
107161
/**
108162
* Example: Test that no groups are added when unconfigured.
109163
*/

0 commit comments

Comments
 (0)