Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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'; | |
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 | 51 | class api_v3_SurveyTest extends CiviUnitTestCase { |
6a488035 | 52 | protected $params; |
fbda92d3 | 53 | protected $entity = 'survey'; |
430ae6dd | 54 | public $DBResetRequired = FALSE; |
fbda92d3 | 55 | public $_eNoticeCompliant = TRUE; |
430ae6dd TO |
56 | |
57 | function setUp() { | |
fbda92d3 | 58 | $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', array('label' => 'PhoneBank', 'return' => 'id'), 'integer'); |
6a488035 | 59 | $this->params = array( |
6a488035 TO |
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 | ||
fbda92d3 | 68 | /** |
69 | * Here we clean up any test data we created. | |
70 | * Note that the quickCleanup function turns off Foreign keys first | |
71 | * so will not remove related entities | |
72 | */ | |
73 | function tearDown() { | |
74 | $tablesToTruncate = array('civicrm_survey'); | |
75 | $this->quickCleanup($tablesToTruncate); | |
76 | } | |
6a488035 | 77 | |
fbda92d3 | 78 | /** |
79 | * test create function succeeds | |
80 | */ | |
6a488035 | 81 | public function testCreateSurvey() { |
fbda92d3 | 82 | $result = $this->callAPIAndDocument('survey', 'create', $this->params, __FUNCTION__, __FILE__); |
83 | $this->getAndCheck($this->params, $result['id'], $this->entity); | |
6a488035 TO |
84 | } |
85 | ||
fbda92d3 | 86 | /** |
87 | * Test get function succeeds (this is actually largely tested in the get | |
88 | * action on create. Add extra checks for any 'special' return values or | |
89 | * behaviours | |
90 | * | |
91 | */ | |
6a488035 | 92 | public function testGetSurvey() { |
fbda92d3 | 93 | $this->createTestEntity(); |
94 | $result = $this->callAPIAndDocument('survey', 'get', $this->params, __FUNCTION__, __FILE__); | |
6a488035 TO |
95 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
96 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); | |
6a488035 TO |
97 | } |
98 | ||
fbda92d3 | 99 | /** |
100 | * Check the delete function succeeds | |
101 | */ | |
6a488035 | 102 | public function testDeleteSurvey() { |
fbda92d3 | 103 | $entity = $this->createTestEntity(); |
104 | $result = $this->callAPIAndDocument('survey', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); | |
105 | $checkDeleted = $this->callAPISuccess($this->entity, 'get', array( | |
6a488035 TO |
106 | )); |
107 | $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__); | |
108 | } | |
109 | ||
fbda92d3 | 110 | /** |
111 | * test & document chained delete pattern. Note that explanation of the pattern | |
112 | * is best put in the $description variable as it will then be displayed in the | |
113 | * test generated examples. (these are to be found in the api/examples folder) | |
114 | * | |
115 | */ | |
6a488035 TO |
116 | public function testGetSurveyChainDelete() { |
117 | $description = "demonstrates get + delete in the same call"; | |
118 | $subfile = 'ChainedGetDelete'; | |
119 | $params = array( | |
6a488035 TO |
120 | 'title' => "survey title", |
121 | 'api.survey.delete' => 1, | |
122 | ); | |
fbda92d3 | 123 | $result = $this->callAPISuccess('survey', 'create', $this->params); |
124 | $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); | |
7fbb4198 | 125 | $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array()), 'In line ' . __LINE__); |
6a488035 | 126 | } |
fbda92d3 | 127 | |
6a488035 TO |
128 | } |
129 |