/** * @depends testApiServerUrl */ public function testEditNoteWIthIncorrectDataType() { $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'); $note = NoteTestHelper::createNoteByNameForOwner('Newest Note', $super); // Provide data with wrong type. $data['occurredOnDateTime'] = "A"; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/notes/note/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 = $note->id; $data = array(); $data['occurredOnDateTime'] = "A"; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/notes/note/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 testGetCountByModelClassName() { $super = User::getByUsername('super'); $user = UserTestHelper::createBasicUserWithEmailAddress('newUser'); Yii::app()->user->userModel = $super; $this->assertEquals(0, LatestActivitiesUtil::getCountByModelClassName('Note', array(), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL)); $this->assertEquals(0, LatestActivitiesUtil::getCountByModelClassName('Note', array(), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER)); $this->assertEquals(0, LatestActivitiesUtil::getCountByModelClassName('Note', array(), $super->id)); $this->assertEquals(0, LatestActivitiesUtil::getCountByModelClassName('Note', array(), $user->id)); NoteTestHelper::createNoteByNameForOwner('test1', $super); $this->assertEquals(1, LatestActivitiesUtil::getCountByModelClassName('Note', array(), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL)); $this->assertEquals(1, LatestActivitiesUtil::getCountByModelClassName('Note', array(), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER)); $this->assertEquals(1, LatestActivitiesUtil::getCountByModelClassName('Note', array(), $super->id)); $this->assertEquals(0, LatestActivitiesUtil::getCountByModelClassName('Note', array(), $user->id)); NoteTestHelper::createNoteByNameForOwner('test1', $user); $this->assertEquals(2, LatestActivitiesUtil::getCountByModelClassName('Note', array(), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL)); $this->assertEquals(1, LatestActivitiesUtil::getCountByModelClassName('Note', array(), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER)); $this->assertEquals(1, LatestActivitiesUtil::getCountByModelClassName('Note', array(), $user->id)); }
/** * @depends testCreateAndGetNoteById */ public function testRemoveActivityItemFromActivity() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $firstNote = NoteTestHelper::createNoteByNameForOwner('Note with relations', $super); $secondNote = NoteTestHelper::createNoteByNameForOwner('Second note with relations', $super); $thirdContact = ContactTestHelper::createContactByNameForOwner('Third', $super); $firstContact = ContactTestHelper::createContactByNameForOwner('First', $super); $secondContact = ContactTestHelper::createContactByNameForOwner('Second', $super); $firstNote->activityItems->add($firstContact); $firstNote->activityItems->add($secondContact); $firstNote->save(); $this->assertEquals(2, count($firstNote->activityItems)); $this->assertEquals($firstContact->id, $firstNote->activityItems[0]->id); $this->assertEquals($secondContact->id, $firstNote->activityItems[1]->id); $noteId = $firstNote->id; $firstNote->forget(); $firstNote = Note::getById($noteId); $this->assertEquals(2, count($firstNote->activityItems)); $this->assertEquals($firstContact->getClassId('Item'), $firstNote->activityItems[0]->id); $this->assertEquals($secondContact->getClassId('Item'), $firstNote->activityItems[1]->id); $firstNote->activityItems->remove($firstContact); $firstNote->save(); $this->assertEquals(1, count($firstNote->activityItems)); $this->assertEquals($secondContact->getClassId('Item'), $firstNote->activityItems[0]->id); $firstNote->forget(); $firstNote = Note::getById($noteId); $this->assertEquals(1, count($firstNote->activityItems)); $this->assertEquals($secondContact->getClassId('Item'), $firstNote->activityItems[0]->id); }