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 * Test APIv3 civicrm_PCP_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Campaign
20 * All API should contain at minimum a success test for each
21 * function - in this case - create, get & delete
22 * In addition any extra functionality should be tested & documented
24 * Failure tests should be added for specific api behaviours but note that
25 * many generic patterns are tested in the syntax conformance test
31 class api_v3_PcpTest
extends CiviUnitTestCase
{
33 protected $entity = 'Pcp';
34 public $DBResetRequired = TRUE;
36 public function setUp() {
38 'title' => "Pcp title",
47 * Test create function succeeds.
49 public function testCreatePcp() {
50 $result = $this->callAPIAndDocument('Pcp', 'create', $this->params
,
51 __FUNCTION__
, __FILE__
);
52 $this->getAndCheck($this->params
, $result['id'], $this->entity
);
56 * Test disable a PCP succeeds.
58 public function testDisablePcp() {
59 $result = civicrm_api3('Pcp', 'create', $this->params
);
60 civicrm_api3('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]);
61 $this->getAndCheck($this->params +
['is_active' => 0], $result['id'], $this->entity
);
65 * Test get function succeeds.
67 * This is actually largely tested in the get
68 * action on create. Add extra checks for any 'special' return values or
71 public function testGetPcp() {
72 $this->createTestEntity();
73 $result = $this->callAPIAndDocument('Pcp', 'get', $this->params
,
74 __FUNCTION__
, __FILE__
);
75 $this->assertEquals(1, $result['count']);
76 $this->assertNotNull($result['values'][$result['id']]['id']);
80 * Check the delete function succeeds.
82 public function testDeletePcp() {
83 $entity = $this->createTestEntity();
84 $checkCreated = $this->callAPISuccess($this->entity
, 'get',
85 ['id' => $entity['id']]);
86 $this->assertEquals(1, $checkCreated['count']);
87 $this->callAPIAndDocument('Pcp', 'delete',
88 ['id' => $entity['id']], __FUNCTION__
, __FILE__
);
89 $checkDeleted = $this->callAPISuccess($this->entity
, 'get',
90 ['id' => $entity['id']]);
91 $this->assertEquals(0, $checkDeleted['count']);
95 * Test & document chained delete pattern.
97 * Note that explanation of the pattern
98 * is best put in the $description variable as it will then be displayed in the
99 * test generated examples. (these are to be found in the api/examples folder).
101 public function testGetPcpChainDelete() {
102 $description = "Demonstrates get + delete in the same call.";
103 $subfile = 'ChainedGetDelete';
104 $params = ['title' => "Pcp title", 'api.Pcp.delete' => 1];
105 $this->callAPISuccess('Pcp', 'create', $this->params
);
106 $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__
,
107 __FILE__
, $description, $subfile);
108 $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', []));