From 0132298baf563b5f6cfdaf2689678a2d4ffd2f79 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 27 Jul 2022 16:49:04 +0100 Subject: [PATCH] Cleanup test, ensure events are declared as translatable for test This test should not have been passing prior to this... it needed the event fields declared as translatable but we got away with it until we didn't --- .../phpunit/api/v4/Entity/TranslationTest.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/api/v4/Entity/TranslationTest.php b/tests/phpunit/api/v4/Entity/TranslationTest.php index 6fc707e961..cd9be2b33c 100644 --- a/tests/phpunit/api/v4/Entity/TranslationTest.php +++ b/tests/phpunit/api/v4/Entity/TranslationTest.php @@ -20,16 +20,17 @@ namespace api\v4\Entity; use api\v4\Api4TestBase; +use Civi\Core\HookInterface; use Civi\Test\TransactionalInterface; /** * @group headless */ -class TranslationTest extends Api4TestBase implements TransactionalInterface { +class TranslationTest extends Api4TestBase implements TransactionalInterface, HookInterface { protected $ids = []; - public function getCreateOKExamples() { + public function getCreateOKExamples(): array { $es = []; $es['asDraft'] = [ @@ -132,7 +133,7 @@ class TranslationTest extends Api4TestBase implements TransactionalInterface { return $es; } - public function getUpdateBadExamples() { + public function getUpdateBadExamples(): array { $createOk = $this->getCreateOKExamples()['asDraft'][0]; $bads = $this->getCreateBadExamples(); @@ -150,10 +151,15 @@ class TranslationTest extends Api4TestBase implements TransactionalInterface { } /** + * Test valid creation. + * * @dataProvider getCreateOKExamples + * * @param array $record + * + * @throws \API_Exception */ - public function testCreateOK($record) { + public function testCreateOK(array $record): void { $record = $this->fillRecord($record); $createResults = \civicrm_api4('Translation', 'create', [ 'checkPermissions' => FALSE, @@ -170,11 +176,12 @@ class TranslationTest extends Api4TestBase implements TransactionalInterface { /** * @dataProvider getCreateBadExamples + * * @param array $record * @param string $errorRegex * Regular expression to compare against the error message. */ - public function testCreateBad($record, $errorRegex) { + public function testCreateBad(array $record, string $errorRegex): void { $record = $this->fillRecord($record); try { \civicrm_api4('Translation', 'create', [ @@ -197,7 +204,7 @@ class TranslationTest extends Api4TestBase implements TransactionalInterface { * @throws \API_Exception * @throws \Civi\API\Exception\NotImplementedException */ - public function testUpdateBad($createRecord, $badUpdate, $errorRegex) { + public function testUpdateBad($createRecord, $badUpdate, $errorRegex): void { $record = $this->fillRecord($createRecord); $createResults = \civicrm_api4('Translation', 'create', [ 'checkPermissions' => FALSE, @@ -234,4 +241,14 @@ class TranslationTest extends Api4TestBase implements TransactionalInterface { return $record; } + /** + * Mark these fields as translatable. + * + * @see CRM_Utils_Hook::translateFields + */ + public static function hook_civicrm_translateFields(&$fields): void { + $fields['civicrm_event']['description'] = TRUE; + $fields['civicrm_event']['title'] = TRUE; + } + } -- 2.25.1