+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017 |
+ | Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
//check for empty parent
'parents' => "",
'visibility' => 'Public Pages',
- 'group_type' => array(1, 2),
+ 'group_type' => [1, 2],
);
$result = $this->callAPISuccess('Group', 'create', $params);
'title' => 'Test Group 2',
'group_type' => 2,
'parents' => $result['id'],
+ 'sequential' => 1,
)
);
- $result = $this->callAPISuccess('Group', 'create', $params);
- $group = $result["values"][$result['id']];
- $this->assertEquals($group['group_type'], array($params['group_type']));
- $this->assertEquals($group['parents'], $params['parents']);
+ $group2 = $this->callAPISuccess('Group', 'create', $params)['values'][0];
+
+ $this->assertEquals($group2['group_type'], array($params['group_type']));
+ $this->assertEquals($params['parents'], $group2['parents']);
+
+ // Test array format for parents.
+ $params = array_merge($params, array(
+ 'name' => 'Test Group 3',
+ 'title' => 'Test Group 3',
+ 'parents' => [$result['id'], $group2['id']],
+ )
+ );
+ $group3 = $this->callAPISuccess('Group', 'create', $params)['values'][0];
+ $parents = $this->callAPISuccess('Group', 'getvalue', ['return' => 'parents', 'id' => $group3['id']]);
+
+ $this->assertAPIArrayComparison("{$result['id']},{$group2['id']}", $parents);
+
+ $groupNesting = $this->callAPISuccess('GroupNesting', 'get', ['child_group_id' => $group3['id']]);
+ // 2 Group nesting entries - one for direct parent & one for grandparent.
+ $this->assertEquals(2, $groupNesting['count']);
+ $this->groupDelete($group2['id']);
+ $this->groupDelete($group3['id']);
+ }
+
+ /**
+ * Test that an array of valid values works for group_type field.
+ */
+ public function testGroupTypeWithPseudoconstantArray() {
+ $params = [
+ 'name' => 'Test Group 2',
+ 'title' => 'Test Group 2',
+ 'group_type' => ['Mailing List', 'Access Control'],
+ 'sequential' => 1,
+ ];
+ $group = $this->callAPISuccess('Group', 'create', $params);
+ $groupType = $this->callAPISuccess('Group', 'getvalue', ['return' => 'group_type', 'id' => $group['id']]);
+
+ $this->assertAPIArrayComparison([2, 1], $groupType);
}
public function testGetNonExistingGroup() {
$params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"] = "Test";
$this->callAPIFailure('group', 'create', $params);
unset($params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"]);
- $group2 = $this->callAPISuccess('group', 'create', $params);
- $this->assertEquals(count($group2['values'][$group2['id']]['parents']), 1);
+ $this->callAPIFailure('group', 'create', $params, '\'test Group\' is not a valid option for field parents');
}
/**