Differential D15178 Diff 36646 src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
| Show First 20 Lines • Show All 900 Lines • ▼ Show 20 Lines | public function testTagMilestoneConflicts() { | ||||
| $this->addProjectTags($user, $task, array($stonework_2->getPHID())); | $this->addProjectTags($user, $task, array($stonework_2->getPHID())); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| array( | array( | ||||
| $stonework_2->getPHID(), | $stonework_2->getPHID(), | ||||
| ), | ), | ||||
| $this->getTaskProjects($task)); | $this->getTaskProjects($task)); | ||||
| } | } | ||||
| public function testBoardMoves() { | |||||
| $user = $this->createUser(); | |||||
| $user->save(); | |||||
| $board = $this->createProject($user); | |||||
| $backlog = $this->addColumn($user, $board, 0); | |||||
| $column = $this->addColumn($user, $board, 1); | |||||
| // New tasks should appear in the backlog. | |||||
| $task1 = $this->newTask($user, array($board)); | |||||
| $expect = array( | |||||
| $backlog->getPHID(), | |||||
| ); | |||||
| $this->assertColumns($expect, $user, $board, $task1); | |||||
| // Moving a task should move it to the destination column. | |||||
| $this->moveToColumn($user, $board, $task1, $backlog, $column); | |||||
| $expect = array( | |||||
| $column->getPHID(), | |||||
| ); | |||||
| $this->assertColumns($expect, $user, $board, $task1); | |||||
| // Same thing again, with a new task. | |||||
| $task2 = $this->newTask($user, array($board)); | |||||
| $expect = array( | |||||
| $backlog->getPHID(), | |||||
| ); | |||||
| $this->assertColumns($expect, $user, $board, $task2); | |||||
| // Move it, too. | |||||
| $this->moveToColumn($user, $board, $task2, $backlog, $column); | |||||
| $expect = array( | |||||
| $column->getPHID(), | |||||
| ); | |||||
| $this->assertColumns($expect, $user, $board, $task2); | |||||
| // Now the stuff should be in the column, in order, with the more recently | |||||
| // moved task on top. | |||||
| $expect = array( | |||||
| $task2->getPHID(), | |||||
| $task1->getPHID(), | |||||
| ); | |||||
| $this->assertTasksInColumn($expect, $user, $board, $column); | |||||
| // Move the second task after the first task. | |||||
| $options = array( | |||||
| 'afterPHID' => $task1->getPHID(), | |||||
| ); | |||||
| $this->moveToColumn($user, $board, $task2, $column, $column, $options); | |||||
| $expect = array( | |||||
| $task1->getPHID(), | |||||
| $task2->getPHID(), | |||||
| ); | |||||
| $this->assertTasksInColumn($expect, $user, $board, $column); | |||||
| // Move the second task before the first task. | |||||
| $options = array( | |||||
| 'beforePHID' => $task1->getPHID(), | |||||
| ); | |||||
| $this->moveToColumn($user, $board, $task2, $column, $column, $options); | |||||
| $expect = array( | |||||
| $task2->getPHID(), | |||||
| $task1->getPHID(), | |||||
| ); | |||||
| $this->assertTasksInColumn($expect, $user, $board, $column); | |||||
| } | |||||
| private function moveToColumn( | |||||
| PhabricatorUser $viewer, | |||||
| PhabricatorProject $board, | |||||
| ManiphestTask $task, | |||||
| PhabricatorProjectColumn $src, | |||||
| PhabricatorProjectColumn $dst, | |||||
| $options = null) { | |||||
| $xactions = array(); | |||||
| if (!$options) { | |||||
| $options = array(); | |||||
| } | |||||
| $xactions[] = id(new ManiphestTransaction()) | |||||
| ->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN) | |||||
| ->setOldValue( | |||||
| array( | |||||
| 'projectPHID' => $board->getPHID(), | |||||
| 'columnPHIDs' => array($src->getPHID()), | |||||
| )) | |||||
| ->setNewValue( | |||||
| array( | |||||
| 'projectPHID' => $board->getPHID(), | |||||
| 'columnPHIDs' => array($dst->getPHID()), | |||||
| ) + $options); | |||||
| $editor = id(new ManiphestTransactionEditor()) | |||||
| ->setActor($viewer) | |||||
| ->setContentSource(PhabricatorContentSource::newConsoleSource()) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->applyTransactions($task, $xactions); | |||||
| } | |||||
| private function assertColumns( | |||||
| array $expect, | |||||
| PhabricatorUser $viewer, | |||||
| PhabricatorProject $board, | |||||
| ManiphestTask $task) { | |||||
| $engine = id(new PhabricatorBoardLayoutEngine()) | |||||
| ->setViewer($viewer) | |||||
| ->setBoardPHIDs(array($board->getPHID())) | |||||
| ->setObjectPHIDs( | |||||
| array( | |||||
| $task->getPHID(), | |||||
| )) | |||||
| ->executeLayout(); | |||||
| $columns = $engine->getObjectColumns($board->getPHID(), $task->getPHID()); | |||||
| $column_phids = mpull($columns, 'getPHID'); | |||||
| $column_phids = array_values($column_phids); | |||||
| $this->assertEqual($expect, $column_phids); | |||||
| } | |||||
| private function assertTasksInColumn( | |||||
| array $expect, | |||||
| PhabricatorUser $viewer, | |||||
| PhabricatorProject $board, | |||||
| PhabricatorProjectColumn $column) { | |||||
| $engine = id(new PhabricatorBoardLayoutEngine()) | |||||
| ->setViewer($viewer) | |||||
| ->setBoardPHIDs(array($board->getPHID())) | |||||
| ->setObjectPHIDs($expect) | |||||
| ->executeLayout(); | |||||
| $object_phids = $engine->getColumnObjectPHIDs( | |||||
| $board->getPHID(), | |||||
| $column->getPHID()); | |||||
| $object_phids = array_values($object_phids); | |||||
| $this->assertEqual($expect, $object_phids); | |||||
| } | |||||
| private function addColumn( | |||||
| PhabricatorUser $viewer, | |||||
| PhabricatorProject $project, | |||||
| $sequence) { | |||||
| $project->setHasWorkboard(1)->save(); | |||||
| return PhabricatorProjectColumn::initializeNewColumn($viewer) | |||||
| ->setSequence(0) | |||||
| ->setProperty('isDefault', ($sequence == 0)) | |||||
| ->setProjectPHID($project->getPHID()) | |||||
| ->save(); | |||||
| } | |||||
| private function getTaskProjects(ManiphestTask $task) { | private function getTaskProjects(ManiphestTask $task) { | ||||
| $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | ||||
| $task->getPHID(), | $task->getPHID(), | ||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | ||||
| sort($project_phids); | sort($project_phids); | ||||
| return $project_phids; | return $project_phids; | ||||
| ▲ Show 20 Lines • Show All 282 Lines • Show Last 20 Lines | |||||