Skip to content

Commit

Permalink
APIv4 - Add unit test to ensure is_active field consitency
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Oct 18, 2023
1 parent 22e1dbe commit 56fec8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 7 additions & 0 deletions tests/phpunit/api/v4/Entity/ConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ protected function checkEntityInfo($entityClass): void {
protected function checkFields($entityName) {
$fields = civicrm_api4($entityName, 'getFields', [
'checkPermissions' => FALSE,
'action' => 'create',
'where' => [['type', '=', 'Field']],
])->indexBy('name');

Expand All @@ -193,6 +194,12 @@ protected function checkFields($entityName) {
// 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) {
Expand Down
7 changes: 0 additions & 7 deletions tests/phpunit/api/v4/Spec/SpecGathererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,4 @@ public function testWithSpecProvider(): void {
$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');
}

}

0 comments on commit 56fec8b

Please sign in to comment.