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