Cleanup test, ensure events are declared as translatable for test
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 27 Jul 2022 15:49:04 +0000 (16:49 +0100)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 2 Aug 2022 02:35:56 +0000 (14:35 +1200)
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

tests/phpunit/api/v4/Entity/TranslationTest.php

index 6fc707e9615f6cf2d78ed4a256b5d3bd0dacd1ca..cd9be2b33c54fdc0d876b61fad2aa59ee751c933 100644 (file)
 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;
+  }
+
 }