Exemplo n.º 1
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 createMeetingWithRelatedAccount($firstName, $meetingName, $usePastStartDateTime = false)
 {
     $account = AccountTestHelper::createAccountByNameForOwner($firstName, Yii::app()->user->userModel);
     $this->assertNull($account->latestActivityDateTime);
     $meeting = MeetingTestHelper::createMeetingByNameForOwner($meetingName, Yii::app()->user->userModel);
     $meeting->activityItems->add($account);
     if ($usePastStartDateTime) {
         $meeting->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     }
     $this->assertTrue($meeting->save());
     $this->assertNull($meeting->activityItems[0]->latestActivityDateTime);
     $meetingId = $meeting->id;
     $accountId = $account->id;
     $meeting->forget();
     $account->forget();
     return array($meetingId, $accountId);
 }
 public function testGetManyManyRelationshipModelIds()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $alisa = UserTestHelper::createBasicUser('Alisa');
     $alicia = UserTestHelper::createBasicUser('Alicia');
     $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('Meeting With User Attendees', $super);
     $data = array('id' => $meeting->id, 'modelClassName' => 'Meeting', 'relationName' => 'userAttendees');
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEmpty($response['data']);
     $meeting->userAttendees->add($alisa);
     $meeting->userAttendees->add($alicia);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['userAttendees']));
     $this->assertEquals('User', $response['data']['userAttendees'][0]['class']);
     $this->assertEquals($alisa->id, $response['data']['userAttendees'][0]['id']);
     $this->assertEquals('User', $response['data']['userAttendees'][1]['class']);
     $this->assertEquals($alicia->id, $response['data']['userAttendees'][1]['id']);
     $data = array('id' => $meeting->id, 'modelClassName' => 'NonExistingModel', 'relationName' => 'userAttendees');
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('The specified class name was invalid.', $response['message']);
     $data = array('id' => $meeting->id, 'modelClassName' => 'Meeting', 'relationName' => 'owner');
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('The specified relationship name does not exist or is not MANY_MANY type.', $response['message']);
 }
 public function testGetMeetingWithAttendees()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $evelina = UserTestHelper::createBasicUser('Evelina');
     $amelia = UserTestHelper::createBasicUser('Amelia');
     $amelia->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($amelia->save());
     $contact1 = ContactTestHelper::createContactByNameForOwner('TestContact3', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('TestContact4', $super);
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact2->save());
     $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('Meeting 2 With User Attendees', $super);
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertTrue(isset($response['data']['attendees']));
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertFalse(isset($response['data']['attendees']['Organizer']['email']));
     $meeting->activityItems->add($contact1);
     $meeting->activityItems->add($contact2);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals($contact2->primaryEmail->emailAddress, $response['data']['attendees']['Contact'][1]['email']);
     $meeting->userAttendees->add($evelina);
     $meeting->userAttendees->add($amelia);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals(2, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertEquals($amelia->id, $response['data']['attendees']['User'][1]['id']);
     $this->assertEquals($amelia->primaryEmail->emailAddress, $response['data']['attendees']['User'][1]['email']);
     $this->assertEquals($amelia->firstName, $response['data']['attendees']['User'][1]['firstName']);
     $this->assertEquals($amelia->lastName, $response['data']['attendees']['User'][1]['lastName']);
     $this->assertEquals($amelia->username, $response['data']['attendees']['User'][1]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     // Test with opportunity and account activity items
     $account = AccountTestHelper::createAccountByNameForOwner('Account 2', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('TestOpportunity 2', $super);
     $meeting2 = MeetingTestHelper::createMeetingByNameForOwner('Meeting 3 With Account and Opportunity', $super);
     $meeting2->activityItems->add($account);
     $meeting2->activityItems->add($opportunity);
     $this->assertTrue($meeting2->save());
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => 'Meeting 3 With Account and Opportunity'), 'sort' => 'name');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(1, count($response['data']['items']));
     $this->assertEquals($account->id, $response['data']['items'][0]['attendees']['Account'][0]['id']);
     $this->assertEquals($account->name, $response['data']['items'][0]['attendees']['Account'][0]['name']);
     $this->assertEquals($opportunity->id, $response['data']['items'][0]['attendees']['Opportunity'][0]['id']);
     $this->assertEquals($opportunity->name, $response['data']['items'][0]['attendees']['Opportunity'][0]['name']);
     // Test with regular user if he can get user attendees
     $michael = UserTestHelper::createBasicUser('Michael');
     $michael->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($michael->save());
     $michael->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $michael->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $michael->setRight('MeetingsModule', MeetingsModule::getCreateRight());
     $saved = $michael->save();
     $this->assertTrue($saved);
     $michaelMeeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 4 With User', $michael);
     $michaelMeeting->userAttendees->add($evelina);
     $this->assertTrue($michaelMeeting->save());
     $authenticationData = $this->login('michael', 'michael');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $michaelMeeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(1, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($michael->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($michael->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($michael->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($michael->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertEquals($michael->primaryEmail->emailAddress, $response['data']['attendees']['Organizer']['email']);
 }