Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1071252
ManiphestTaskTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
ManiphestTaskTestCase.php
View Options
<?php
final
class
ManiphestTaskTestCase
extends
PhabricatorTestCase
{
protected
function
getPhabricatorTestCaseConfiguration
()
{
return
array
(
self
::
PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES
=>
true
,
);
}
public
function
testTaskReordering
()
{
$viewer
=
$this
->
generateNewTestUser
();
$t1
=
$this
->
newTask
(
$viewer
,
'Task 1'
);
$t2
=
$this
->
newTask
(
$viewer
,
'Task 2'
);
$t3
=
$this
->
newTask
(
$viewer
,
'Task 3'
);
// Default order should be reverse creation.
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
3
,
2
,
1
),
array_keys
(
$tasks
));
// Move T3 to the middle.
$this
->
moveTask
(
$viewer
,
$t3
,
$t2
,
true
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
2
,
3
,
1
),
array_keys
(
$tasks
));
// Move T3 to the end.
$this
->
moveTask
(
$viewer
,
$t3
,
$t1
,
true
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
2
,
1
,
3
),
array_keys
(
$tasks
));
// Repeat the move above, there should be no overall change in order.
$this
->
moveTask
(
$viewer
,
$t3
,
$t1
,
true
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
2
,
1
,
3
),
array_keys
(
$tasks
));
// Move T3 to the first slot in the priority.
$this
->
movePriority
(
$viewer
,
$t3
,
$t3
->
getPriority
(),
false
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
3
,
2
,
1
),
array_keys
(
$tasks
));
// Move T3 to the last slot in the priority.
$this
->
movePriority
(
$viewer
,
$t3
,
$t3
->
getPriority
(),
true
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
2
,
1
,
3
),
array_keys
(
$tasks
));
// Move T3 before T2.
$this
->
moveTask
(
$viewer
,
$t3
,
$t2
,
false
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
3
,
2
,
1
),
array_keys
(
$tasks
));
// Move T3 before T1.
$this
->
moveTask
(
$viewer
,
$t3
,
$t1
,
false
);
$tasks
=
$this
->
loadTasks
(
$viewer
);
$t1
=
$tasks
[
1
];
$t2
=
$tasks
[
2
];
$t3
=
$tasks
[
3
];
$this
->
assertEqual
(
array
(
2
,
3
,
1
),
array_keys
(
$tasks
));
}
private
function
newTask
(
PhabricatorUser
$viewer
,
$title
)
{
$task
=
ManiphestTask
::
initializeNewTask
(
$viewer
);
$xactions
=
array
();
$xactions
[]
=
id
(
new
ManiphestTransaction
())
->
setTransactionType
(
ManiphestTransaction
::
TYPE_TITLE
)
->
setNewValue
(
$title
);
$this
->
applyTaskTransactions
(
$viewer
,
$task
,
$xactions
);
return
$task
;
}
private
function
loadTasks
(
PhabricatorUser
$viewer
)
{
$tasks
=
id
(
new
ManiphestTaskQuery
())
->
setViewer
(
$viewer
)
->
setOrderBy
(
ManiphestTaskQuery
::
ORDER_PRIORITY
)
->
execute
();
$tasks
=
mpull
(
$tasks
,
null
,
'getID'
);
return
$tasks
;
}
private
function
moveTask
(
PhabricatorUser
$viewer
,
$src
,
$dst
,
$is_after
)
{
list
(
$pri
,
$sub
)
=
ManiphestTransactionEditor
::
getAdjacentSubpriority
(
$dst
,
$is_after
);
$xactions
=
array
();
$xactions
[]
=
id
(
new
ManiphestTransaction
())
->
setTransactionType
(
ManiphestTransaction
::
TYPE_PRIORITY
)
->
setNewValue
(
$pri
);
$xactions
[]
=
id
(
new
ManiphestTransaction
())
->
setTransactionType
(
ManiphestTransaction
::
TYPE_SUBPRIORITY
)
->
setNewValue
(
$sub
);
return
$this
->
applyTaskTransactions
(
$viewer
,
$src
,
$xactions
);
}
private
function
movePriority
(
PhabricatorUser
$viewer
,
$src
,
$target_priority
,
$is_end
)
{
list
(
$pri
,
$sub
)
=
ManiphestTransactionEditor
::
getEdgeSubpriority
(
$target_priority
,
$is_end
);
$xactions
=
array
();
$xactions
[]
=
id
(
new
ManiphestTransaction
())
->
setTransactionType
(
ManiphestTransaction
::
TYPE_PRIORITY
)
->
setNewValue
(
$pri
);
$xactions
[]
=
id
(
new
ManiphestTransaction
())
->
setTransactionType
(
ManiphestTransaction
::
TYPE_SUBPRIORITY
)
->
setNewValue
(
$sub
);
return
$this
->
applyTaskTransactions
(
$viewer
,
$src
,
$xactions
);
}
private
function
applyTaskTransactions
(
PhabricatorUser
$viewer
,
ManiphestTask
$task
,
array
$xactions
)
{
$content_source
=
PhabricatorContentSource
::
newConsoleSource
();
$editor
=
id
(
new
ManiphestTransactionEditor
())
->
setActor
(
$viewer
)
->
setContentSource
(
$content_source
)
->
setContinueOnNoEffect
(
true
)
->
applyTransactions
(
$task
,
$xactions
);
return
$task
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jun 29, 4:07 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
261517
Default Alt Text
ManiphestTaskTestCase.php (4 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment