Cleanup test, ensure events are declared as translatable for test
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / TranslationTest.php
index 730d00d3d5c296d7bf75773409c7164957d97492..cd9be2b33c54fdc0d876b61fad2aa59ee751c933 100644 (file)
 
 namespace api\v4\Entity;
 
-use api\v4\UnitTestCase;
+use api\v4\Api4TestBase;
+use Civi\Core\HookInterface;
+use Civi\Test\TransactionalInterface;
 
 /**
  * @group headless
  */
-class TranslationTest extends UnitTestCase {
+class TranslationTest extends Api4TestBase implements TransactionalInterface, HookInterface {
 
   protected $ids = [];
 
-  public function getCreateOKExamples() {
+  public function getCreateOKExamples(): array {
     $es = [];
 
     $es['asDraft'] = [
@@ -131,7 +133,7 @@ class TranslationTest extends UnitTestCase {
     return $es;
   }
 
-  public function getUpdateBadExamples() {
+  public function getUpdateBadExamples(): array {
     $createOk = $this->getCreateOKExamples()['asDraft'][0];
     $bads = $this->getCreateBadExamples();
 
@@ -149,10 +151,15 @@ class TranslationTest extends UnitTestCase {
   }
 
   /**
+   * 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,
@@ -169,11 +176,12 @@ class TranslationTest extends UnitTestCase {
 
   /**
    * @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', [
@@ -196,7 +204,7 @@ class TranslationTest extends UnitTestCase {
    * @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,
@@ -233,4 +241,14 @@ class TranslationTest extends UnitTestCase {
     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;
+  }
+
 }