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