mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add some test coverage for board moves
Summary: Ref T10010. This isn't totally comprehensive, and a lot of behaviors aren't testable (e.g., all the Javascript stuff) but at least covers the basic create/move/reorder operations. Test Plan: `arc unit` Reviewers: chad Reviewed By: chad Maniphest Tasks: T10010 Differential Revision: https://secure.phabricator.com/D15178
This commit is contained in:
parent
9961de0e80
commit
00165424d0
2 changed files with 161 additions and 2 deletions
|
@ -906,6 +906,165 @@ final class PhabricatorProjectCoreTestCase extends PhabricatorTestCase {
|
|||
$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) {
|
||||
$project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$task->getPHID(),
|
||||
|
|
|
@ -23,7 +23,7 @@ final class PhabricatorBoardLayoutEngine extends Phobject {
|
|||
}
|
||||
|
||||
public function setBoardPHIDs(array $board_phids) {
|
||||
$this->boardPHIDs = $board_phids;
|
||||
$this->boardPHIDs = array_fuse($board_phids);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ final class PhabricatorBoardLayoutEngine extends Phobject {
|
|||
}
|
||||
|
||||
public function setObjectPHIDs(array $object_phids) {
|
||||
$this->objectPHIDs = $object_phids;
|
||||
$this->objectPHIDs = array_fuse($object_phids);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue