4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 namespace api\v
4\Spec
;
22 use Civi\Api4\Service\Spec\FieldSpec
;
23 use Civi\Api4\Service\Spec\RequestSpec
;
24 use api\v
4\UnitTestCase
;
29 class RequestSpecTest
extends UnitTestCase
{
31 public function testRequiredFieldFetching() {
32 $spec = new RequestSpec('Contact', 'get');
33 $requiredField = new FieldSpec('name', 'Contact');
34 $requiredField->setRequired(TRUE);
35 $nonRequiredField = new FieldSpec('age', 'Contact', 'Integer');
36 $nonRequiredField->setRequired(FALSE);
37 $spec->addFieldSpec($requiredField);
38 $spec->addFieldSpec($nonRequiredField);
40 $requiredFields = $spec->getRequiredFields();
42 $this->assertCount(1, $requiredFields);
43 $this->assertEquals('name', array_shift($requiredFields)->getName());
46 public function testGettingFieldNames() {
47 $spec = new RequestSpec('Contact', 'get');
48 $nameField = new FieldSpec('name', 'Contact');
49 $ageField = new FieldSpec('age', 'Contact', 'Integer');
50 $spec->addFieldSpec($nameField);
51 $spec->addFieldSpec($ageField);
53 $fieldNames = $spec->getFieldNames();
55 $this->assertCount(2, $fieldNames);
56 $this->assertEquals(['name', 'age'], $fieldNames);