mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
When using the Herald test console on a transactional object, guess a reasonable set of transactions to simulate
Summary: Depends on D20518. Ref T13283. When you use the "Test Console" in Herald to test rules, pass the most recent group of transactions to the Adapter. This will make it easier to test rules that depend on edit state, since you can make the type of edit you're trying to test and then use the Test Console to actually test if it matches in the way you expect. The transactions we select may not be exactly the group of transactions that most recently applied. For example, if you make edits A, B, and C in rapid succession and then run the Test Console on the object, it may select "A + B + C" as a transaction group. But we'll show you what we selected and this is basically sane/reasonable and should be fine. (Eventually, we could include a separate "transaction group ID" on transactions if we want to get this selection to match exactly.) Test Plan: Ran the Test Console on various objects, saw sensible transaction lists in the transcripts. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13283 Differential Revision: https://secure.phabricator.com/D20519
This commit is contained in:
parent
046888ac2e
commit
bf2f3991d2
1 changed files with 39 additions and 0 deletions
|
@ -46,6 +46,11 @@ final class HeraldTestConsoleController extends HeraldController {
|
|||
->setActingAsPHID($viewer->getPHID())
|
||||
->setViewer($viewer);
|
||||
|
||||
$applied_xactions = $this->loadAppliedTransactions($object);
|
||||
if ($applied_xactions !== null) {
|
||||
$adapter->setAppliedTransactions($applied_xactions);
|
||||
}
|
||||
|
||||
$rules = id(new HeraldRuleQuery())
|
||||
->setViewer($viewer)
|
||||
->withContentTypes(array($adapter->getAdapterContentType()))
|
||||
|
@ -245,4 +250,38 @@ final class HeraldTestConsoleController extends HeraldController {
|
|||
return PhabricatorContentSource::newFromRequest($request);
|
||||
}
|
||||
|
||||
private function loadAppliedTransactions($object) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = PhabricatorApplicationTransactionQuery::newQueryForObject(
|
||||
$object);
|
||||
|
||||
$xactions = $query
|
||||
->withObjectPHIDs(array($object->getPHID()))
|
||||
->setViewer($viewer)
|
||||
->setLimit(100)
|
||||
->execute();
|
||||
|
||||
$applied = array();
|
||||
|
||||
// Pick the most recent group of transactions. This may not be exactly the
|
||||
// same as what Herald acted on: for example, we may select a single group
|
||||
// of transactions here which were really applied across two or more edits.
|
||||
// Since this is relatively rare and we show you what we picked, it's okay
|
||||
// that we just do roughly the right thing.
|
||||
foreach ($xactions as $xaction) {
|
||||
if (!$xaction->shouldDisplayGroupWith($applied)) {
|
||||
break;
|
||||
}
|
||||
$applied[] = $xaction;
|
||||
}
|
||||
|
||||
return $applied;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue