Merge pull request #14974 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / api / v3 / PcpTest.php
CommitLineData
b025fef8 1<?php
2
3/*
4 * +--------------------------------------------------------------------+
2fe49090 5 * | CiviCRM version 5 |
b025fef8 6 * +--------------------------------------------------------------------+
6b83d5bd 7 * | Copyright CiviCRM LLC (c) 2004-2019 |
b025fef8 8 * +--------------------------------------------------------------------+
ebf91a5a
SL
9 * | This file is a part of CiviCRM. |
10 * | |
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. |
14 * | |
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. |
19 * | |
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 |
b025fef8 26 * +--------------------------------------------------------------------+
27 */
28
29/**
30 * Test APIv3 civicrm_PCP_* functions
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Campaign
34 */
35
36/**
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
40 *
41 * Failure tests should be added for specific api behaviours but note that
42 * many generic patterns are tested in the syntax conformance test
43 *
44 * @author eileen
efc37755 45 *
46 * @group headless
b025fef8 47 */
48class api_v3_PcpTest extends CiviUnitTestCase {
49 protected $params;
50 protected $entity = 'Pcp';
51 public $DBResetRequired = TRUE;
52
53 public function setUp() {
9099cab3 54 $this->params = [
efc37755 55 'title' => "Pcp title",
56 'contact_id' => 1,
57 'page_id' => 1,
39b959db 58 'pcp_block_id' => 1,
9099cab3 59 ];
b025fef8 60 parent::setUp();
61 }
62
63 /**
64 * Test create function succeeds.
65 */
66 public function testCreatePcp() {
efc37755 67 $result = $this->callAPIAndDocument('Pcp', 'create', $this->params,
b025fef8 68 __FUNCTION__, __FILE__);
69 $this->getAndCheck($this->params, $result['id'], $this->entity);
70 }
71
8168545f
SM
72 /**
73 * Test disable a PCP succeeds.
74 */
75 public function testDisablePcp() {
76 $result = civicrm_api3('Pcp', 'create', $this->params);
9099cab3
CW
77 civicrm_api3('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]);
78 $this->getAndCheck($this->params + ['is_active' => 0], $result['id'], $this->entity);
8168545f
SM
79 }
80
b025fef8 81 /**
82 * Test get function succeeds.
83 *
84 * This is actually largely tested in the get
85 * action on create. Add extra checks for any 'special' return values or
86 * behaviours
87 */
88 public function testGetPcp() {
89 $this->createTestEntity();
efc37755 90 $result = $this->callAPIAndDocument('Pcp', 'get', $this->params,
b025fef8 91 __FUNCTION__, __FILE__);
92 $this->assertEquals(1, $result['count']);
93 $this->assertNotNull($result['values'][$result['id']]['id']);
94 }
95
96 /**
97 * Check the delete function succeeds.
98 */
99 public function testDeletePcp() {
100 $entity = $this->createTestEntity();
efc37755 101 $checkCreated = $this->callAPISuccess($this->entity, 'get',
9099cab3 102 ['id' => $entity['id']]);
b025fef8 103 $this->assertEquals(1, $checkCreated['count']);
3c27d467 104 $this->callAPIAndDocument('Pcp', 'delete',
9099cab3 105 ['id' => $entity['id']], __FUNCTION__, __FILE__);
efc37755 106 $checkDeleted = $this->callAPISuccess($this->entity, 'get',
9099cab3 107 ['id' => $entity['id']]);
b025fef8 108 $this->assertEquals(0, $checkDeleted['count']);
109 }
110
111 /**
112 * Test & document chained delete pattern.
113 *
114 * Note that explanation of the pattern
115 * is best put in the $description variable as it will then be displayed in the
116 * test generated examples. (these are to be found in the api/examples folder).
117 */
118 public function testGetPcpChainDelete() {
119 $description = "Demonstrates get + delete in the same call.";
120 $subfile = 'ChainedGetDelete';
9099cab3 121 $params = ['title' => "Pcp title", 'api.Pcp.delete' => 1];
3c27d467 122 $this->callAPISuccess('Pcp', 'create', $this->params);
123 $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__,
b025fef8 124 __FILE__, $description, $subfile);
9099cab3 125 $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', []));
b025fef8 126 }
efc37755 127
128}