Skip to content

Commit

Permalink
Apiv4 - Test fixes after moving component api files to extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed May 15, 2023
1 parent d616e55 commit 7323840
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
10 changes: 5 additions & 5 deletions CRM/Upgrade/Incremental/php/FiveSixtyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Contribution;
use Civi\Api4\MappingField;

/**
Expand Down Expand Up @@ -129,10 +128,11 @@ public static function convertMappingFieldsToApi4StyleNames(): bool {
'contribution_check_number' => 'check_number',
'contribution_campaign_id' => 'campaign_id',
];
$apiv4 = Contribution::getFields(FALSE)->addWhere('custom_field_id', '>', 0)->execute();
foreach ($apiv4 as $apiv4Field) {
$fieldMap['custom_' . $apiv4Field['custom_field_id']] = $apiv4Field['name'];
}
$fieldMap += CRM_Core_DAO::executeQuery('
SELECT CONCAT("custom_", fld.id) AS old, CONCAT(grp.name, ".", fld.name) AS new
FROM civicrm_custom_field fld, civicrm_custom_group grp
WHERE grp.id = fld.custom_group_id AND grp.extends = "Contribution"
')->fetchMap('old', 'new');

// Update the mapped fields.
foreach ($mappings as $mapping) {
Expand Down
20 changes: 9 additions & 11 deletions tests/phpunit/api/v4/Entity/ConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public function tearDown(): void {
* @throws \CRM_Core_Exception
*/
public function getEntitiesHitech(): array {
// Ensure all components are enabled so their entities show up
foreach (array_keys(\CRM_Core_Component::getComponents()) as $component) {
\CRM_Core_BAO_ConfigSetting::enableComponent($component);
}
return $this->toDataProviderArray(Entity::get(FALSE)->execute()->column('name'));
}

Expand All @@ -102,20 +98,22 @@ public function getEntitiesHitech(): array {
* @return array
*/
public function getEntitiesLotech(): array {
// TODO: Auto-scan required core extensions like search_kit
$manual['add'] = ['SearchDisplay', 'SearchSegment'];
// Core + required core extensions
$directores = ['', 'ext/search_kit/', 'ext/civi_*/'];
$manual['remove'] = ['CustomValue'];
$manual['transform'] = ['CiviCase' => 'Case'];

$scanned = [];
$srcDir = dirname(__DIR__, 5);
foreach ((array) glob("$srcDir/Civi/Api4/*.php") as $name) {
$fileName = basename($name, '.php');
$scanned[] = $manual['transform'][$fileName] ?? $fileName;
$baseDir = dirname(__DIR__, 5);
foreach ($directores as $directory) {
foreach ((array) glob("$baseDir/{$directory}Civi/Api4/*.php") as $name) {
$fileName = basename($name, '.php');
$scanned[] = $manual['transform'][$fileName] ?? $fileName;
}
}

$names = array_diff(
array_unique(array_merge($scanned, $manual['add'])),
$scanned,
$manual['remove']
);

Expand Down
10 changes: 0 additions & 10 deletions tests/phpunit/api/v4/Entity/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace api\v4\Entity;

use Civi\API\Exception\NotImplementedException;
use Civi\Api4\Entity;
use api\v4\Api4TestBase;

Expand Down Expand Up @@ -60,15 +59,6 @@ public function testEntityComponent() {
$this->assertArrayNotHasKey('Participant', $result,
"Entity::get should not have Participant when CiviEvent disabled");

// Trying to use a CiviEvent API will fail when component is disabled
try {
\Civi\Api4\Participant::get(FALSE)->execute();
$this->fail();
}
catch (NotImplementedException $e) {
$this->assertStringContainsString('CiviEvent', $e->getMessage());
}

\CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
$result = Entity::get(FALSE)
->execute()
Expand Down

0 comments on commit 7323840

Please sign in to comment.