Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / ValidateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Tests for the generic validate API action.
14 *
15 * @package CiviCRM_APIv3
16 * @group headless
17 */
18 class api_v3_ValidateTest extends CiviUnitTestCase {
19
20 /**
21 * This method is called before a test is executed.
22 */
23 protected function setUp() {
24 parent::setUp();
25 }
26
27 public function testEmptyContactValidate() {
28 $validation = $this->callAPISuccess('Contact', 'validate', ['action' => "create"]);
29 $expectedOut = [
30 'contact_type' => [
31 'message' => "Mandatory key(s) missing from params array: contact_type",
32 'code' => "mandatory_missing",
33 ],
34 ];
35 $this->assertEquals($validation['values'][0], $expectedOut);
36 }
37
38 public function testContributionValidate() {
39 $validation = $this->callAPISuccess('Contribution', 'validate', ['action' => "create", 'total_amount' => "100w"]);
40 $totalAmountErrors = [
41 'message' => "total_amount is not a valid amount: 100w",
42 'code' => "incorrect_value",
43 ];
44
45 $contactIdErrors = [
46 'message' => "Mandatory key(s) missing from params array: contact_id",
47 'code' => "mandatory_missing",
48 ];
49
50 $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors);
51 $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors);
52 }
53
54 public function testContributionDateValidate() {
55 $params = [
56 'action' => "create",
57 'financial_type_id' => "1",
58 'total_amount' => "100",
59 'contact_id' => "1",
60 'receive_date' => 'abc',
61 ];
62 $validation = $this->callAPISuccess('Contribution', 'validate', $params);
63
64 $expectedOut = [
65 'receive_date' => [
66 'message' => "receive_date is not a valid date: abc",
67 'code' => "incorrect_value",
68 ],
69 ];
70
71 $this->assertEquals($validation['values'][0], $expectedOut);
72 }
73
74 }