Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ApiRestContactStateTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  public function testGetContactState()
43  {
44  $super = User::getByUsername('super');
45  Yii::app()->user->userModel = $super;
46  $this->assertTrue(ContactsModule::loadStartingData());
47 
48  $authenticationData = $this->login();
49  $headers = array(
50  'Accept: application/json',
51  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
52  'ZURMO_TOKEN: ' . $authenticationData['token'],
53  'ZURMO_API_REQUEST_TYPE: REST',
54  );
55 
56  $contactStates = ContactState::getAll();
57  $this->assertEquals(6, count($contactStates));
58  $compareData = $this->getModelToApiDataUtilData($contactStates[3]);
59 
60  $response = $this->createApiCallWithRelativeUrl('read/' . $compareData['id'], 'GET', $headers);
61  $response = json_decode($response, true);
62  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
63  $this->assertEquals($compareData, $response['data']);
64  }
65 
69  public function testListContactStates()
70  {
71  $super = User::getByUsername('super');
72  Yii::app()->user->userModel = $super;
73 
74  $authenticationData = $this->login();
75  $headers = array(
76  'Accept: application/json',
77  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
78  'ZURMO_TOKEN: ' . $authenticationData['token'],
79  'ZURMO_API_REQUEST_TYPE: REST',
80  );
81 
82  $contactStates = ContactsUtil::getContactStateDataFromStartingStateLabelByLanguage(Yii::app()->language);
83  $compareData = array();
84  foreach ($contactStates as $contactState)
85  {
86  $compareData[] = $this->getModelToApiDataUtilData($contactState);
87  }
88 
89  $response = $this->createApiCallWithRelativeUrl('listContactStates/', 'GET', $headers);
90  $response = json_decode($response, true);
91 
92  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
93  $this->assertEquals(count($compareData), count($response['data']['items']));
94  $this->assertEquals(count($compareData), $response['data']['totalCount']);
95  $this->assertEquals(1, $response['data']['currentPage']);
96  $this->assertEquals($compareData, $response['data']['items']);
97  }
98 
99  public function testListContactStateAttributes()
100  {
102  $super = User::getByUsername('super');
103  Yii::app()->user->userModel = $super;
104 
105  $authenticationData = $this->login();
106  $headers = array(
107  'Accept: application/json',
108  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
109  'ZURMO_TOKEN: ' . $authenticationData['token'],
110  'ZURMO_API_REQUEST_TYPE: REST',
111  );
112  $allAttributes = ApiRestTestHelper::getModelAttributes(new ContactState());
113 
114  $response = $this->createApiCallWithRelativeUrl('listAttributes/' , 'GET', $headers);
115  $response = json_decode($response, true);
116  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
117  $this->assertEquals($allAttributes, $response['data']['items']);
118  }
119 
123  public function testListLeadsStates()
124  {
125  $super = User::getByUsername('super');
126  Yii::app()->user->userModel = $super;
127 
128  $authenticationData = $this->login();
129  $headers = array(
130  'Accept: application/json',
131  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
132  'ZURMO_TOKEN: ' . $authenticationData['token'],
133  'ZURMO_API_REQUEST_TYPE: REST',
134  );
135  $leadStates = LeadsUtil::getLeadStateDataFromStartingStateLabelByLanguage(Yii::app()->language);
136 
137  $compareData = array();
138  foreach ($leadStates as $leadState)
139  {
140  $compareData[] = $this->getModelToApiDataUtilData($leadState);
141  }
142 
143  $response = $this->createApiCallWithRelativeUrl('listLeadStates/', 'GET', $headers);
144  $response = json_decode($response, true);
145 
146  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
147  $this->assertEquals(count($compareData), count($response['data']['items']));
148  $this->assertEquals(count($compareData), $response['data']['totalCount']);
149  $this->assertEquals(1, $response['data']['currentPage']);
150  $this->assertEquals($compareData, $response['data']['items']);
151  }
152 
156  public function testListAllContactStates()
157  {
158  $super = User::getByUsername('super');
159  Yii::app()->user->userModel = $super;
160 
161  $authenticationData = $this->login();
162  $headers = array(
163  'Accept: application/json',
164  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
165  'ZURMO_TOKEN: ' . $authenticationData['token'],
166  'ZURMO_API_REQUEST_TYPE: REST',
167  );
168 
169  $contactStates = ContactState::getAll();
170  $this->assertEquals(6, count($contactStates));
171  foreach ($contactStates as $contactState)
172  {
173  $compareData[] = $this->getModelToApiDataUtilData($contactState);
174  }
175 
176  $response = $this->createApiCallWithRelativeUrl('list/', 'GET', $headers);
177  $response = json_decode($response, true);
178  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
179  $this->assertEquals(6, count($response['data']['items']));
180  $this->assertEquals(6, $response['data']['totalCount']);
181  $this->assertEquals(1, $response['data']['currentPage']);
182  $this->assertEquals($compareData, $response['data']['items']);
183  }
184 
185  protected function getApiControllerClassName()
186  {
187  Yii::import('application.modules.contacts.controllers.ContactStateApiController', true);
188  return 'ContactsContactStateApiController';
189  }
190 
191  protected function getModuleBaseApiUrl()
192  {
193  return 'contacts/contactState/api/';
194  }
195  }
196 ?>
static getByUsername($username)
Definition: User.php:49
static getContactStateDataFromStartingStateLabelByLanguage($language)
static forgetAll()
static getModelAttributes(RedBeanModel $model)
static loadStartingData()
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getLeadStateDataFromStartingStateLabelByLanguage($language)
Definition: LeadsUtil.php:212
Generated on Fri Jul 3 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.