Afform - Test cleanup
authorcolemanw <coleman@civicrm.org>
Fri, 13 Oct 2023 02:42:56 +0000 (22:42 -0400)
committercolemanw <coleman@civicrm.org>
Fri, 13 Oct 2023 02:42:56 +0000 (22:42 -0400)
ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformTest.php
ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php

index ade9f0c09cf54598f391fb24bf4213db73e5b6bf..54c721ef669107e1db3a809579a56d7a53b36022 100644 (file)
@@ -1,7 +1,12 @@
 <?php
 
+use Civi\Api4\Afform;
 use Civi\Api4\Contact;
+use Civi\Api4\CustomField;
+use Civi\Api4\CustomGroup;
+use Civi\Api4\Group;
 use Civi\Api4\GroupContact;
+use Civi\Api4\SavedSearch;
 
 /**
  * Test case for Afform with autocomplete.
@@ -32,7 +37,7 @@ EOHTML;
     ]);
 
     // Saved search for filtering
-    \Civi\Api4\SavedSearch::create(FALSE)
+    SavedSearch::create(FALSE)
       ->setValues([
         'name' => 'the_unit_test_search',
         'label' => 'the_unit_test_search',
@@ -84,7 +89,7 @@ EOHTML;
       ],
     ];
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setValues($values)
         ->execute();
@@ -96,7 +101,7 @@ EOHTML;
 
     // Submit with a valid ID, it should work
     $values['Individual1'][0]['fields']['id'] = $contacts['B'];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -126,17 +131,17 @@ EOHTML;
       ->execute()->indexBy('first_name')->column('id');
 
     // Place contacts A & B in the group, but not contact C
-    $group = \Civi\Api4\Group::create(FALSE)
+    $group = Group::create(FALSE)
       ->addValue('name', $lastName)
       ->addValue('title', $lastName)
       ->addChain('A', GroupContact::create()->addValue('group_id', '$id')->addValue('contact_id', $contacts['A']))
       ->addChain('B', GroupContact::create()->addValue('group_id', '$id')->addValue('contact_id', $contacts['B']))
       ->execute()->single();
 
-    \Civi\Api4\CustomGroup::create(FALSE)
+    CustomGroup::create(FALSE)
       ->addValue('title', 'test_af_fields')
       ->addValue('extends', 'Contact')
-      ->addChain('fields', \Civi\Api4\CustomField::save()
+      ->addChain('fields', CustomField::save()
         ->addDefault('custom_group_id', '$id')
         ->setRecords([
           ['label' => 'contact_ref', 'data_type' => 'ContactReference', 'html_type' => 'Autocomplete', 'filter' => 'action=get&group=' . $group['id']],
@@ -184,7 +189,7 @@ EOHTML;
       ],
     ];
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setValues($values)
         ->execute();
@@ -196,7 +201,7 @@ EOHTML;
 
     // Submit with a valid ID, it should work
     $values['Individual1'][0]['fields']['test_af_fields.contact_ref'] = $contacts['B'];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -224,10 +229,10 @@ EOHTML;
       ->setRecords($sampleData)
       ->execute()->indexBy('first_name')->column('id');
 
-    \Civi\Api4\CustomGroup::create(FALSE)
+    CustomGroup::create(FALSE)
       ->addValue('title', 'test_address_fields')
       ->addValue('extends', 'Address')
-      ->addChain('fields', \Civi\Api4\CustomField::save()
+      ->addChain('fields', CustomField::save()
         ->addDefault('custom_group_id', '$id')
         ->setRecords([
           ['label' => 'contact_ref', 'data_type' => 'ContactReference', 'html_type' => 'Autocomplete', 'filter' => 'action=get&source=in'],
@@ -282,7 +287,7 @@ EOHTML;
       ],
     ];
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setValues($values)
         ->execute();
@@ -294,7 +299,7 @@ EOHTML;
 
     // Submit with a valid ID, it should work
     $values['Individual1'][0]['joins']['Address'][0]['test_address_fields.contact_ref'] = $contacts['A'];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
index 2457fb510b3df6c29015eae0b9def0fe5573b8e5..b3f8c6307553e756f7f07d88e0424ca3df11e256 100644 (file)
@@ -1,6 +1,6 @@
 <?php
-require_once __DIR__ . '/AfformTestCase.php';
-require_once __DIR__ . '/AfformUsageTestCase.php';
+
+use Civi\Api4\Afform;
 
 /**
  * Test case for Afform.prefill and Afform.submit.
@@ -87,7 +87,7 @@ EOHTML;
     CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
 
     // Autofill form with current user. See `Civi\Afform\Behavior\ContactAutofill`
-    $prefill = Civi\Api4\Afform::prefill()
+    $prefill = Afform::prefill()
       ->setName($this->formName)
       ->execute()
       ->indexBy('name');
@@ -98,7 +98,7 @@ EOHTML;
       ['fields' => ['first_name' => 'Firsty', 'last_name' => 'Lasty']],
     ];
 
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues(['me' => $submission])
       ->execute();
@@ -115,7 +115,7 @@ EOHTML;
     ]);
 
     // Get states for USA
-    $result = Civi\Api4\Afform::getOptions()
+    $result = Afform::getOptions()
       ->setName($this->formName)
       ->setModelName('me')
       ->setFieldName('state_province_id')
@@ -125,7 +125,7 @@ EOHTML;
     $this->assertEquals('Alabama', $result[0]['label']);
 
     // Get states for UK
-    $result = Civi\Api4\Afform::getOptions()
+    $result = Afform::getOptions()
       ->setName($this->formName)
       ->setModelName('me')
       ->setFieldName('state_province_id')
@@ -165,7 +165,7 @@ EOHTML;
         ],
       ],
     ];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -208,7 +208,7 @@ EOHTML;
     CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
 
     try {
-      Civi\Api4\Afform::prefill()
+      Afform::prefill()
         ->setName($this->formName)
         ->setArgs([])
         ->execute()
@@ -220,7 +220,7 @@ EOHTML;
     }
 
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setArgs([])
         ->setValues([
@@ -262,7 +262,7 @@ EOHTML;
         ],
       ],
     ];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -301,7 +301,7 @@ EOHTML;
         ],
       ],
     ];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -347,7 +347,7 @@ EOHTML;
         ],
       ],
     ];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -415,7 +415,7 @@ EOHTML;
         ],
       ],
     ];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
@@ -448,7 +448,7 @@ EOHTML;
     ];
 
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setValues($values)
         ->execute();
@@ -484,7 +484,7 @@ EOHTML;
     ];
 
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setValues($values)
         ->execute();
@@ -514,26 +514,26 @@ EOHTML;
     ];
 
     // Submit twice
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues(['me' => $submitValues])
       ->execute();
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues(['me' => $submitValues])
       ->execute();
 
     // Autofilling form works because limit hasn't been reached
-    Civi\Api4\Afform::prefill()->setName($this->formName)->execute();
+    Afform::prefill()->setName($this->formName)->execute();
 
     // Last time
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues(['me' => $submitValues])
       ->execute();
 
     // Stats should report that we've reached the submission limit
-    $stats = \Civi\Api4\Afform::get(FALSE)
+    $stats = Afform::get(FALSE)
       ->addSelect('submit_enabled', 'submission_count', 'submit_currently_open')
       ->addWhere('name', '=', $this->formName)
       ->execute()->single();
@@ -543,13 +543,13 @@ EOHTML;
 
     // Prefilling and submitting are no longer allowed.
     try {
-      Civi\Api4\Afform::prefill()->setName($this->formName)->execute();
+      Afform::prefill()->setName($this->formName)->execute();
       $this->fail();
     }
     catch (\Civi\API\Exception\UnauthorizedException $e) {
     }
     try {
-      Civi\Api4\Afform::submit()
+      Afform::submit()
         ->setName($this->formName)
         ->setValues(['me' => $submitValues])
         ->execute();
index e1e848a208d8d8f9f93f352bd17d2f97a8bb1573..f572a35c35aee1817a311495ad991d74421e5232 100644 (file)
@@ -1,5 +1,10 @@
 <?php
 
+use Civi\Api4\Afform;
+use Civi\Api4\Contact;
+use Civi\Api4\CustomField;
+use Civi\Api4\CustomGroup;
+
 /**
  * Test case for Afform.prefill and Afform.submit.
  *
@@ -31,14 +36,14 @@ EOHTML;
    * which can be submitted multiple times
    */
   public function testMultiRecordCustomBlock(): void {
-    \Civi\Api4\CustomGroup::create(FALSE)
+    CustomGroup::create(FALSE)
       ->addValue('name', 'MyThings')
       ->addValue('title', 'My Things')
       ->addValue('style', 'Tab with table')
       ->addValue('extends', 'Contact')
       ->addValue('is_multiple', TRUE)
       ->addValue('max_multiple', 2)
-      ->addChain('fields', \Civi\Api4\CustomField::save()
+      ->addChain('fields', CustomField::save()
         ->addDefault('custom_group_id', '$id')
         ->setRecords([
           ['name' => 'my_text', 'label' => 'My Text', 'data_type' => 'String', 'html_type' => 'Text'],
@@ -48,7 +53,7 @@ EOHTML;
       ->execute();
 
     // Creating a custom group should automatically create an afform block
-    $block = \Civi\Api4\Afform::get()
+    $block = Afform::get()
       ->addWhere('name', '=', 'afblockCustom_MyThings')
       ->addSelect('layout', 'directive_name')
       ->setLayoutFormat('shallow')
@@ -83,11 +88,11 @@ EOHTML;
         ],
       ],
     ];
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute();
-    $contact = \Civi\Api4\Contact::get(FALSE)
+    $contact = Contact::get(FALSE)
       ->addWhere('first_name', '=', $firstName)
       ->addJoin('Custom_MyThings AS Custom_MyThings', 'LEFT', ['id', '=', 'Custom_MyThings.entity_id'])
       ->addSelect('Custom_MyThings.my_text', 'Custom_MyThings.my_friend')
index fa706c1cb3428d3228728bceb17a67833a354ed6..cd5115112270f50a042b5f6c2b1763ba0e056ca6 100644 (file)
@@ -5,6 +5,12 @@
  *
  * @group headless
  */
+
+use Civi\Api4\Afform;
+use Civi\Api4\Contact;
+use Civi\Api4\CustomField;
+use Civi\Api4\CustomGroup;
+
 require_once __DIR__ . '/AfformTestCase.php';
 require_once __DIR__ . '/AfformUsageTestCase.php';
 class api_v4_AfformFileUploadTest extends api_v4_AfformUsageTestCase {
@@ -38,11 +44,11 @@ EOHTML;
    */
   public function testSubmitFile(): void {
     // Single-value set
-    \Civi\Api4\CustomGroup::create(FALSE)
+    CustomGroup::create(FALSE)
       ->addValue('name', 'MyInfo')
       ->addValue('title', 'My Info')
       ->addValue('extends', 'Contact')
-      ->addChain('fields', \Civi\Api4\CustomField::save()
+      ->addChain('fields', CustomField::save()
         ->addDefault('custom_group_id', '$id')
         ->setRecords([
           ['name' => 'single_file_field', 'label' => 'A File', 'data_type' => 'File', 'html_type' => 'File'],
@@ -51,14 +57,14 @@ EOHTML;
       ->execute();
 
     // Multi-record set
-    \Civi\Api4\CustomGroup::create(FALSE)
+    CustomGroup::create(FALSE)
       ->addValue('name', 'MyFiles')
       ->addValue('title', 'My Files')
       ->addValue('style', 'Tab with table')
       ->addValue('extends', 'Contact')
       ->addValue('is_multiple', TRUE)
       ->addValue('max_multiple', 3)
-      ->addChain('fields', \Civi\Api4\CustomField::save()
+      ->addChain('fields', CustomField::save()
         ->addDefault('custom_group_id', '$id')
         ->setRecords([
           ['name' => 'my_file', 'label' => 'My File', 'data_type' => 'File', 'html_type' => 'File'],
@@ -100,14 +106,14 @@ EOHTML;
         ],
       ],
     ];
-    $submission = Civi\Api4\Afform::submit()
+    $submission = Afform::submit()
       ->setName($this->formName)
       ->setValues($values)
       ->execute()->first();
 
     foreach ([0, 1] as $entityIndex) {
       $this->mockUploadFile();
-      Civi\Api4\Afform::submitFile()
+      Afform::submitFile()
         ->setName($this->formName)
         ->setToken($submission['token'])
         ->setModelName('Individual1')
@@ -117,7 +123,7 @@ EOHTML;
 
       foreach ([0, 1] as $joinIndex) {
         $this->mockUploadFile();
-        Civi\Api4\Afform::submitFile()
+        Afform::submitFile()
           ->setName($this->formName)
           ->setToken($submission['token'])
           ->setModelName('Individual1')
@@ -129,7 +135,7 @@ EOHTML;
       }
     }
 
-    $contacts = \Civi\Api4\Contact::get(FALSE)
+    $contacts = Contact::get(FALSE)
       ->addWhere('last_name', '=', $lastName)
       ->addJoin('Custom_MyFiles AS MyFiles', 'LEFT', ['id', '=', 'MyFiles.entity_id'])
       ->addSelect('first_name', 'MyInfo.single_file_field', 'MyFiles.my_file')
index 936eb8ed567cf3799d9ea5936c7cd262021a35f1..f99602750fed95edb9610e59685d73c33b1e0759 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Api4\Afform;
+
 /**
  * Test case for Afform with autocomplete.
  *
@@ -55,7 +57,7 @@ EOHTML;
       ],
     ]);
 
-    $prefill = Civi\Api4\Afform::prefill()
+    $prefill = Afform::prefill()
       ->setName($this->formName)
       ->setArgs(['Individual1' => $cid])
       ->execute()
@@ -81,7 +83,7 @@ EOHTML;
     $this->assertEmpty($prefill['Individual1']['values'][1]['joins']['Phone']);
 
     // Prefill a specific contact for the af-repeat entity
-    $prefill = Civi\Api4\Afform::prefill()
+    $prefill = Afform::prefill()
       ->setName($this->formName)
       ->setArgs(['Individual1' => [1 => $cid[3]]])
       ->execute()
@@ -93,7 +95,7 @@ EOHTML;
     $this->assertEquals('3-1', $prefill['Individual1']['values'][1]['joins']['Phone'][0]['phone']);
 
     // Form entity has `max="3"` so a forth contact (index 3) is out-of-bounds
-    $prefill = Civi\Api4\Afform::prefill()
+    $prefill = Afform::prefill()
       ->setName($this->formName)
       ->setArgs(['Individual1' => [3 => $cid[0]]])
       ->execute();
@@ -144,7 +146,7 @@ EOHTML;
       civicrm_api4('Relationship', 'create', ['values' => $values]);
     }
 
-    $prefill = Civi\Api4\Afform::prefill()
+    $prefill = Afform::prefill()
       ->setName($this->formName)
       ->execute()
       ->indexBy('name');
index bb12c0e8570580eff5d3c2e00d5c45782736c042..1d6a07b8fa782fe85832d0c8cab9998b9cae1333 100644 (file)
@@ -1,6 +1,9 @@
 <?php
 
+use Civi\Api4\Afform;
+use Civi\Api4\Contact;
 use Civi\Api4\Relationship;
+use Civi\Api4\RelationshipType;
 
 /**
  * Test case for Afform.prefill and Afform.submit.
@@ -46,7 +49,7 @@ EOHTML;
       ],
     ];
 
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($submission)
       ->execute();
@@ -98,7 +101,7 @@ EOHTML;
     $typeIds = [];
 
     foreach ($types as $type) {
-      $typeIds[] = \Civi\Api4\RelationshipType::create(FALSE)
+      $typeIds[] = RelationshipType::create(FALSE)
         ->addValue('contact_type_a', 'Organization')
         ->addValue('contact_type_b', 'Individual')
         ->addValue('name_a_b', $type)
@@ -121,7 +124,7 @@ EOHTML;
       ],
     ];
 
-    Civi\Api4\Afform::submit()
+    Afform::submit()
       ->setName($this->formName)
       ->setValues($submission)
       ->execute();
@@ -162,7 +165,7 @@ EOHTML;
       'permission' => CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION,
     ]);
 
-    $contact = \Civi\Api4\Contact::save(FALSE)
+    $contact = Contact::save(FALSE)
       ->addRecord(['first_name' => 'Child1'])
       ->addRecord(['first_name' => 'Child2', 'is_deleted' => TRUE])
       ->addRecord(['first_name' => 'Parent'])
@@ -181,7 +184,7 @@ EOHTML;
       ->addRecord(['contact_id_a' => $contact[6], 'contact_id_b' => $contact[2], 'relationship_type_id:name' => 'Child of'])
       ->execute();
 
-    $prefill = Civi\Api4\Afform::prefill(FALSE)
+    $prefill = Afform::prefill(FALSE)
       ->setName($this->formName)
       ->setArgs(['Organization1' => $contact[3]])
       ->execute()
index 9e609605c6e3b25c50366f5e576123414bfabbc4..01118ef23ed9ae8af9b563b9764f572e678fdcf3 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Api4\Afform;
+
 /**
  * Ensure that the routes created by Afform are working.
  * @group e2e
@@ -16,7 +18,7 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C
 
   public function setUp(): void {
     parent::setUp();
-    Civi\Api4\Afform::revert()
+    Afform::revert()
       ->setCheckPermissions(FALSE)
       ->addWhere('name', '=', $this->formName)
       ->execute();
@@ -24,7 +26,7 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C
 
   public function tearDown(): void {
     parent::tearDown();
-    Civi\Api4\Afform::revert()
+    Afform::revert()
       ->setCheckPermissions(FALSE)
       ->addWhere('name', '=', $this->formName)
       ->execute();
@@ -39,7 +41,7 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C
     $result = $http->get($url('civicrm/mock-page'));
     $this->assertNotAuthorized($result, 'mock-page');
 
-    Civi\Api4\Afform::update()
+    Afform::update()
       ->setCheckPermissions(FALSE)
       ->addWhere('name', '=', $this->formName)
       ->addValue('permission', CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION)
@@ -55,7 +57,7 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C
       return CRM_Utils_System::url($path, $query, TRUE, NULL, FALSE);
     };
 
-    Civi\Api4\Afform::update()
+    Afform::update()
       ->setCheckPermissions(FALSE)
       ->addWhere('name', '=', $this->formName)
       ->addValue('permission', CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION)
@@ -64,7 +66,7 @@ class api_v4_AfformRoutingTest extends \PHPUnit\Framework\TestCase implements \C
     $this->assertOpensPage($http->get($url('civicrm/mock-page')), 'mock-page');
     $this->assertNotAuthorized($http->get($url('civicrm/mock-page-renamed')), 'mock-page');
 
-    Civi\Api4\Afform::update()
+    Afform::update()
       ->setCheckPermissions(FALSE)
       ->addWhere('name', '=', $this->formName)
       ->addValue('server_route', 'civicrm/mock-page-renamed')
index c087e8ba739b49ccb73080438617d77cf8c6f56d..a408249e51d538e47f5b608ac223a69ddbd62fc3 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+
+use Civi\Api4\Afform;
 use Civi\Api4\Dashboard;
 
 /**
@@ -63,10 +65,10 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
       }
     };
 
-    Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
+    Afform::revert()->addWhere('name', '=', $formName)->execute();
 
     $message = 'The initial Afform.get should return default data';
-    $result = Civi\Api4\Afform::get()
+    $result = Afform::get()
       ->addSelect('*', 'has_base', 'has_local', 'base_module')
       ->addWhere('name', '=', $formName)->execute();
     $this->assertEquals($formName, $result[0]['name'], $message);
@@ -82,7 +84,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
     $checkDashlet($originalMetadata);
 
     $message = 'After updating with Afform.create, the revised data should be returned';
-    $result = Civi\Api4\Afform::update()
+    $result = Afform::update()
       ->addWhere('name', '=', $formName)
       ->addValue('description', 'The temporary description')
       ->addValue('permission', ['access foo', 'access bar'])
@@ -92,7 +94,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
     $this->assertEquals('The temporary description', $result[0]['description'], $message);
 
     $message = 'After updating, the Afform.get API should return blended data';
-    $result = Civi\Api4\Afform::get()
+    $result = Afform::get()
       ->addSelect('*', 'has_base', 'has_local', 'base_module')
       ->addWhere('name', '=', $formName)->execute();
     $this->assertEquals($formName, $result[0]['name'], $message);
@@ -107,9 +109,9 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
     $this->assertEquals('org.civicrm.afform-mock', $get($result[0], 'base_module'), $message);
     $checkDashlet($result[0]);
 
-    Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
+    Afform::revert()->addWhere('name', '=', $formName)->execute();
     $message = 'After reverting, the final Afform.get should return default data';
-    $result = Civi\Api4\Afform::get()
+    $result = Afform::get()
       ->addSelect('*', 'has_base', 'has_local', 'base_module')
       ->addWhere('name', '=', $formName)->execute();
     $this->assertEquals($formName, $result[0]['name'], $message);
@@ -162,7 +164,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
    * @dataProvider getFormatExamples
    */
   public function testBasicConvert($formName, $updateFormat, $updateLayout, $readFormat, $readLayout, $exampleName): void {
-    $actual = Civi\Api4\Afform::convert()->setLayout($updateLayout)
+    $actual = Afform::convert()->setLayout($updateLayout)
       ->setFrom($updateFormat)
       ->setTo($readFormat)
       ->execute();
@@ -205,22 +207,22 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
    * @dataProvider getFormatExamples
    */
   public function testUpdateAndGetFormat($formName, $updateFormat, $updateLayout, $readFormat, $readLayout, $exampleName): void {
-    Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
+    Afform::revert()->addWhere('name', '=', $formName)->execute();
 
-    Civi\Api4\Afform::update()
+    Afform::update()
       ->addWhere('name', '=', $formName)
       ->setLayoutFormat($updateFormat)
       ->setValues(['layout' => $updateLayout])
       ->execute();
 
-    $result = Civi\Api4\Afform::get()
+    $result = Afform::get()
       ->addWhere('name', '=', $formName)
       ->setLayoutFormat($readFormat)
       ->execute();
 
     $this->assertEquals($readLayout, $this->fudgeMarkup($result[0]['layout']), "Based on \"$exampleName\", writing content as \"$updateFormat\" and reading back as \"$readFormat\".");
 
-    Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
+    Afform::revert()->addWhere('name', '=', $formName)->execute();
   }
 
   public function getWhitespaceExamples() {
@@ -241,12 +243,12 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
    * @dataProvider getWhitespaceExamples
    */
   public function testWhitespaceFormat($directiveName, $example, $exampleName): void {
-    Civi\Api4\Afform::save()
+    Afform::save()
       ->addRecord(['name' => $directiveName, 'layout' => $example['html']])
       ->setLayoutFormat('html')
       ->execute();
 
-    $result = Civi\Api4\Afform::get()
+    $result = Afform::get()
       ->addWhere('name', '=', $directiveName)
       ->setLayoutFormat('shallow')
       ->setFormatWhitespace(TRUE)
@@ -255,13 +257,13 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
 
     $this->assertEquals($example['stripped'] ?? $example['shallow'], $this->fudgeMarkup($result['layout']));
 
-    Civi\Api4\Afform::save()
+    Afform::save()
       ->addRecord(['name' => $directiveName, 'layout' => $result['layout']])
       ->setLayoutFormat('shallow')
       ->setFormatWhitespace(TRUE)
       ->execute();
 
-    $result = Civi\Api4\Afform::get()
+    $result = Afform::get()
       ->addWhere('name', '=', $directiveName)
       ->setLayoutFormat('html')
       ->execute()
@@ -275,25 +277,25 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
     $this->createLoggedInUser();
 
     // The default mockPage has 1 explicit requirement + 2 automatic requirements.
-    Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
+    Afform::revert()->addWhere('name', '=', $formName)->execute();
     $angModule = Civi::service('angular')->getModule($formName);
     $this->assertEquals(['afCore', 'mockBespoke', 'mockBareFile', 'mockFoo'], $angModule['requires']);
-    $storedRequires = Civi\Api4\Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
+    $storedRequires = Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
     $this->assertEquals(['mockBespoke'], $storedRequires[0]['requires']);
 
     // Knock down to 1 explicit + 1 automatic.
-    Civi\Api4\Afform::update()
+    Afform::update()
       ->addWhere('name', '=', $formName)
       ->setLayoutFormat('html')
       ->setValues(['layout' => '<div>The bare file says "<mock-bare-file/>"</div>'])
       ->execute();
     $angModule = Civi::service('angular')->getModule($formName);
     $this->assertEquals(['afCore', 'mockBespoke', 'mockBareFile'], $angModule['requires']);
-    $storedRequires = Civi\Api4\Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
+    $storedRequires = Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
     $this->assertEquals(['mockBespoke'], $storedRequires[0]['requires']);
 
     // Remove the last explict and implicit requirements.
-    Civi\Api4\Afform::update()
+    Afform::update()
       ->addWhere('name', '=', $formName)
       ->setLayoutFormat('html')
       ->setValues([
@@ -303,10 +305,10 @@ class api_v4_AfformTest extends api_v4_AfformTestCase {
       ->execute();
     $angModule = Civi::service('angular')->getModule($formName);
     $this->assertEquals(['afCore'], $angModule['requires']);
-    $storedRequires = Civi\Api4\Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
+    $storedRequires = Afform::get()->addWhere('name', '=', $formName)->addSelect('requires')->execute();
     $this->assertEquals([], $storedRequires[0]['requires']);
 
-    Civi\Api4\Afform::revert()->addWhere('name', '=', $formName)->execute();
+    Afform::revert()->addWhere('name', '=', $formName)->execute();
     $angModule = Civi::service('angular')->getModule($formName);
     $this->assertEquals(['afCore', 'mockBespoke', 'mockBareFile', 'mockFoo'], $angModule['requires']);
   }
index 9e121c5e72017b6fceb3d6dbda411ebc1db53ab2..2e9b7b30bc7e35de8eb766323b22ceaa92790e8a 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Api4\Afform;
+
 /**
  * Test case for Afform.prefill and Afform.submit.
  *
@@ -15,14 +17,14 @@ abstract class api_v4_AfformUsageTestCase extends api_v4_AfformTestCase {
 
   public function setUp(): void {
     parent::setUp();
-    Civi\Api4\Afform::revert(FALSE)
+    Afform::revert(FALSE)
       ->addWhere('type', '=', 'block')
       ->execute();
     $this->formName = 'mock' . rand(0, 100000);
   }
 
   public function tearDown(): void {
-    Civi\Api4\Afform::revert(FALSE)
+    Afform::revert(FALSE)
       ->addWhere('name', '=', $this->formName)
       ->execute();
     parent::tearDown();
@@ -34,7 +36,7 @@ abstract class api_v4_AfformUsageTestCase extends api_v4_AfformTestCase {
       'name' => $this->formName,
     ];
     $full = array_merge($defaults, $values);
-    Civi\Api4\Afform::create(FALSE)
+    Afform::create(FALSE)
       ->setLayoutFormat('html')
       ->setValues($full)
       ->execute();