public function testCopy()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = Yii::app()->user->userModel;
     $project = new Project();
     $project->name = 'Project 1';
     $project->owner = $user;
     $project->description = 'Description';
     $user = UserTestHelper::createBasicUser('Steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
     $this->assertTrue($account->save());
     $id = $account->id;
     unset($account);
     $account = Account::getById($id);
     $this->assertEquals("Tom & Jerry's Account", $account->name);
     $contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
     $this->assertTrue($project->save());
     $this->assertEquals(1, count($project->auditEvents));
     $id = $project->id;
     $project->forget();
     unset($project);
     $project = Project::getById($id);
     ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
     $this->assertEquals('Project 1', $project->name);
     $this->assertEquals('Description', $project->description);
     $this->assertEquals(1, $project->accounts->count());
     $this->assertEquals(1, $project->contacts->count());
     $this->assertEquals(1, $project->opportunities->count());
     $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem1 = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
     $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
     $copyToProject = new Project();
     ProjectZurmoCopyModelUtil::copy($project, $copyToProject);
     ProjectZurmoCopyModelUtil::processAfterCopy($project, $copyToProject);
     $this->assertTrue($copyToProject->save());
     $this->assertEquals($copyToProject->name, $project->name);
     $this->assertEquals($copyToProject->description, $project->description);
     $this->assertEquals($copyToProject->status, $project->status);
     $project = Project::getByName('Project 1');
     $this->assertEquals(2, count($project));
     $tasks = Task::getAll();
     $this->assertEquals(2, count($tasks));
 }
 /**
  * @covers sortKanbanColumnItems
  * @covers checkKanbanTypeByStatusAndUpdateIfRequired
  */
 public function testSortKanbanColumnItems()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $project = ProjectTestHelper::createProjectByNameForOwner('MyKanbanProject', Yii::app()->user->userModel);
     $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000);
     //First kanban task
     $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem1 = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
     $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
     $task2 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MySecondKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem2 = KanbanItem::getByTask($task2->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type);
     $this->assertEquals($task2->project->id, $kanbanItem2->kanbanRelatedItem->id);
     $task3 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyThirdKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem3 = KanbanItem::getByTask($task3->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type);
     $this->assertEquals($task3->project->id, $kanbanItem3->kanbanRelatedItem->id);
     $sourceKanbanType = TasksUtil::resolveKanbanItemTypeForTaskStatus(Task::STATUS_IN_PROGRESS);
     TasksUtil::sortKanbanColumnItems($sourceKanbanType, $task->project);
     $kanbanItem = KanbanItem::getByTask($task->id);
     $kanbanItem2 = KanbanItem::getByTask($task2->id);
     $kanbanItem3 = KanbanItem::getByTask($task3->id);
     $this->assertEquals($task->id, $kanbanItem->task->id);
     $this->assertEquals(1, $kanbanItem->sortOrder);
     $this->assertEquals($task2->id, $kanbanItem2->task->id);
     $this->assertEquals(2, $kanbanItem2->sortOrder);
     $this->assertEquals($task3->id, $kanbanItem3->task->id);
     $this->assertEquals(3, $kanbanItem3->sortOrder);
     //Update status and check checkKanbanTypeByStatusAndUpdateIfRequired
     $task->status = Task::STATUS_NEW;
     $this->assertTrue($task->save());
     TasksUtil::checkKanbanTypeByStatusAndUpdateIfRequired($task);
     $kanbanItem = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItem->type);
     $kanbanItem2 = KanbanItem::getByTask($task2->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type);
     $kanbanItem3 = KanbanItem::getByTask($task3->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type);
     $this->assertEquals($task->id, $kanbanItem->task->id);
     $this->assertEquals(1, $kanbanItem->sortOrder);
     $this->assertEquals($task2->id, $kanbanItem2->task->id);
     $this->assertEquals(1, $kanbanItem2->sortOrder);
     $this->assertEquals($task3->id, $kanbanItem3->task->id);
     $this->assertEquals(2, $kanbanItem3->sortOrder);
 }