mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
Fixed Task Generation
Summary: Ref T2903 Test Plan: Successfully generated tasks with authors and owners. Reviewers: epriestley, AnhNhan Reviewed By: epriestley CC: aran, Korvin, AnhNhan, chad Maniphest Tasks: T2903 Differential Revision: https://secure.phabricator.com/D5704
This commit is contained in:
parent
f302751a23
commit
1e2f01efc2
5 changed files with 92 additions and 2 deletions
|
@ -1089,6 +1089,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMainMenuSearchView' => 'view/page/menu/PhabricatorMainMenuSearchView.php',
|
||||
'PhabricatorMainMenuView' => 'view/page/menu/PhabricatorMainMenuView.php',
|
||||
'PhabricatorManiphestConfigOptions' => 'applications/maniphest/config/PhabricatorManiphestConfigOptions.php',
|
||||
'PhabricatorManiphestTaskTestDataGenerator' => 'applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php',
|
||||
'PhabricatorMarkupCache' => 'applications/cache/storage/PhabricatorMarkupCache.php',
|
||||
'PhabricatorMarkupEngine' => 'infrastructure/markup/PhabricatorMarkupEngine.php',
|
||||
'PhabricatorMarkupInterface' => 'infrastructure/markup/PhabricatorMarkupInterface.php',
|
||||
|
@ -2793,6 +2794,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMainMenuSearchView' => 'AphrontView',
|
||||
'PhabricatorMainMenuView' => 'AphrontView',
|
||||
'PhabricatorManiphestConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorManiphestTaskTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorMarkupCache' => 'PhabricatorCacheDAO',
|
||||
'PhabricatorMenuItemView' => 'AphrontTagView',
|
||||
'PhabricatorMenuView' => 'AphrontTagView',
|
||||
|
|
|
@ -6,4 +6,14 @@ abstract class PhabricatorTestDataGenerator {
|
|||
return;
|
||||
}
|
||||
|
||||
public function loadOneRandom($classname) {
|
||||
try {
|
||||
return newv($classname, array())
|
||||
->loadOneWhere("1 = 1 ORDER BY RAND() LIMIT 1");
|
||||
} catch (PhutilMissingSymbolException $ex) {
|
||||
throw new PhutilMissingSymbolException(
|
||||
"Unable to load symbol ".$classname.": this class does not exit.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,12 +19,25 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$admin = PhabricatorUser::getOmnipotentUser();
|
||||
$peoplegen = new PhabricatorPeopleTestDataGenerator();
|
||||
$object = $peoplegen->generate();
|
||||
// $peoplegen = new PhabricatorPeopleTestDataGenerator();
|
||||
// $object = $peoplegen->generate();
|
||||
// $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||
// $admin);
|
||||
// echo "Generated ".$handle->getFullName()."\n";
|
||||
|
||||
$taskgen = new PhabricatorManiphestTaskTestDataGenerator();
|
||||
$object = $taskgen->generate();
|
||||
$handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||
$admin);
|
||||
echo "Generated ".$handle->getFullName()."\n";
|
||||
echo "\nRequested data has been generated.";
|
||||
|
||||
// $taskgen = new PhabricatorRevisionTestDataGenerator();
|
||||
// $object = $taskgen->generate();
|
||||
// $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||
// $admin);
|
||||
// echo "Generated ".$handle->getFullName()."\n";
|
||||
// echo "\nRequested data has been generated.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorManiphestTaskTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
return id(new ManiphestTask())
|
||||
->setStatus($this->generateTaskStatus())
|
||||
->setPriority($this->generateTaskPriority())
|
||||
->setSubPriority($this->generateTaskSubPriority())
|
||||
->setAuthorPHID($this->loadAuthorPHID())
|
||||
->setTitle($this->generateTitle())
|
||||
->setDescription($this->generateDescription())
|
||||
->setOwnerPHID($this->loadOwnerPHID())
|
||||
->save();
|
||||
}
|
||||
|
||||
private function loadPhabrictorUserPHID() {
|
||||
return $this->loadOneRandom("PhabricatorUser")->getPHID();
|
||||
}
|
||||
|
||||
public function loadAuthorPHID() {
|
||||
return $this->loadPhabrictorUserPHID();
|
||||
}
|
||||
|
||||
public function loadOwnerPHID() {
|
||||
if (rand(0, 3) == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return $this->loadPhabrictorUserPHID();
|
||||
}
|
||||
}
|
||||
|
||||
public function generateTitle() {
|
||||
return id(new PhutilLipsumContextFreeGrammar())
|
||||
->generate();
|
||||
}
|
||||
|
||||
public function generateDescription() {
|
||||
return id(new PhutilLipsumContextFreeGrammar())
|
||||
->generateSeveral(rand(30, 40));
|
||||
}
|
||||
|
||||
public function generateTaskPriority() {
|
||||
return array_rand(ManiphestTaskPriority::getTaskPriorityMap());
|
||||
}
|
||||
|
||||
public function generateTaskSubPriority() {
|
||||
return rand(2 << 16, 2 << 32);
|
||||
}
|
||||
|
||||
public function generateTaskStatus() {
|
||||
$statuses = array_keys(ManiphestTaskStatus::getTaskStatusMap());
|
||||
// Make sure 4/5th of all generated Tasks are open
|
||||
$random = rand(0, 4);
|
||||
if ($random != 0) {
|
||||
return ManiphestTaskStatus::STATUS_OPEN;
|
||||
} else {
|
||||
return array_rand($statuses);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -39,6 +39,7 @@ final class PhabricatorPeopleTestDataGenerator
|
|||
protected function generateUsername($random_real_name) {
|
||||
$name = strtolower($random_real_name);
|
||||
$name = preg_replace('/[^a-z]/s' , ' ', $name);
|
||||
$name = preg_replace('/\s+/', ' ', $name);
|
||||
$words = explode(" ", $name);
|
||||
$random = rand(0, 4);
|
||||
$reduced = "";
|
||||
|
|
Loading…
Reference in a new issue