-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APIv4 - Default select clause to exclude "Extra" fields
Recently a "type" property was added to getFieldSpec to allow "Extra" calculated fields to be declared. This updates api Get to *not* select those fields by default, as their calculation can be expensive.
- Loading branch information
Showing
11 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
ext/afform/core/tests/phpunit/Civi/Afform/AfformGetTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace Civi\Afform; | ||
|
||
use Civi\Api4\Afform; | ||
use Civi\Test\HeadlessInterface; | ||
use Civi\Test\TransactionalInterface; | ||
|
||
/** | ||
* @group headless | ||
*/ | ||
class AfformGetTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, TransactionalInterface { | ||
|
||
private $formName = 'abc_123_test'; | ||
|
||
public function setUpHeadless() { | ||
return \Civi\Test::headless()->installMe(__DIR__)->apply(); | ||
} | ||
|
||
public function tearDown(): void { | ||
Afform::revert(FALSE)->addWhere('name', '=', $this->formName)->execute(); | ||
parent::tearDown(); | ||
} | ||
|
||
public function testGetReturnFields() { | ||
Afform::create() | ||
->addValue('name', $this->formName) | ||
->addValue('title', 'Test Form') | ||
->execute(); | ||
|
||
// Omitting select should return regular fields but not extra fields | ||
$result = Afform::get() | ||
->addWhere('name', '=', $this->formName) | ||
->execute()->single(); | ||
$this->assertEquals($this->formName, $result['name']); | ||
$this->assertArrayNotHasKey('directive_name', $result); | ||
$this->assertArrayNotHasKey('has_base', $result); | ||
|
||
// Select * should also return regular fields only | ||
$result = Afform::get() | ||
->addSelect('*') | ||
->addWhere('name', '=', $this->formName) | ||
->execute()->single(); | ||
$this->assertEquals($this->formName, $result['name']); | ||
$this->assertArrayNotHasKey('module_name', $result); | ||
$this->assertArrayNotHasKey('has_local', $result); | ||
|
||
// Selecting * and has_base should return core and that one extra field | ||
$result = Afform::get() | ||
->addSelect('*', 'has_base') | ||
->addWhere('name', '=', $this->formName) | ||
->execute()->single(); | ||
$this->assertEquals($this->formName, $result['name']); | ||
$this->assertFalse($result['has_base']); | ||
$this->assertArrayNotHasKey('has_local', $result); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters