public function testListContactStateAttributes()
 {
     RedBeanModel::forgetAll();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $allAttributes = ApiRestTestHelper::getModelAttributes(new ContactState());
     $response = $this->createApiCallWithRelativeUrl('listAttributes/', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals($allAttributes, $response['data']['items']);
 }
예제 #2
0
 protected function login($username = '******', $password = '******', $type = 'json')
 {
     $headers = array('Accept: application/' . $type, 'ZURMO_AUTH_USERNAME: '******'ZURMO_AUTH_PASSWORD: '******'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/zurmo/api/login', 'POST', $headers);
     if ($type == 'json') {
         $response = json_decode($response, true);
     } elseif ($type == 'xml') {
         $response = XML2Array::createArray($response);
     }
     if ($response['status'] == ApiResponse::STATUS_SUCCESS) {
         return $response['data'];
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * @depends testApiServerUrl
  */
 public function testLanguage()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $model = new ApiTestModelItem2();
     $model->name = 'sample name';
     $this->assertTrue($model->save());
     $headers = array('Accept: application/json', 'ZURMO_API_REQUEST_TYPE: REST', 'ZURMO_LANG: fr');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/api/testModelItem2/api/read/2/', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('Sign in required.', $response['message']);
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST', 'ZURMO_LANG: fr');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/api/testModelItem2/api/read/2/', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('The ID specified was invalid.', $response['message']);
 }
예제 #4
0
 /**
  * @depends testApiServerUrl
  */
 public function testListCurrencies()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $currencies = Currency::getAll();
     $compareData = array();
     foreach ($currencies as $currency) {
         $redBeanModelToApiDataUtil = new RedBeanModelToApiDataUtil($currency);
         $compareData[] = $redBeanModelToApiDataUtil->getData();
     }
     //Test List
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/zurmo/currency/api/list/', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(count($currencies), count($response['data']['items']));
     $this->assertEquals(count($currencies), $response['data']['totalCount']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($compareData, $response['data']['items']);
 }
예제 #5
0
 /**
  * @depends testApiServerUrl
  */
 public function testEditMeetingWIthIncorrectDataType()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $meeting = MeetingTestHelper::createMeetingByNameForOwner('Newest Meeting', $super);
     // Provide data with wrong type.
     $data['startDateTime'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/create/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals(2, count($response['errors']));
     $id = $meeting->id;
     $data = array();
     $data['startDateTime'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/update/' . $id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals(1, count($response['errors']));
 }
 public function testLogout()
 {
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/zurmo/api/logout', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
 }
예제 #7
0
 protected function createApiCallWithRelativeUrl($relativeUrl, $method, $headers, $data = array())
 {
     $baseUrl = $this->getBaseApiUrl();
     $url = $baseUrl . $relativeUrl;
     return ApiRestTestHelper::createApiCall($url, $method, $headers, $data);
 }
 public function testNotAllowedGuestAction()
 {
     $authenticationData = $this->login('st', 'st');
     $headers = array('Accept: application/xml', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createXmlApiCall($this->serverUrl . '/test.php/accounts/account/api/read/1', 'GET', $headers);
     $response = XML2Array::createArray($response);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('Sign in required.', $response['message']);
 }
예제 #9
0
 /**
  * @depends testApiServerUrl
  */
 public function testGetCustomFieldData()
 {
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     //Fill some data
     $values = array('Prospect', 'Customer', 'Vendor');
     $typeFieldData = CustomFieldData::getByName('AccountTypes');
     $typeFieldData->serializedData = serialize($values);
     $this->assertTrue($typeFieldData->save());
     CustomFieldData::forgetAll();
     $customFieldData = CustomFieldData::getByName('AccountTypes');
     $compareData = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, 'en');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/zurmo/customField/api/read/AccountTypes', 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals($compareData, $response['data']);
 }
 /**
  * @depends testCustomListAction
  */
 public function testCustomDeleteAction()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $testModels = ApiTestModelItem2::getByName('new name 2');
     $this->assertEquals(1, count($testModels));
     //Test Delete
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/api/testModelItem2/api/customDelete/?id=' . $testModels[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/api/testModelItem2/api/customGet/?id=' . $testModels[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
 }