Merge pull request #17294 from agh1/sr-rel-perms
[civicrm-core.git] / tests / phpunit / api / v3 / SurveyTest.php
1 <?php
2 /*
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test APIv3 civicrm_survey_* 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
28 *
29 * @group headless
30 */
31 class api_v3_SurveyTest extends CiviUnitTestCase {
32 protected $params;
33 protected $entity = 'survey';
34 public $DBResetRequired = FALSE;
35
36 public function setUp() {
37 $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', [
38 'label' => 'PhoneBank',
39 'return' => 'value',
40 ], 'integer');
41 $this->useTransaction();
42 $this->enableCiviCampaign();
43 $this->params = [
44 'title' => "survey title",
45 'activity_type_id' => $phoneBankActivityTypeID,
46 'max_number_of_contacts' => 12,
47 'instructions' => "Call people, ask for money",
48 ];
49 parent::setUp();
50 }
51
52 /**
53 * Test create function succeeds.
54 */
55 public function testCreateSurvey() {
56 $result = $this->callAPIAndDocument('survey', 'create', $this->params, __FUNCTION__, __FILE__);
57 $this->getAndCheck($this->params, $result['id'], $this->entity);
58 }
59
60 /**
61 * Test get function succeeds.
62 *
63 * This is actually largely tested in the get
64 * action on create. Add extra checks for any 'special' return values or
65 * behaviours
66 */
67 public function testGetSurvey() {
68 $this->createTestEntity();
69 $result = $this->callAPIAndDocument('survey', 'get', $this->params, __FUNCTION__, __FILE__);
70 $this->assertEquals(1, $result['count']);
71 $this->assertNotNull($result['values'][$result['id']]['id']);
72 }
73
74 /**
75 * Check the delete function succeeds.
76 */
77 public function testDeleteSurvey() {
78 $entity = $this->createTestEntity();
79 $result = $this->callAPIAndDocument('survey', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
80 $checkDeleted = $this->callAPISuccess($this->entity, 'get', []);
81 $this->assertEquals(0, $checkDeleted['count']);
82 }
83
84 /**
85 * Test & document chained delete pattern.
86 *
87 * Note that explanation of the pattern
88 * is best put in the $description variable as it will then be displayed in the
89 * test generated examples. (these are to be found in the api/examples folder).
90 */
91 public function testGetSurveyChainDelete() {
92 $description = "Demonstrates get + delete in the same call.";
93 $subfile = 'ChainedGetDelete';
94 $params = [
95 'title' => "survey title",
96 'api.survey.delete' => 1,
97 ];
98 $result = $this->callAPISuccess('survey', 'create', $this->params);
99 $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
100 $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', []));
101 }
102
103 }