Skip to content

Commit c7be6f4

Browse files
deedyepriestley
authored andcommitted
Task Generation with Transactions, Auxiliary Fields, and Projects
Summary: Ref T2903 Test Plan: Task Generation is visibly functional with additional changes. Reviewers: epriestley Reviewed By: epriestley CC: AnhNhan, aran, Korvin Maniphest Tasks: T2903 Differential Revision: https://secure.phabricator.com/D5799
1 parent 0ecc5de commit c7be6f4

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,77 @@ final class PhabricatorManiphestTaskTestDataGenerator
44
extends PhabricatorTestDataGenerator {
55

66
public function generate() {
7-
return id(new ManiphestTask())
8-
->setStatus($this->generateTaskStatus())
9-
->setPriority($this->generateTaskPriority())
7+
$authorPHID = $this->loadAuthorPHID();
8+
$author = id(new PhabricatorUser())
9+
->loadOneWhere('phid = %s', $authorPHID);
10+
$task = id(new ManiphestTask())
1011
->setSubPriority($this->generateTaskSubPriority())
11-
->setAuthorPHID($this->loadAuthorPHID())
12-
->setTitle($this->generateTitle())
13-
->setDescription($this->generateDescription())
14-
->setOwnerPHID($this->loadOwnerPHID())
15-
->save();
12+
->setAuthorPHID($authorPHID)
13+
->setTitle($this->generateTitle());
14+
$content_source = PhabricatorContentSource::newForSource(
15+
PhabricatorContentSource::SOURCE_UNKNOWN,
16+
array());
17+
$template = id(new ManiphestTransaction())
18+
->setAuthorPHID($authorPHID)
19+
->setContentSource($content_source);
20+
// Accumulate Transactions
21+
$changes = array();
22+
$changes[ManiphestTransactionType::TYPE_TITLE] =
23+
$this->generateTitle();
24+
$changes[ManiphestTransactionType::TYPE_DESCRIPTION] =
25+
$this->generateDescription();
26+
$changes[ManiphestTransactionType::TYPE_OWNER] =
27+
$this->loadOwnerPHID();
28+
$changes[ManiphestTransactionType::TYPE_STATUS] =
29+
$this->generateTaskStatus();
30+
$changes[ManiphestTransactionType::TYPE_PRIORITY] =
31+
$this->generateTaskPriority();
32+
$changes[ManiphestTransactionType::TYPE_CCS] =
33+
$this->getCCPHIDs();
34+
$changes[ManiphestTransactionType::TYPE_PROJECTS] =
35+
$this->getProjectPHIDs();
36+
$transactions = array();
37+
foreach ($changes as $type => $value) {
38+
$transaction = clone $template;
39+
$transaction->setTransactionType($type);
40+
$transaction->setNewValue($value);
41+
$transactions[] = $transaction;
42+
}
43+
// Accumulate Auxiliary Transactions
44+
$aux_fields = id(ManiphestTaskExtensions::newExtensions())
45+
->loadFields($task, $author);
46+
if ($aux_fields) {
47+
foreach ($aux_fields as $aux_field) {
48+
$transaction = clone $template;
49+
$transaction->setTransactionType(
50+
ManiphestTransactionType::TYPE_AUXILIARY);
51+
$aux_key = $aux_field->getAuxiliaryKey();
52+
$transaction->setMetadataValue('aux:key', $aux_key);
53+
$transaction->setNewValue($aux_field->getValueForStorage());
54+
$transactions[] = $transaction;
55+
}
56+
}
57+
// Apply Transactions
58+
$editor = id(new ManiphestTransactionEditor())
59+
->setActor($author)
60+
->applyTransactions($task, $transactions);
61+
return $task->save();
62+
}
63+
64+
public function getCCPHIDs() {
65+
$ccs = array();
66+
for ($i = 0; $i < rand(1, 4);$i++) {
67+
$ccs[] = $this->loadPhabrictorUserPHID();
68+
}
69+
return $ccs;
70+
}
71+
72+
public function getProjectPHIDs() {
73+
$projects = array();
74+
for ($i = 0; $i < rand(1, 4);$i++) {
75+
$projects[] = $this->loadOneRandom("PhabricatorProject")->getPHID();
76+
}
77+
return $projects;
1678
}
1779

1880
private function loadPhabrictorUserPHID() {

0 commit comments

Comments
 (0)