Merge pull request #5536 from totten/4.5-httpclient
[civicrm-core.git] / tests / phpunit / api / v3 / SurveyTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31/**
32 * Test APIv3 civicrm_survey_* functions
33 *
92915c55
TO
34 * @package CiviCRM_APIv3
35 * @subpackage API_Campaign
6a488035
TO
36 */
37
38require_once 'CiviTest/CiviUnitTestCase.php';
fbda92d3 39
40/**
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
44 *
45 * Failure tests should be added for specific api behaviours but note that
46 * many generic patterns are tested in the syntax conformance test
47 *
48 * @author eileen
49 *
50 */
6a488035 51class api_v3_SurveyTest extends CiviUnitTestCase {
6a488035 52 protected $params;
fbda92d3 53 protected $entity = 'survey';
430ae6dd 54 public $DBResetRequired = FALSE;
b7c9bc4c 55
430ae6dd 56
00be9182 57 public function setUp() {
92915c55
TO
58 $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', array(
59 'label' => 'PhoneBank',
acb1052e 60 'return' => 'value',
92915c55 61 ), 'integer');
0c250cae 62 $this->useTransaction();
9ce17194 63 $this->enableCiviCampaign();
6a488035 64 $this->params = array(
6a488035
TO
65 'title' => "survey title",
66 'activity_type_id' => $phoneBankActivityTypeID,
67 'max_number_of_contacts' => 12,
68 'instructions' => "Call people, ask for money",
69 );
70 parent::setUp();
71 }
72
fbda92d3 73 /**
eceb18cc 74 * Test create function succeeds.
fbda92d3 75 */
6a488035 76 public function testCreateSurvey() {
fbda92d3 77 $result = $this->callAPIAndDocument('survey', 'create', $this->params, __FUNCTION__, __FILE__);
78 $this->getAndCheck($this->params, $result['id'], $this->entity);
6a488035
TO
79 }
80
fbda92d3 81 /**
fe482240
EM
82 * Test get function succeeds.
83 *
84 * This is actually largely tested in the get
fbda92d3 85 * action on create. Add extra checks for any 'special' return values or
86 * behaviours
fbda92d3 87 */
6a488035 88 public function testGetSurvey() {
fbda92d3 89 $this->createTestEntity();
90 $result = $this->callAPIAndDocument('survey', 'get', $this->params, __FUNCTION__, __FILE__);
6a488035
TO
91 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
92 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
6a488035
TO
93 }
94
6c6e6187 95 /**
eceb18cc 96 * Check the delete function succeeds.
6c6e6187 97 */
6a488035 98 public function testDeleteSurvey() {
fbda92d3 99 $entity = $this->createTestEntity();
100 $result = $this->callAPIAndDocument('survey', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
6c6e6187 101 $checkDeleted = $this->callAPISuccess($this->entity, 'get', array());
6a488035
TO
102 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
103 }
104
fbda92d3 105 /**
fe482240
EM
106 * Test & document chained delete pattern.
107 *
108 * Note that explanation of the pattern
fbda92d3 109 * is best put in the $description variable as it will then be displayed in the
fe482240 110 * test generated examples. (these are to be found in the api/examples folder).
fbda92d3 111 */
6a488035 112 public function testGetSurveyChainDelete() {
5c49fee0 113 $description = "Demonstrates get + delete in the same call.";
92915c55
TO
114 $subfile = 'ChainedGetDelete';
115 $params = array(
6a488035
TO
116 'title' => "survey title",
117 'api.survey.delete' => 1,
118 );
fbda92d3 119 $result = $this->callAPISuccess('survey', 'create', $this->params);
120 $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
7fbb4198 121 $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array()), 'In line ' . __LINE__);
6a488035 122 }
fbda92d3 123
6a488035 124}