3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Tests for the generic validate API action.
15 * @package CiviCRM_APIv3
18 class api_v3_ValidateTest
extends CiviUnitTestCase
{
21 * This method is called before a test is executed.
23 protected function setUp() {
27 public function testEmptyContactValidate() {
28 $validation = $this->callAPISuccess('Contact', 'validate', ['action' => "create"]);
31 'message' => "Mandatory key(s) missing from params array: contact_type",
32 'code' => "mandatory_missing",
35 $this->assertEquals($validation['values'][0], $expectedOut);
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",
46 'message' => "Mandatory key(s) missing from params array: contact_id",
47 'code' => "mandatory_missing",
50 $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors);
51 $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors);
54 public function testContributionDateValidate() {
57 'financial_type_id' => "1",
58 'total_amount' => "100",
60 'receive_date' => 'abc',
62 $validation = $this->callAPISuccess('Contribution', 'validate', $params);
66 'message' => "receive_date is not a valid date: abc",
67 'code' => "incorrect_value",
71 $this->assertEquals($validation['values'][0], $expectedOut);