APIv4 - Delete unnecessary contact spec provider
authorcolemanw <coleman@civicrm.org>
Wed, 27 Sep 2023 16:19:09 +0000 (12:19 -0400)
committercolemanw <coleman@civicrm.org>
Wed, 27 Sep 2023 16:21:20 +0000 (12:21 -0400)
Civi/Api4/Service/Spec/Provider/ContactCreationSpecProvider.php [deleted file]
tests/phpunit/api/v4/Action/GetFieldsTest.php

diff --git a/Civi/Api4/Service/Spec/Provider/ContactCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/ContactCreationSpecProvider.php
deleted file mode 100644 (file)
index 15cb41c..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved.                        |
- |                                                                    |
- | This work is published under the GNU AGPLv3 license with some      |
- | permitted exceptions and without any warranty. For full license    |
- | and copyright information, see https://civicrm.org/licensing       |
- +--------------------------------------------------------------------+
- */
-
-namespace Civi\Api4\Service\Spec\Provider;
-
-use Civi\Api4\Service\Spec\RequestSpec;
-
-/**
- * @service
- * @internal
- */
-class ContactCreationSpecProvider extends \Civi\Core\Service\AutoService implements Generic\SpecProviderInterface {
-
-  /**
-   * @param \Civi\Api4\Service\Spec\RequestSpec $spec
-   */
-  public function modifySpec(RequestSpec $spec) {
-    $spec->getFieldByName('is_opt_out')->setRequired(FALSE);
-    $spec->getFieldByName('is_deleted')->setRequired(FALSE);
-  }
-
-  /**
-   * @param string $entity
-   * @param string $action
-   *
-   * @return bool
-   */
-  public function applies($entity, $action) {
-    return $entity === 'Contact' && $action === 'create';
-  }
-
-}
index becf8e10271fd7ca5128408b16279f3077f35ef9..b12e26e068821ec5dbd468e48af6a8f7dc23e495 100644 (file)
@@ -60,6 +60,7 @@ class GetFieldsTest extends Api4TestBase implements TransactionalInterface {
 
   public function testContactGetFields(): void {
     $fields = Contact::getFields(FALSE)
+      ->setAction('create')
       ->execute()
       ->indexBy('name');
     // Ensure table & column are returned
@@ -71,6 +72,7 @@ class GetFieldsTest extends Api4TestBase implements TransactionalInterface {
     $this->assertEquals(['name', 'label', 'icon'], $fields['contact_sub_type']['suffixes']);
 
     // Check `required` and `nullable`
+    $this->assertFalse($fields['is_opt_out']['required']);
     $this->assertFalse($fields['is_deleted']['required']);
     $this->assertFalse($fields['is_deleted']['nullable']);
     $this->assertFalse($fields['id']['nullable']);