0a25ac6c4067d0c92a31757d4c62a0853bc0ad16
[civicrm-core.git] / tests / phpunit / api / v3 / ValidateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Tests for the generic validate API action.
30 *
31 * @package CiviCRM_APIv3
32 * @group headless
33 */
34 class api_v3_ValidateTest extends CiviUnitTestCase {
35
36 /**
37 * This method is called before a test is executed.
38 */
39 protected function setUp() {
40 parent::setUp();
41 }
42
43 public function testEmptyContactValidate() {
44 $validation = $this->callAPISuccess('Contact', 'validate', array('action' => "create"));
45 $expectedOut = array(
46 'contact_type' => array(
47 'message' => "Mandatory key(s) missing from params array: contact_type",
48 'code' => "mandatory_missing",
49 ),
50 );
51 $this->assertEquals($validation['values'][0], $expectedOut);
52 }
53
54 public function testContributionValidate() {
55 $validation = $this->callAPISuccess('Contribution', 'validate', array('action' => "create", 'total_amount' => "100w"));
56 $totalAmountErrors = array(
57 'message' => "total_amount is not a valid amount: 100w",
58 'code' => "incorrect_value",
59 );
60
61 $contactIdErrors = array(
62 'message' => "Mandatory key(s) missing from params array: contact_id",
63 'code' => "mandatory_missing",
64 );
65
66 $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors);
67 $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors);
68 }
69
70 public function testContributionDateValidate() {
71 $params = array(
72 'action' => "create",
73 'financial_type_id' => "1",
74 'total_amount' => "100",
75 'contact_id' => "1",
76 'receive_date' => 'abc',
77 );
78 $validation = $this->callAPISuccess('Contribution', 'validate', $params);
79
80 $expectedOut = array(
81 'receive_date' => array(
82 'message' => "receive_date is not a valid date: abc",
83 'code' => "incorrect_value",
84 ),
85 );
86
87 $this->assertEquals($validation['values'][0], $expectedOut);
88 }
89
90 }