public function setUp(): void {
$this->_apiversion = 3;
parent::setUp();
- $this->useTransaction(TRUE);
- $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
+ $this->useTransaction();
$this->params = [
- 'msg_title' => $template['msg_title'],
- 'msg_subject' => $template['msg_subject'],
- 'msg_text' => $template['msg_text'],
- 'msg_html' => $template['msg_html'],
- 'workflow_id' => $template['workflow_id'],
- 'is_default' => $template['is_default'],
- 'is_reserved' => $template['is_reserved'],
+ 'msg_title' => 'title',
+ 'msg_subject' => 'subject',
+ 'msg_text' => 'text',
+ 'msg_html' => 'html',
+ 'workflow_name' => 'friend',
];
}
- public function tearDown(): void {
- parent::tearDown();
- unset(CRM_Core_Config::singleton()->userPermissionClass->permissions);
- }
-
/**
* Test create function succeeds.
*/
- public function testCreate() {
+ public function testCreate(): void {
$result = $this->callAPIAndDocument('MessageTemplate', 'create', $this->params, __FUNCTION__, __FILE__);
$this->getAndCheck($this->params, $result['id'], $this->entity);
}
* Add extra checks for any 'special' return values or
* behaviours
*/
- public function testGet() {
- $result = $this->callAPIAndDocument('MessageTemplate', 'get', $this->params, __FUNCTION__, __FILE__);
+ public function testGet(): void {
+ $result = $this->callAPIAndDocument('MessageTemplate', 'get', [
+ 'workflow_name' => 'contribution_invoice_receipt',
+ 'is_default' => 1,
+ ], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
}
/**
* Check the delete function succeeds.
*/
- public function testDelete() {
- $entity = $this->createTestEntity();
- $result = $this->callAPIAndDocument('MessageTemplate', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
+ public function testDelete(): void {
+ $entity = $this->createTestEntity('MessageTemplate', $this->params);
+ $this->callAPIAndDocument('MessageTemplate', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->entity, 'get', [
'id' => $entity['id'],
]);
/**
* If you give workflow_id, then workflow_name should also be set.
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testWorkflowIdToName() {
- $wfName = 'uf_notify';
- $wfId = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_option_value WHERE name = %1', [
- 1 => [$wfName, 'String'],
+ public function testWorkflowIDToName(): void {
+ $workflowName = 'uf_notify';
+ $workflowID = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_option_value WHERE name = %1', [
+ 1 => [$workflowName, 'String'],
]);
$created = $this->callAPISuccess('MessageTemplate', 'create', [
'msg_subject' => __FUNCTION__,
'msg_text' => __FUNCTION__,
'msg_html' => __FUNCTION__,
- 'workflow_id' => $wfId,
+ 'workflow_id' => $workflowID,
]);
- $this->assertEquals($wfName, $created['values'][$created['id']]['workflow_name']);
- $this->assertEquals($wfId, $created['values'][$created['id']]['workflow_id']);
+ $this->assertEquals($workflowName, $created['values'][$created['id']]['workflow_name']);
+ $this->assertEquals($workflowID, $created['values'][$created['id']]['workflow_id']);
$get = $this->callAPISuccess('MessageTemplate', 'getsingle', ['id' => $created['id']]);
- $this->assertEquals($wfName, $get['workflow_name']);
- $this->assertEquals($wfId, $get['workflow_id']);
+ $this->assertEquals($workflowName, $get['workflow_name']);
+ $this->assertEquals($workflowID, $get['workflow_id']);
}
/**
* If you give workflow_name, then workflow_id should also be set.
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testWorkflowNameToId() {
- $wfName = 'petition_sign';
- $wfId = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_option_value WHERE name = %1', [
- 1 => [$wfName, 'String'],
+ public function testWorkflowNameToID(): void {
+ $workflowName = 'petition_sign';
+ $workflowID = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_option_value WHERE name = %1', [
+ 1 => ['petition_sign', 'String'],
]);
$created = $this->callAPISuccess('MessageTemplate', 'create', [
'msg_subject' => __FUNCTION__,
'msg_text' => __FUNCTION__,
'msg_html' => __FUNCTION__,
- 'workflow_name' => $wfName,
+ 'workflow_name' => $workflowName,
]);
- $this->assertEquals($wfName, $created['values'][$created['id']]['workflow_name']);
- $this->assertEquals($wfId, $created['values'][$created['id']]['workflow_id']);
+ $this->assertEquals($workflowName, $created['values'][$created['id']]['workflow_name']);
+ $this->assertEquals($workflowID, $created['values'][$created['id']]['workflow_id']);
$get = $this->callAPISuccess('MessageTemplate', 'getsingle', ['id' => $created['id']]);
- $this->assertEquals($wfName, $get['workflow_name']);
- $this->assertEquals($wfId, $get['workflow_id']);
+ $this->assertEquals($workflowName, $get['workflow_name']);
+ $this->assertEquals($workflowID, $get['workflow_id']);
}
- public function testPermissionChecks() {
- $entity = $this->createTestEntity();
+ /**
+ * Test workflow permissions.
+ *
+ * edit message templates allows editing all templates, otherwise:
+ * - edit user-driven message templates is required when workflow_name is not set.
+ * - edit system workflow message templates is required when workflow_name is set.
+ */
+ public function testPermissionChecks(): void {
+ $this->createTestEntity('MessageTemplate', [
+ 'msg_title' => 'title',
+ 'msg_subject' => 'subject',
+ 'msg_html' => 'html',
+ 'workflow_name' => 'friend',
+ ], 'workflow');
+
+ $this->createTestEntity('MessageTemplate', [
+ 'msg_title' => 'title',
+ 'msg_subject' => 'subject',
+ 'msg_html' => 'html',
+ ], 'user');
+
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit user-driven message templates'];
- // Ensure that it cannot create a system message or update a system message tempalte given current permissions.
+ // Attempting to update the workflow template should fail with only user permissions.
$this->callAPIFailure('MessageTemplate', 'create', [
- 'id' => $entity['id'],
+ 'id' => $this->ids['MessageTemplate']['workflow'],
'msg_subject' => 'test msg permission subject',
'check_permissions' => TRUE,
]);
- $testUserEntity = $entity['values'][$entity['id']];
- unset($testUserEntity['id']);
- $testUserEntity['msg_subject'] = 'Test user message template';
- unset($testUserEntity['workflow_id']);
- unset($testUserEntity['workflow_name']);
- $testuserEntity['check_permissions'] = TRUE;
- // ensure that it can create user templates;
- $userEntity = $this->callAPISuccess('MessageTemplate', 'create', $testUserEntity);
+
+ // The user message should be possible to update.
+ $this->callAPISuccess('MessageTemplate', 'create', [
+ 'id' => $this->ids['MessageTemplate']['user'],
+ 'msg_subject' => 'Test user message template',
+ 'check_permissions' => TRUE,
+ ]);
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit system workflow message templates'];
- // Now check that when its swapped around permissions that the correct reponses are detected.
+ // Now check that when its swapped around permissions that the correct responses are detected.
$this->callAPIFailure('MessageTemplate', 'create', [
- 'id' => $userEntity['id'],
+ 'id' => $this->ids['MessageTemplate']['user'],
'msg_subject' => 'User template updated by system message permission',
'check_permissions' => TRUE,
]);
$this->callAPISuccess('MessageTemplate', 'create', [
- 'id' => $entity['id'],
+ 'id' => $this->ids['MessageTemplate']['workflow'],
'msg_subject' => 'test msg permission subject',
'check_permissions' => TRUE,
]);
- $newEntityParams = $entity['values'][$entity['id']];
- unset($newEntityParams['id']);
- $newEntityParams['check_permissions'] = TRUE;
- $this->callAPISuccess('MessageTemplate', 'create', $newEntityParams);
- // verify with all 3 permissions someone can do everything.
+
+ // With both permissions the user can update both template types.
CRM_Core_Config::singleton()->userPermissionClass->permissions = [
'edit system workflow message templates',
'edit user-driven message templates',
];
$this->callAPISuccess('MessageTemplate', 'create', [
- 'id' => $userEntity['id'],
- 'msg_subject' => 'User template updated by system message permission',
+ 'id' => $this->ids['MessageTemplate']['workflow'],
+ 'msg_subject' => 'Workflow template updated',
'check_permissions' => TRUE,
]);
$this->callAPISuccess('MessageTemplate', 'create', [
- 'id' => $entity['id'],
- 'msg_subject' => 'test msg permission subject',
+ 'id' => $this->ids['MessageTemplate']['user'],
+ 'msg_subject' => 'User template updated',
'check_permissions' => TRUE,
]);
- // Verify that the backwards compatabiltiy still works i.e. having edit message templates allows for editing of both kinds of message templates
+
+ // Verify that the backwards compatibility still works i.e. having edit message templates allows for editing of both kinds of message templates
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit message templates'];
- $this->callAPISuccess('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by edit message permission', 'check_permissions' => TRUE]);
- $this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject backwards compatabilty', 'check_permissions' => TRUE]);
+ $this->callAPISuccess('MessageTemplate', 'create', ['id' => $this->ids['MessageTemplate']['workflow'], 'msg_subject' => 'User template updated by edit message permission', 'check_permissions' => TRUE]);
+ $this->callAPISuccess('MessageTemplate', 'create', ['id' => $this->ids['MessageTemplate']['user'], 'msg_subject' => 'test msg permission subject backwards compatibility', 'check_permissions' => TRUE]);
}
}
public function setUp(): void {
$this->params = [
- 'title' => "Pcp title",
+ 'title' => 'Pcp title',
'contact_id' => 1,
'page_id' => 1,
'pcp_block_id' => 1,
/**
* Test create function succeeds.
*/
- public function testCreatePcp() {
+ public function testCreatePcp(): void {
$result = $this->callAPIAndDocument('Pcp', 'create', $this->params,
__FUNCTION__, __FILE__);
$this->getAndCheck($this->params, $result['id'], $this->entity);
/**
* Test disable a PCP succeeds.
*/
- public function testDisablePcp() {
- $result = civicrm_api3('Pcp', 'create', $this->params);
- civicrm_api3('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]);
+ public function testDisablePcp(): void {
+ $result = $this->callAPISuccess('Pcp', 'create', $this->params);
+ $this->callAPISuccess('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]);
$this->getAndCheck($this->params + ['is_active' => 0], $result['id'], $this->entity);
}
* action on create. Add extra checks for any 'special' return values or
* behaviours
*/
- public function testGetPcp() {
- $this->createTestEntity();
+ public function testGetPcp(): void {
+ $this->createTestEntity('PCP', $this->params);
$result = $this->callAPIAndDocument('Pcp', 'get', $this->params,
__FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
/**
* Check the delete function succeeds.
*/
- public function testDeletePcp() {
- $entity = $this->createTestEntity();
+ public function testDeletePcp(): void {
+ $entity = $this->createTestEntity('PCP', $this->params);
$checkCreated = $this->callAPISuccess($this->entity, 'get',
['id' => $entity['id']]);
$this->assertEquals(1, $checkCreated['count']);
* is best put in the $description variable as it will then be displayed in the
* test generated examples. (these are to be found in the api/examples folder).
*/
- public function testGetPcpChainDelete() {
- $description = "Demonstrates get + delete in the same call.";
- $subfile = 'ChainedGetDelete';
- $params = ['title' => "Pcp title", 'api.Pcp.delete' => 1];
+ public function testGetPcpChainDelete(): void {
+ $description = 'Demonstrates get + delete in the same call.';
+ $params = ['title' => 'Pcp title', 'api.Pcp.delete' => 1];
$this->callAPISuccess('Pcp', 'create', $this->params);
$this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__,
- __FILE__, $description, $subfile);
+ __FILE__, $description, 'ChainedGetDelete');
$this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', []));
}
$this->useTransaction();
$this->enableCiviCampaign();
$this->params = [
- 'title' => "survey title",
+ 'title' => 'survey title',
'activity_type_id' => $phoneBankActivityTypeID,
'max_number_of_contacts' => 12,
- 'instructions' => "Call people, ask for money",
+ 'instructions' => 'Call people, ask for money',
];
}
/**
* Test create function succeeds.
*/
- public function testCreateSurvey() {
- $result = $this->callAPIAndDocument('survey', 'create', $this->params, __FUNCTION__, __FILE__);
+ public function testCreateSurvey(): void {
+ $result = $this->callAPIAndDocument('Survey', 'create', $this->params, __FUNCTION__, __FILE__);
$this->getAndCheck($this->params, $result['id'], $this->entity);
}
* action on create. Add extra checks for any 'special' return values or
* behaviours
*/
- public function testGetSurvey() {
- $this->createTestEntity();
- $result = $this->callAPIAndDocument('survey', 'get', $this->params, __FUNCTION__, __FILE__);
+ public function testGetSurvey(): void {
+ $this->createTestEntity('Survey', $this->params);
+ $result = $this->callAPIAndDocument('Survey', 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
}
/**
* Check the delete function succeeds.
*/
- public function testDeleteSurvey() {
- $entity = $this->createTestEntity();
- $result = $this->callAPIAndDocument('survey', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
+ public function testDeleteSurvey(): void {
+ $entity = $this->createTestEntity('Survey', $this->params);
+ $this->callAPIAndDocument('survey', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
* is best put in the $description variable as it will then be displayed in the
* test generated examples. (these are to be found in the api/examples folder).
*/
- public function testGetSurveyChainDelete() {
- $description = "Demonstrates get + delete in the same call.";
- $subfile = 'ChainedGetDelete';
+ public function testGetSurveyChainDelete(): void {
+ $description = 'Demonstrates get + delete in the same call.';
$params = [
- 'title' => "survey title",
+ 'title' => 'survey title',
'api.survey.delete' => 1,
];
- $result = $this->callAPISuccess('survey', 'create', $this->params);
- $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $this->callAPISuccess('Survey', 'create', $this->params);
+ $this->callAPIAndDocument('Survey', 'get', $params, __FUNCTION__, __FILE__, $description, 'ChainedGetDelete');
$this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', []));
}