public function createTaskWithRelatedAccount($firstName, $taskName) { $account = AccountTestHelper::createAccountByNameForOwner($firstName, Yii::app()->user->userModel); $this->assertNull($account->latestActivityDateTime); $task = TaskTestHelper::createTaskByNameForOwner($taskName, Yii::app()->user->userModel); $task->activityItems->add($account); $this->assertTrue($task->save()); $this->assertNull($task->activityItems[0]->latestActivityDateTime); $taskId = $task->id; $accountId = $account->id; $task->forget(); $account->forget(); return array($taskId, $accountId); }
/** * @covers createKanbanItemFromTask */ public function testCreateKanbanItemFromTask() { $task = TaskTestHelper::createTaskByNameForOwner('My Kanban Task', Yii::app()->user->userModel); $task->status = Task::STATUS_IN_PROGRESS; $accounts = Account::getByName('anAccount'); $task->activityItems->add($accounts[0]); $this->assertTrue($task->save()); $kanbanItem = TasksUtil::createKanbanItemFromTask($task); $this->assertEquals($kanbanItem->type, KanbanItem::TYPE_IN_PROGRESS); }
/** * @depends testApiServerUrl */ public function testEditTaskWIthIncorrectDataType() { $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'); $task = TaskTestHelper::createTaskByNameForOwner('Newest Task', $super); // Provide data with wrong type. $data['dueDateTime'] = "A"; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/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 = $task->id; $data = array(); $data['dueDateTime'] = "A"; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/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'])); }
/** * Test if all deleted items was pulled from read permission tables via API. * Please note that here we do not test if data are inserted in read permission tables correctly, that is * part of read permission subscription tests * @throws NotFoundException */ public function testGetDeletedTasks() { $timestamp = time(); sleep(1); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $this->deleteAllModelsAndRecordsFromReadPermissionTable('Task'); $job = new ReadPermissionSubscriptionUpdateJob(); $task1 = TaskTestHelper::createTaskByNameForOwner('Task1', $super); $task2 = TaskTestHelper::createTaskByNameForOwner('Task2', $super); $task3 = TaskTestHelper::createTaskByNameForOwner('Task3', $super); $this->assertTrue($job->run()); sleep(1); $taskId1 = $task1->id; $taskId2 = $task2->id; $taskId3 = $task3->id; $task1->delete(); $task2->delete(); $task3->delete(); $this->assertTrue($job->run()); $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $data = array('userId' => $super->id, 'sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1)); $response = $this->createApiCallWithRelativeUrl('getDeletedItems/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(3, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['pageSize']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertContains($taskId1, $response['data']['items']); $this->assertContains($taskId2, $response['data']['items']); $data = array('userId' => $super->id, 'sinceTimestamp' => 0, 'pagination' => array('pageSize' => 2, 'page' => 2)); $response = $this->createApiCallWithRelativeUrl('getDeletedItems/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(3, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['pageSize']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertContains($taskId3, $response['data']['items']); }
public function testResolveRelatedContactsAndSetLatestActivityDateTime() { $contact = ContactTestHelper::createContactByNameForOwner('contact2', Yii::app()->user->userModel); $this->assertNull($contact->latestActivityDateTime); $contact2 = ContactTestHelper::createContactByNameForOwner('contact3', Yii::app()->user->userModel); $this->assertNull($contact2->latestActivityDateTime); $task = TaskTestHelper::createTaskByNameForOwner('task3', Yii::app()->user->userModel); $task->activityItems->add($contact); $task->activityItems->add($contact2); $this->assertTrue($task->save()); $this->assertNull($task->activityItems[0]->latestActivityDateTime); $this->assertNull($task->activityItems[1]->latestActivityDateTime); $taskId = $task->id; $contactId = $contact->id; $contact2Id = $contact2->id; $task->forget(); $contact->forget(); $contact2->forget(); //Retrieve the task, so the related activity item is an Item and needs to be casted down $task = Task::getById($taskId); $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); ContactLatestActivityDateTimeObserver::resolveRelatedModelsAndSetLatestActivityDateTime($task->activityItems, $dateTime, 'Contact'); $task->forget(); $contact = Contact::getById($contactId); $this->assertEquals($dateTime, $contact->latestActivityDateTime); $contact2 = Contact::getById($contact2Id); $this->assertEquals($dateTime, $contact2->latestActivityDateTime); }
public function testUpdateStatusOnDragInKanbanView() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $project = ProjectTestHelper::createProjectByNameForOwner('a new project', $super); $task = TaskTestHelper::createTaskByNameForOwner('My Kanban Task', Yii::app()->user->userModel); $task->project = $project; $task->status = Task::STATUS_IN_PROGRESS; $taskId = $task->id; $this->assertTrue($task->save()); $task1 = TaskTestHelper::createTaskByNameForOwner('My Kanban Task 1', Yii::app()->user->userModel); $task1->project = $project; $task1->status = Task::STATUS_NEW; $this->assertTrue($task1->save()); $task1Id = $task1->id; $taskArray = array($task, $task1); foreach ($taskArray as $row => $data) { $kanbanItem = KanbanItem::getByTask($data->id); if ($kanbanItem == null) { //Create KanbanItem here $kanbanItem = TasksUtil::createKanbanItemFromTask($data); } $kanbanItemsArray[] = $kanbanItem; } $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItemsArray[1]->type); $this->assertEquals(1, $kanbanItemsArray[1]->sortOrder); $this->assertEquals(1, $kanbanItemsArray[0]->sortOrder); $this->setGetArray(array('items' => array($task1->id, $task->id), 'type' => KanbanItem::TYPE_IN_PROGRESS)); $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/updateStatusOnDragInKanbanView', false); $contentArray = CJSON::decode($content); $this->assertContains('Finish', $contentArray['button']); $task1 = Task::getById($task1Id); $this->assertEquals(Task::STATUS_IN_PROGRESS, $task1->status); $kanbanItem = KanbanItem::getByTask($task1Id); $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem->type); $kanbanItem = KanbanItem::getByTask($taskId); $this->assertEquals(2, $kanbanItem->sortOrder); }
public function testGetAddedOrDeletedModelsFromReadSubscriptionTable() { ReadPermissionsSubscriptionUtil::buildTables(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $messageLogger = new DebuggingMessageLogger(); $task = TaskTestHelper::createTaskByNameForOwner('Test Task', $super); // Because ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables completed in previous test // status need to be ReadPermissionsSubscriptionUtil::STATUS_COMPLETED $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $this->assertTrue(ReadPermissionsSubscriptionUtil::isReadPermissionSubscriptionUpdateCompleted()); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger); $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus()); $this->assertTrue(ReadPermissionsSubscriptionUtil::isReadPermissionSubscriptionUpdateCompleted()); $sql = "SELECT * FROM task_read_subscription WHERE userid = " . $super->id; $permissionTableRows = ZurmoRedBean::getAll($sql); $this->assertEquals(1, count($permissionTableRows)); $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super); $this->asserttrue(is_array($addedModelIds)); $this->assertEquals(1, count($addedModelIds)); ModelCreationApiSyncUtil::insertItem('TestService', $task->id, 'Task', '2013-05-03 15:16:06'); $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super); $this->asserttrue(is_array($addedModelIds)); $this->assertEquals(0, count($addedModelIds)); }
public function testGetAddedOrDeletedModelsFromReadSubscriptionTable() { ReadPermissionsSubscriptionUtil::buildTables(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $task = TaskTestHelper::createTaskByNameForOwner('Test Task', $super); ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables(false); $sql = "SELECT * FROM task_read_subscription WHERE userid = " . $super->id; $permissionTableRows = R::getAll($sql); $this->assertEquals(1, count($permissionTableRows)); $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super); $this->asserttrue(is_array($addedModelIds)); $this->assertEquals(1, count($addedModelIds)); ModelCreationApiSyncUtil::insertItem('TestService', $task->id, 'Task', '2013-05-03 15:16:06'); $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super); $this->asserttrue(is_array($addedModelIds)); $this->assertEquals(0, count($addedModelIds)); }