Commit | Line | Data |
---|---|---|
b025fef8 | 1 | <?php |
b025fef8 | 2 | /* |
7d61e75f TO |
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 | +--------------------------------------------------------------------+ | |
b025fef8 | 10 | */ |
11 | ||
12 | /** | |
13 | * Test APIv3 civicrm_PCP_* functions | |
14 | * | |
15 | * @package CiviCRM_APIv3 | |
16 | * @subpackage API_Campaign | |
17 | */ | |
18 | ||
19 | /** | |
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 | |
23 | * | |
24 | * Failure tests should be added for specific api behaviours but note that | |
25 | * many generic patterns are tested in the syntax conformance test | |
26 | * | |
27 | * @author eileen | |
efc37755 | 28 | * |
29 | * @group headless | |
b025fef8 | 30 | */ |
31 | class api_v3_PcpTest extends CiviUnitTestCase { | |
32 | protected $params; | |
33 | protected $entity = 'Pcp'; | |
34 | public $DBResetRequired = TRUE; | |
35 | ||
36 | public function setUp() { | |
9099cab3 | 37 | $this->params = [ |
efc37755 | 38 | 'title' => "Pcp title", |
39 | 'contact_id' => 1, | |
40 | 'page_id' => 1, | |
39b959db | 41 | 'pcp_block_id' => 1, |
9099cab3 | 42 | ]; |
b025fef8 | 43 | parent::setUp(); |
44 | } | |
45 | ||
46 | /** | |
47 | * Test create function succeeds. | |
48 | */ | |
49 | public function testCreatePcp() { | |
efc37755 | 50 | $result = $this->callAPIAndDocument('Pcp', 'create', $this->params, |
b025fef8 | 51 | __FUNCTION__, __FILE__); |
52 | $this->getAndCheck($this->params, $result['id'], $this->entity); | |
53 | } | |
54 | ||
8168545f SM |
55 | /** |
56 | * Test disable a PCP succeeds. | |
57 | */ | |
58 | public function testDisablePcp() { | |
59 | $result = civicrm_api3('Pcp', 'create', $this->params); | |
9099cab3 CW |
60 | civicrm_api3('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]); |
61 | $this->getAndCheck($this->params + ['is_active' => 0], $result['id'], $this->entity); | |
8168545f SM |
62 | } |
63 | ||
b025fef8 | 64 | /** |
65 | * Test get function succeeds. | |
66 | * | |
67 | * This is actually largely tested in the get | |
68 | * action on create. Add extra checks for any 'special' return values or | |
69 | * behaviours | |
70 | */ | |
71 | public function testGetPcp() { | |
72 | $this->createTestEntity(); | |
efc37755 | 73 | $result = $this->callAPIAndDocument('Pcp', 'get', $this->params, |
b025fef8 | 74 | __FUNCTION__, __FILE__); |
75 | $this->assertEquals(1, $result['count']); | |
76 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Check the delete function succeeds. | |
81 | */ | |
82 | public function testDeletePcp() { | |
83 | $entity = $this->createTestEntity(); | |
efc37755 | 84 | $checkCreated = $this->callAPISuccess($this->entity, 'get', |
9099cab3 | 85 | ['id' => $entity['id']]); |
b025fef8 | 86 | $this->assertEquals(1, $checkCreated['count']); |
3c27d467 | 87 | $this->callAPIAndDocument('Pcp', 'delete', |
9099cab3 | 88 | ['id' => $entity['id']], __FUNCTION__, __FILE__); |
efc37755 | 89 | $checkDeleted = $this->callAPISuccess($this->entity, 'get', |
9099cab3 | 90 | ['id' => $entity['id']]); |
b025fef8 | 91 | $this->assertEquals(0, $checkDeleted['count']); |
92 | } | |
93 | ||
94 | /** | |
95 | * Test & document chained delete pattern. | |
96 | * | |
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). | |
100 | */ | |
101 | public function testGetPcpChainDelete() { | |
102 | $description = "Demonstrates get + delete in the same call."; | |
103 | $subfile = 'ChainedGetDelete'; | |
9099cab3 | 104 | $params = ['title' => "Pcp title", 'api.Pcp.delete' => 1]; |
3c27d467 | 105 | $this->callAPISuccess('Pcp', 'create', $this->params); |
106 | $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__, | |
b025fef8 | 107 | __FILE__, $description, $subfile); |
9099cab3 | 108 | $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', [])); |
b025fef8 | 109 | } |
efc37755 | 110 | |
111 | } |