From 6bd0e2751e40d7a9e77bdf668bdc858576cac0ba Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 20 Jun 2021 11:14:29 +1200 Subject: [PATCH] Add unit test for event copy --- tests/phpunit/CRM/Core/CopyTest.php | 33 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/CRM/Core/CopyTest.php b/tests/phpunit/CRM/Core/CopyTest.php index dd28d3e221..8829447410 100644 --- a/tests/phpunit/CRM/Core/CopyTest.php +++ b/tests/phpunit/CRM/Core/CopyTest.php @@ -5,11 +5,31 @@ */ class CRM_Core_CopyTest extends CiviUnitTestCase { - public function testEventCopy() { - - $event = $this->eventCreate(); + /** + * Has the test class been verified as 'getsafe'. + * + * If a class is getsafe it means that where + * callApiSuccess is called 'return' is specified or 'return' =>'id' + * can be added by that function. This is part of getting away + * from open-ended get calls. + * + * @var bool + */ + protected $isGetSafe = TRUE; + + use CRMTraits_Custom_CustomDataTrait; + + public function testEventCopy(): void { + + $this->createCustomGroupWithFieldOfType(['extends' => 'Event']); + $event = $this->eventCreate([$this->getCustomFieldName('text') => 'blah']); $eventId = $event['id']; $eventRes = $event['values'][$eventId]; + $params[$this->getCustomFieldName('text') . '_1'] = 'blah'; + $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, + $eventId, + 'Event' + ); $eventCopy = CRM_Event_BAO_Event::copy($eventId); $identicalParams = [ @@ -28,11 +48,12 @@ class CRM_Core_CopyTest extends CiviUnitTestCase { 'is_active', 'is_show_location', 'is_email_confirm', + $this->getCustomFieldName('text'), ]; // same format for better comparison - $eventData = civicrm_api3('Event', 'getsingle', ['id' => $eventId]); - $eventCopy = civicrm_api3('Event', 'getsingle', ['id' => $eventCopy->id]); + $eventData = $this->callAPISuccessGetSingle('Event', ['id' => $eventId, 'return' => array_merge($identicalParams, ['title'])]); + $eventCopy = $this->callAPISuccessGetSingle('Event', ['id' => $eventCopy->id, 'return' => array_merge($identicalParams, ['title'])]); foreach ($identicalParams as $name) { $this->assertEquals($eventCopy[$name], $eventData[$name], "{$name} should be equals between source and copy"); @@ -93,7 +114,7 @@ class CRM_Core_CopyTest extends CiviUnitTestCase { $ploc[$field] = $eventData[$field] . $locSuffix; } - $res = $this->callAPISuccess('Event', 'create', $ploc); + $this->callAPISuccess('Event', 'create', $ploc); } // now that the data is different, do the copy -- 2.25.1