Merge pull request #13926 from pradpnayak/NoticeErrorProfile
[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() {
efc37755 54 $this->params = array(
55 'title' => "Pcp title",
56 'contact_id' => 1,
57 'page_id' => 1,
58 'pcp_block_id' => 1);
b025fef8 59 parent::setUp();
60 }
61
62 /**
63 * Test create function succeeds.
64 */
65 public function testCreatePcp() {
efc37755 66 $result = $this->callAPIAndDocument('Pcp', 'create', $this->params,
b025fef8 67 __FUNCTION__, __FILE__);
68 $this->getAndCheck($this->params, $result['id'], $this->entity);
69 }
70
8168545f
SM
71 /**
72 * Test disable a PCP succeeds.
73 */
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);
78 }
79
b025fef8 80 /**
81 * Test get function succeeds.
82 *
83 * This is actually largely tested in the get
84 * action on create. Add extra checks for any 'special' return values or
85 * behaviours
86 */
87 public function testGetPcp() {
88 $this->createTestEntity();
efc37755 89 $result = $this->callAPIAndDocument('Pcp', 'get', $this->params,
b025fef8 90 __FUNCTION__, __FILE__);
91 $this->assertEquals(1, $result['count']);
92 $this->assertNotNull($result['values'][$result['id']]['id']);
93 }
94
95 /**
96 * Check the delete function succeeds.
97 */
98 public function testDeletePcp() {
99 $entity = $this->createTestEntity();
efc37755 100 $checkCreated = $this->callAPISuccess($this->entity, 'get',
101 array('id' => $entity['id']));
b025fef8 102 $this->assertEquals(1, $checkCreated['count']);
3c27d467 103 $this->callAPIAndDocument('Pcp', 'delete',
efc37755 104 array('id' => $entity['id']), __FUNCTION__, __FILE__);
105 $checkDeleted = $this->callAPISuccess($this->entity, 'get',
106 array('id' => $entity['id']));
b025fef8 107 $this->assertEquals(0, $checkDeleted['count']);
108 }
109
110 /**
111 * Test & document chained delete pattern.
112 *
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).
116 */
117 public function testGetPcpChainDelete() {
118 $description = "Demonstrates get + delete in the same call.";
119 $subfile = 'ChainedGetDelete';
efc37755 120 $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1);
3c27d467 121 $this->callAPISuccess('Pcp', 'create', $this->params);
122 $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__,
b025fef8 123 __FILE__, $description, $subfile);
efc37755 124 $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array()));
b025fef8 125 }
efc37755 126
127}