@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+161 -2
+159
src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
··· 906 906 $this->getTaskProjects($task)); 907 907 } 908 908 909 + public function testBoardMoves() { 910 + $user = $this->createUser(); 911 + $user->save(); 912 + 913 + $board = $this->createProject($user); 914 + 915 + $backlog = $this->addColumn($user, $board, 0); 916 + $column = $this->addColumn($user, $board, 1); 917 + 918 + // New tasks should appear in the backlog. 919 + $task1 = $this->newTask($user, array($board)); 920 + $expect = array( 921 + $backlog->getPHID(), 922 + ); 923 + $this->assertColumns($expect, $user, $board, $task1); 924 + 925 + // Moving a task should move it to the destination column. 926 + $this->moveToColumn($user, $board, $task1, $backlog, $column); 927 + $expect = array( 928 + $column->getPHID(), 929 + ); 930 + $this->assertColumns($expect, $user, $board, $task1); 931 + 932 + // Same thing again, with a new task. 933 + $task2 = $this->newTask($user, array($board)); 934 + $expect = array( 935 + $backlog->getPHID(), 936 + ); 937 + $this->assertColumns($expect, $user, $board, $task2); 938 + 939 + // Move it, too. 940 + $this->moveToColumn($user, $board, $task2, $backlog, $column); 941 + $expect = array( 942 + $column->getPHID(), 943 + ); 944 + $this->assertColumns($expect, $user, $board, $task2); 945 + 946 + // Now the stuff should be in the column, in order, with the more recently 947 + // moved task on top. 948 + $expect = array( 949 + $task2->getPHID(), 950 + $task1->getPHID(), 951 + ); 952 + $this->assertTasksInColumn($expect, $user, $board, $column); 953 + 954 + // Move the second task after the first task. 955 + $options = array( 956 + 'afterPHID' => $task1->getPHID(), 957 + ); 958 + $this->moveToColumn($user, $board, $task2, $column, $column, $options); 959 + $expect = array( 960 + $task1->getPHID(), 961 + $task2->getPHID(), 962 + ); 963 + $this->assertTasksInColumn($expect, $user, $board, $column); 964 + 965 + // Move the second task before the first task. 966 + $options = array( 967 + 'beforePHID' => $task1->getPHID(), 968 + ); 969 + $this->moveToColumn($user, $board, $task2, $column, $column, $options); 970 + $expect = array( 971 + $task2->getPHID(), 972 + $task1->getPHID(), 973 + ); 974 + $this->assertTasksInColumn($expect, $user, $board, $column); 975 + 976 + } 977 + 978 + private function moveToColumn( 979 + PhabricatorUser $viewer, 980 + PhabricatorProject $board, 981 + ManiphestTask $task, 982 + PhabricatorProjectColumn $src, 983 + PhabricatorProjectColumn $dst, 984 + $options = null) { 985 + 986 + $xactions = array(); 987 + 988 + if (!$options) { 989 + $options = array(); 990 + } 991 + 992 + $xactions[] = id(new ManiphestTransaction()) 993 + ->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN) 994 + ->setOldValue( 995 + array( 996 + 'projectPHID' => $board->getPHID(), 997 + 'columnPHIDs' => array($src->getPHID()), 998 + )) 999 + ->setNewValue( 1000 + array( 1001 + 'projectPHID' => $board->getPHID(), 1002 + 'columnPHIDs' => array($dst->getPHID()), 1003 + ) + $options); 1004 + 1005 + $editor = id(new ManiphestTransactionEditor()) 1006 + ->setActor($viewer) 1007 + ->setContentSource(PhabricatorContentSource::newConsoleSource()) 1008 + ->setContinueOnNoEffect(true) 1009 + ->applyTransactions($task, $xactions); 1010 + } 1011 + 1012 + private function assertColumns( 1013 + array $expect, 1014 + PhabricatorUser $viewer, 1015 + PhabricatorProject $board, 1016 + ManiphestTask $task) { 1017 + 1018 + $engine = id(new PhabricatorBoardLayoutEngine()) 1019 + ->setViewer($viewer) 1020 + ->setBoardPHIDs(array($board->getPHID())) 1021 + ->setObjectPHIDs( 1022 + array( 1023 + $task->getPHID(), 1024 + )) 1025 + ->executeLayout(); 1026 + 1027 + $columns = $engine->getObjectColumns($board->getPHID(), $task->getPHID()); 1028 + $column_phids = mpull($columns, 'getPHID'); 1029 + $column_phids = array_values($column_phids); 1030 + 1031 + $this->assertEqual($expect, $column_phids); 1032 + } 1033 + 1034 + private function assertTasksInColumn( 1035 + array $expect, 1036 + PhabricatorUser $viewer, 1037 + PhabricatorProject $board, 1038 + PhabricatorProjectColumn $column) { 1039 + 1040 + $engine = id(new PhabricatorBoardLayoutEngine()) 1041 + ->setViewer($viewer) 1042 + ->setBoardPHIDs(array($board->getPHID())) 1043 + ->setObjectPHIDs($expect) 1044 + ->executeLayout(); 1045 + 1046 + $object_phids = $engine->getColumnObjectPHIDs( 1047 + $board->getPHID(), 1048 + $column->getPHID()); 1049 + $object_phids = array_values($object_phids); 1050 + 1051 + $this->assertEqual($expect, $object_phids); 1052 + } 1053 + 1054 + private function addColumn( 1055 + PhabricatorUser $viewer, 1056 + PhabricatorProject $project, 1057 + $sequence) { 1058 + 1059 + $project->setHasWorkboard(1)->save(); 1060 + 1061 + return PhabricatorProjectColumn::initializeNewColumn($viewer) 1062 + ->setSequence(0) 1063 + ->setProperty('isDefault', ($sequence == 0)) 1064 + ->setProjectPHID($project->getPHID()) 1065 + ->save(); 1066 + } 1067 + 909 1068 private function getTaskProjects(ManiphestTask $task) { 910 1069 $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 911 1070 $task->getPHID(),
+2 -2
src/applications/project/engine/PhabricatorBoardLayoutEngine.php
··· 23 23 } 24 24 25 25 public function setBoardPHIDs(array $board_phids) { 26 - $this->boardPHIDs = $board_phids; 26 + $this->boardPHIDs = array_fuse($board_phids); 27 27 return $this; 28 28 } 29 29 ··· 32 32 } 33 33 34 34 public function setObjectPHIDs(array $object_phids) { 35 - $this->objectPHIDs = $object_phids; 35 + $this->objectPHIDs = array_fuse($object_phids); 36 36 return $this; 37 37 } 38 38