From 56fec8be6bcfea321351d59285b8edf981a8d38b Mon Sep 17 00:00:00 2001 From: colemanw Date: Wed, 18 Oct 2023 10:11:45 -0400 Subject: [PATCH] APIv4 - Add unit test to ensure is_active field consitency --- tests/phpunit/api/v4/Entity/ConformanceTest.php | 7 +++++++ tests/phpunit/api/v4/Spec/SpecGathererTest.php | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/api/v4/Entity/ConformanceTest.php b/tests/phpunit/api/v4/Entity/ConformanceTest.php index ee9f0a8d18..7c656b61f6 100644 --- a/tests/phpunit/api/v4/Entity/ConformanceTest.php +++ b/tests/phpunit/api/v4/Entity/ConformanceTest.php @@ -182,6 +182,7 @@ class ConformanceTest extends Api4TestBase implements HookInterface { protected function checkFields($entityName) { $fields = civicrm_api4($entityName, 'getFields', [ 'checkPermissions' => FALSE, + 'action' => 'create', 'where' => [['type', '=', 'Field']], ])->indexBy('name'); @@ -193,6 +194,12 @@ class ConformanceTest extends Api4TestBase implements HookInterface { // Hmm, not true of every primary key... what about Afform.name? $this->assertEquals('Integer', $fields[$idField]['data_type']); + // The underlying schema is not 100% consistent, but this is the standard in APIv4 + if (isset($fields['is_active'])) { + $this->assertTrue($fields['is_active']['default_value']); + $this->assertFalse($fields['is_active']['required']); + } + // Ensure that the getFields (FieldSpec) format is generally consistent. foreach ($fields as $field) { $isNotNull = function($v) { diff --git a/tests/phpunit/api/v4/Spec/SpecGathererTest.php b/tests/phpunit/api/v4/Spec/SpecGathererTest.php index f879af8c18..04de1c46a4 100644 --- a/tests/phpunit/api/v4/Spec/SpecGathererTest.php +++ b/tests/phpunit/api/v4/Spec/SpecGathererTest.php @@ -65,11 +65,4 @@ class SpecGathererTest extends Api4TestBase { $this->assertContains('foo', $fieldNames); } - public function testIsActiveFieldCanDefaultToFalse(): void { - $gatherer = new SpecGatherer(); - // Use Dashboard as it has is_active field and that defaults to 0 (according to schema) - $specs = $gatherer->getSpec('Dashboard', 'create', FALSE); - self::assertFalse($specs->getFieldByName('is_active')->getDefaultValue(), 'Default value for "is_active" field is not false'); - } - } -- 2.25.1