3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test APIv3 civicrm_survey_* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Campaign
38 require_once 'CiviTest/CiviUnitTestCase.php';
41 * All API should contain at minimum a success test for each
42 * function - in this case - create, get & delete
43 * In addition any extra functionality should be tested & documented
45 * Failure tests should be added for specific api behaviours but note that
46 * many generic patterns are tested in the syntax conformance test
51 class api_v3_SurveyTest
extends CiviUnitTestCase
{
53 protected $entity = 'survey';
54 public $DBResetRequired = FALSE;
57 public function setUp() {
58 $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', array(
59 'label' => 'PhoneBank',
62 $this->useTransaction();
63 $this->enableCiviCampaign();
64 $this->params
= array(
65 'title' => "survey title",
66 'activity_type_id' => $phoneBankActivityTypeID,
67 'max_number_of_contacts' => 12,
68 'instructions' => "Call people, ask for money",
74 * Test create function succeeds.
76 public function testCreateSurvey() {
77 $result = $this->callAPIAndDocument('survey', 'create', $this->params
, __FUNCTION__
, __FILE__
);
78 $this->getAndCheck($this->params
, $result['id'], $this->entity
);
82 * Test get function succeeds.
84 * This is actually largely tested in the get
85 * action on create. Add extra checks for any 'special' return values or
88 public function testGetSurvey() {
89 $this->createTestEntity();
90 $result = $this->callAPIAndDocument('survey', 'get', $this->params
, __FUNCTION__
, __FILE__
);
91 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
92 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
96 * Check the delete function succeeds.
98 public function testDeleteSurvey() {
99 $entity = $this->createTestEntity();
100 $result = $this->callAPIAndDocument('survey', 'delete', array('id' => $entity['id']), __FUNCTION__
, __FILE__
);
101 $checkDeleted = $this->callAPISuccess($this->entity
, 'get', array());
102 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
106 * Test & document chained delete pattern.
108 * Note that explanation of the pattern
109 * is best put in the $description variable as it will then be displayed in the
110 * test generated examples. (these are to be found in the api/examples folder).
112 public function testGetSurveyChainDelete() {
113 $description = "Demonstrates get + delete in the same call.";
114 $subfile = 'ChainedGetDelete';
116 'title' => "survey title",
117 'api.survey.delete' => 1,
119 $result = $this->callAPISuccess('survey', 'create', $this->params
);
120 $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
121 $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array()), 'In line ' . __LINE__
);