3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_survey_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Campaign
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
24 * Failure tests should be added for specific api behaviours but note that
25 * many generic patterns are tested in the syntax conformance test
31 class api_v3_SurveyTest
extends CiviUnitTestCase
{
33 protected $entity = 'survey';
34 public $DBResetRequired = FALSE;
36 public function setUp() {
37 $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', [
38 'label' => 'PhoneBank',
41 $this->useTransaction();
42 $this->enableCiviCampaign();
44 'title' => "survey title",
45 'activity_type_id' => $phoneBankActivityTypeID,
46 'max_number_of_contacts' => 12,
47 'instructions' => "Call people, ask for money",
53 * Test create function succeeds.
55 public function testCreateSurvey() {
56 $result = $this->callAPIAndDocument('survey', 'create', $this->params
, __FUNCTION__
, __FILE__
);
57 $this->getAndCheck($this->params
, $result['id'], $this->entity
);
61 * Test get function succeeds.
63 * This is actually largely tested in the get
64 * action on create. Add extra checks for any 'special' return values or
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']);
75 * Check the delete function succeeds.
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']);
85 * Test & document chained delete pattern.
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).
91 public function testGetSurveyChainDelete() {
92 $description = "Demonstrates get + delete in the same call.";
93 $subfile = 'ChainedGetDelete';
95 'title' => "survey title",
96 'api.survey.delete' => 1,
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', []));