Merge pull request #956 from kurund/fix-gendata
[civicrm-core.git] / tests / phpunit / api / v3 / SurveyTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31 /**
32 * Test APIv3 civicrm_survey_* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Campaign
36 */
37
38 require_once 'CiviTest/CiviUnitTestCase.php';
39 class api_v3_SurveyTest extends CiviUnitTestCase {
40 protected $_apiversion;
41 protected $params;
42 protected $id;
43 public $DBResetRequired = FALSE;
44
45 function setUp() {
46 $this->_apiversion = 3;
47 $phoneBankActivity = civicrm_api('Option_value', 'Get', array('label' => 'PhoneBank', 'version' => $this->_apiversion, 'sequential' => 1));
48 $phoneBankActivityTypeID = $phoneBankActivity['values'][0]['value'];
49 $this->params = array(
50 'version' => 3,
51 'title' => "survey title",
52 'activity_type_id' => $phoneBankActivityTypeID,
53 'max_number_of_contacts' => 12,
54 'instructions' => "Call people, ask for money",
55 );
56 parent::setUp();
57 }
58
59 function tearDown() {}
60
61 public function testCreateSurvey() {
62 $result = civicrm_api('survey', 'create', $this->params);
63 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
64 $this->assertAPISuccess($result, 'In line ' . __LINE__);
65 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
66 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
67 }
68
69 public function testGetSurvey() {
70
71 $result = civicrm_api('survey', 'get', $this->params);
72 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
73 $this->assertAPISuccess($result, 'In line ' . __LINE__);
74 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
75 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
76 $this->id = $result['id'];
77 }
78
79 public function testDeleteSurvey() {
80 $entity = civicrm_api('survey', 'get', $this->params);
81 $result = civicrm_api('survey', 'delete', array('version' => 3, 'id' => $entity['id']));
82 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
83 $this->assertAPISuccess($result, 'In line ' . __LINE__);
84 $checkDeleted = civicrm_api('survey', 'get', array(
85 'version' => 3,
86 ));
87 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
88 }
89
90 public function testGetSurveyChainDelete() {
91 $description = "demonstrates get + delete in the same call";
92 $subfile = 'ChainedGetDelete';
93 $params = array(
94 'version' => 3,
95 'title' => "survey title",
96 'api.survey.delete' => 1,
97 );
98 $result = civicrm_api('survey', 'create', $this->params);
99 $result = civicrm_api('survey', 'get', $params);
100 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
101 $this->assertAPISuccess($result, 'In line ' . __LINE__);
102 $this->assertEquals(0, civicrm_api('survey', 'getcount', array('version' => 3)), 'In line ' . __LINE__);
103 }
104 }
105