Skip to content

Commit

Permalink
dev/core#2199: Use ufgroup id and hook method name in test message fo…
Browse files Browse the repository at this point in the history
…r 'delete' op
  • Loading branch information
lucky091588 committed Nov 27, 2020
1 parent aa1bbf9 commit 0b97519
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions tests/phpunit/CRM/Core/BAO/UFGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ public function implementHookPre($op, $objectName, $id, &$params) {
}
elseif ($op == 'delete') {
$systemLog = $this->callAPISuccess('SystemLog', 'create', [
'message' => 'nasdfeiasdfl',
'message' => "CRM_Core_BAO_UFGroupTest::implementHookPre $id",
'level' => 'info',
]);
}
}
}

public function implementHookPost($op, $objectName, $objectId, &$objectRef) {
if ($objectName == 'UFGroup') {
if ($op == 'create') {
$objectRef->is_active = 0;
}
elseif ($op == 'delete') {
$systemLog = $this->callAPISuccess('SystemLog', 'create', [
'message' => "CRM_Core_BAO_UFGroupTest::implementHookPost $objectId",
'level' => 'info',
]);
}
Expand Down Expand Up @@ -46,29 +60,16 @@ public function testPreHookIsCalledForDelete() {
'is_active' => 1,
];
$ufGroup = CRM_Core_BAO_UFGroup::add($params);
$ufGroup = CRM_Core_BAO_UFGroup::del($ufGroup->id);
$ufGroupID = $ufGroup->id;
$ufGroup = CRM_Core_BAO_UFGroup::del($ufGroupID);

// Assert that pre hook implemntation was called for delete op.
$systemLogCount = $this->callAPISuccess('SystemLog', 'getcount', [
'message' => 'nasdfeiasdfl',
'message' => "CRM_Core_BAO_UFGroupTest::implementHookPre $ufGroupID",
'level' => 'info',
]);

$this->assertEquals(1, $systemLogCount, 'There should be one system log entry with message "nasdfeiasdfl"');
}

public function implementHookPost($op, $objectName, $objectId, &$objectRef) {
if ($objectName == 'UFGroup') {
if ($op == 'create') {
$objectRef->is_active = 0;
}
elseif ($op == 'delete') {
$systemLog = $this->callAPISuccess('SystemLog', 'create', [
'message' => 'nasdfeiasd23',
'level' => 'info',
]);
}
}
$this->assertEquals(1, $systemLogCount, 'There should be one system log entry with message "CRM_Core_BAO_UFGroupTest::implementHookPre ' . $ufGroupID . '"');
}

public function testPostHookIsCalledForCreate() {
Expand All @@ -93,15 +94,16 @@ public function testPostHookIsCalledForDelete() {
'is_active' => 1,
];
$ufGroup = CRM_Core_BAO_UFGroup::add($params);
$ufGroup = CRM_Core_BAO_UFGroup::del($ufGroup->id);
$ufGroupID = $ufGroup->id;
$ufGroup = CRM_Core_BAO_UFGroup::del($ufGroupID);

// Assert that pre hook implemntation was called for delete op.
$systemLogCount = $this->callAPISuccess('SystemLog', 'getcount', [
'message' => 'nasdfeiasd23',
'message' => "CRM_Core_BAO_UFGroupTest::implementHookPost $ufGroupID",
'level' => 'info',
]);

$this->assertEquals(1, $systemLogCount, 'There should be one system log entry with message "nasdfeiasd23"');
$this->assertEquals(1, $systemLogCount, 'There should be one system log entry with message "CRM_Core_BAO_UFGroupTest::implementHookPost ' . $ufGroupID . '"');
}

}

0 comments on commit 0b97519

Please sign in to comment.