/**
  * @depends testSaveChecklistItemForTaskUsingAjax
  */
 public function testUpdateStatusViaAjax()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $tasks = Task::getByName('aTest');
     $task = $tasks[0];
     $taskId = $task->id;
     $checkListItems = $task->checkListItems;
     $this->setGetArray(array('id' => $checkListItems[0]->id, 'taskId' => $taskId, 'checkListItemCompleted' => '1'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/taskCheckItems/updateStatusViaAjax', true);
     $taskCheckListItem = TaskCheckListItem::getById(intval($checkListItems[0]->id));
     $this->assertTrue((bool) $taskCheckListItem->completed);
     $this->setGetArray(array('id' => $checkListItems[0]->id, 'taskId' => $taskId, 'checkListItemCompleted' => '0'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/taskCheckItems/updateStatusViaAjax', true);
     $taskCheckListItem = TaskCheckListItem::getById(intval($checkListItems[0]->id));
     $this->assertFalse((bool) $taskCheckListItem->completed);
 }
Ejemplo n.º 2
0
 /**
  * @covers getTaskCompletionPercentage
  */
 public function testTaskCompletionPercentage()
 {
     $tasks = Task::getByName('MyTest');
     $task = $tasks[0];
     $checkListItem = new TaskCheckListItem();
     $checkListItem->name = 'Test Item 1';
     $this->assertTrue($checkListItem->unrestrictedSave());
     $task->checkListItems->add($checkListItem);
     $task->save(false);
     $checkListItem = new TaskCheckListItem();
     $checkListItem->name = 'Test Item 2';
     $checkListItem->completed = true;
     $this->assertTrue($checkListItem->unrestrictedSave());
     $task->checkListItems->add($checkListItem);
     $task->save(false);
     $this->assertEquals(2, count($task->checkListItems));
     $percent = TasksUtil::getTaskCompletionPercentage($task);
     $this->assertEquals(50, $percent);
 }
 /**
  * Renders task check list items
  * @return string
  */
 protected function renderTaskCheckListItems()
 {
     $getParams = array('relatedModelId' => $this->model->id, 'relatedModelClassName' => get_class($this->model), 'relatedModelRelationName' => 'checkListItems');
     $taskCheckListItem = TaskCheckListItem::getByTask($this->model->id);
     $view = new TaskCheckListItemsForTaskView('taskCheckItems', 'tasks', $taskCheckListItem, $this->model, $this->form, $getParams);
     $content = $view->render();
     return $content;
 }
 /**
  * Delete checklist item
  */
 public function actionDeleteCheckListItem($id, $taskId)
 {
     $task = Task::getById((int) $taskId);
     $taskCheckListItem = TaskCheckListItem::getById(intval($id));
     $task->checkListItems->remove($taskCheckListItem);
     $saved = $task->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $getParams = array('uniquePageId' => null, 'relatedModelId' => $task->id, 'relatedModelClassName' => 'Task', 'relatedModelRelationName' => 'checkListItems');
     $url = Yii::app()->createUrl('tasks/taskCheckItems/ajaxCheckItemListForRelatedTaskModel', $getParams);
     $this->redirect($url);
 }