Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | */ |
18 | ||
19 | ||
19b53e5b C |
20 | namespace api\v4\Spec; |
21 | ||
22 | use Civi\Api4\Service\Spec\FieldSpec; | |
23 | use Civi\Api4\Service\Spec\RequestSpec; | |
24 | use api\v4\UnitTestCase; | |
25 | ||
26 | /** | |
27 | * @group headless | |
28 | */ | |
29 | class RequestSpecTest extends UnitTestCase { | |
30 | ||
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); | |
39 | ||
40 | $requiredFields = $spec->getRequiredFields(); | |
41 | ||
42 | $this->assertCount(1, $requiredFields); | |
43 | $this->assertEquals('name', array_shift($requiredFields)->getName()); | |
44 | } | |
45 | ||
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); | |
52 | ||
53 | $fieldNames = $spec->getFieldNames(); | |
54 | ||
55 | $this->assertCount(2, $fieldNames); | |
56 | $this->assertEquals(['name', 'age'], $fieldNames); | |
57 | } | |
58 | ||
59 | } |