Merge pull request #9570 from colemanw/CRM-19773-report
[civicrm-core.git] / tests / phpunit / api / v3 / PcpTest.php
1 <?php
2
3 /*
4 * +--------------------------------------------------------------------+
5 * | CiviCRM version 4.7 |
6 * +--------------------------------------------------------------------+
7 * | Copyright CiviCRM LLC (c) 2004-2017 |
8 * +--------------------------------------------------------------------+
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 |
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
45 *
46 * @group headless
47 */
48 class api_v3_PcpTest extends CiviUnitTestCase {
49 protected $params;
50 protected $entity = 'Pcp';
51 public $DBResetRequired = TRUE;
52
53 public function setUp() {
54 $this->params = array(
55 'title' => "Pcp title",
56 'contact_id' => 1,
57 'page_id' => 1,
58 'pcp_block_id' => 1);
59 parent::setUp();
60 }
61
62 /**
63 * Test create function succeeds.
64 */
65 public function testCreatePcp() {
66 $result = $this->callAPIAndDocument('Pcp', 'create', $this->params,
67 __FUNCTION__, __FILE__);
68 $this->getAndCheck($this->params, $result['id'], $this->entity);
69 }
70
71 /**
72 * Test get function succeeds.
73 *
74 * This is actually largely tested in the get
75 * action on create. Add extra checks for any 'special' return values or
76 * behaviours
77 */
78 public function testGetPcp() {
79 $this->createTestEntity();
80 $result = $this->callAPIAndDocument('Pcp', 'get', $this->params,
81 __FUNCTION__, __FILE__);
82 $this->assertEquals(1, $result['count']);
83 $this->assertNotNull($result['values'][$result['id']]['id']);
84 }
85
86 /**
87 * Check the delete function succeeds.
88 */
89 public function testDeletePcp() {
90 $entity = $this->createTestEntity();
91 $checkCreated = $this->callAPISuccess($this->entity, 'get',
92 array('id' => $entity['id']));
93 $this->assertEquals(1, $checkCreated['count']);
94 $this->callAPIAndDocument('Pcp', 'delete',
95 array('id' => $entity['id']), __FUNCTION__, __FILE__);
96 $checkDeleted = $this->callAPISuccess($this->entity, 'get',
97 array('id' => $entity['id']));
98 $this->assertEquals(0, $checkDeleted['count']);
99 }
100
101 /**
102 * Test & document chained delete pattern.
103 *
104 * Note that explanation of the pattern
105 * is best put in the $description variable as it will then be displayed in the
106 * test generated examples. (these are to be found in the api/examples folder).
107 */
108 public function testGetPcpChainDelete() {
109 $description = "Demonstrates get + delete in the same call.";
110 $subfile = 'ChainedGetDelete';
111 $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1);
112 $this->callAPISuccess('Pcp', 'create', $this->params);
113 $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__,
114 __FILE__, $description, $subfile);
115 $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array()));
116 }
117
118 }