4 * +--------------------------------------------------------------------+
5 * | CiviCRM version 5 |
6 * +--------------------------------------------------------------------+
7 * | Copyright CiviCRM LLC (c) 2004-2019 |
8 * +--------------------------------------------------------------------+
9 * | This file is a part of CiviCRM. |
11 * | CiviCRM is free software; you can copy, modify, and distribute it |
12 * | under the terms of the GNU Affero General Public License |
13 * | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 * | CiviCRM is distributed in the hope that it will be useful, but |
16 * | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 * | See the GNU Affero General Public License for more details. |
20 * | You should have received a copy of the GNU Affero General Public |
21 * | License and the CiviCRM Licensing Exception along |
22 * | with this program; if not, contact CiviCRM LLC |
23 * | at info[AT]civicrm[DOT]org. If you have questions about the |
24 * | GNU Affero General Public License or the licensing of CiviCRM, |
25 * | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 * +--------------------------------------------------------------------+
30 * Test APIv3 civicrm_PCP_* functions
32 * @package CiviCRM_APIv3
33 * @subpackage API_Campaign
37 * All API should contain at minimum a success test for each
38 * function - in this case - create, get & delete
39 * In addition any extra functionality should be tested & documented
41 * Failure tests should be added for specific api behaviours but note that
42 * many generic patterns are tested in the syntax conformance test
48 class api_v3_PcpTest
extends CiviUnitTestCase
{
50 protected $entity = 'Pcp';
51 public $DBResetRequired = TRUE;
53 public function setUp() {
54 $this->params
= array(
55 'title' => "Pcp title",
63 * Test create function succeeds.
65 public function testCreatePcp() {
66 $result = $this->callAPIAndDocument('Pcp', 'create', $this->params
,
67 __FUNCTION__
, __FILE__
);
68 $this->getAndCheck($this->params
, $result['id'], $this->entity
);
72 * Test disable a PCP succeeds.
74 public function testDisablePcp() {
75 $result = civicrm_api3('Pcp', 'create', $this->params
);
76 civicrm_api3('Pcp', 'create', array('id' => $result['id'], 'is_active' => 0));
77 $this->getAndCheck($this->params +
array('is_active' => 0), $result['id'], $this->entity
);
81 * Test get function succeeds.
83 * This is actually largely tested in the get
84 * action on create. Add extra checks for any 'special' return values or
87 public function testGetPcp() {
88 $this->createTestEntity();
89 $result = $this->callAPIAndDocument('Pcp', 'get', $this->params
,
90 __FUNCTION__
, __FILE__
);
91 $this->assertEquals(1, $result['count']);
92 $this->assertNotNull($result['values'][$result['id']]['id']);
96 * Check the delete function succeeds.
98 public function testDeletePcp() {
99 $entity = $this->createTestEntity();
100 $checkCreated = $this->callAPISuccess($this->entity
, 'get',
101 array('id' => $entity['id']));
102 $this->assertEquals(1, $checkCreated['count']);
103 $this->callAPIAndDocument('Pcp', 'delete',
104 array('id' => $entity['id']), __FUNCTION__
, __FILE__
);
105 $checkDeleted = $this->callAPISuccess($this->entity
, 'get',
106 array('id' => $entity['id']));
107 $this->assertEquals(0, $checkDeleted['count']);
111 * Test & document chained delete pattern.
113 * Note that explanation of the pattern
114 * is best put in the $description variable as it will then be displayed in the
115 * test generated examples. (these are to be found in the api/examples folder).
117 public function testGetPcpChainDelete() {
118 $description = "Demonstrates get + delete in the same call.";
119 $subfile = 'ChainedGetDelete';
120 $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1);
121 $this->callAPISuccess('Pcp', 'create', $this->params
);
122 $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__
,
123 __FILE__
, $description, $subfile);
124 $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array()));