From: colemanw Date: Fri, 13 Oct 2023 02:42:56 +0000 (-0400) Subject: Afform - Test cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=69939ea624c554d09c74b303a93906bf41d31970;p=civicrm-core.git Afform - Test cleanup --- diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php index ade9f0c09c..54c721ef66 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformAutocompleteUsageTest.php @@ -1,7 +1,12 @@ 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(); diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php index 2457fb510b..b3f8c63075 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformContactUsageTest.php @@ -1,6 +1,6 @@ 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(); diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php index e1e848a208..f572a35c35 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformCustomFieldUsageTest.php @@ -1,5 +1,10 @@ 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') diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php index fa706c1cb3..cd51151122 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php @@ -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') diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php index 936eb8ed56..f99602750f 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformPrefillUsageTest.php @@ -1,5 +1,7 @@ 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'); diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php index bb12c0e857..1d6a07b8fa 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformRelationshipUsageTest.php @@ -1,6 +1,9 @@ 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() diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php index 9e609605c6..01118ef23e 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformRoutingTest.php @@ -1,5 +1,7 @@ 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') diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php index c087e8ba73..a408249e51 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php @@ -1,4 +1,6 @@ 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' => '
The bare file says ""
']) ->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']); } diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php b/ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php index 9e121c5e72..2e9b7b30bc 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformUsageTestCase.php @@ -1,5 +1,7 @@ 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();