mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 01:10:58 +01:00
Successfully Generated People
Summary: Ref T2903 Test Plan: Added new person whose profile was visible afterwards. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan, btrahan Maniphest Tasks: T2903 Differential Revision: https://secure.phabricator.com/D5682
This commit is contained in:
parent
8ea5c8c74e
commit
5107cc908e
4 changed files with 124 additions and 2 deletions
|
@ -1204,6 +1204,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleLogsController' => 'applications/people/controller/PhabricatorPeopleLogsController.php',
|
||||
'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php',
|
||||
'PhabricatorPeopleQuery' => 'applications/people/PhabricatorPeopleQuery.php',
|
||||
'PhabricatorPeopleTestDataGenerator' => 'applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php',
|
||||
'PhabricatorPhabricatorOAuthConfigOptions' => 'applications/config/option/PhabricatorPhabricatorOAuthConfigOptions.php',
|
||||
'PhabricatorPhameConfigOptions' => 'applications/phame/config/PhabricatorPhameConfigOptions.php',
|
||||
'PhabricatorPholioConfigOptions' => 'applications/pholio/config/PhabricatorPholioConfigOptions.php',
|
||||
|
@ -1401,6 +1402,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTagView' => 'view/layout/PhabricatorTagView.php',
|
||||
'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php',
|
||||
'PhabricatorTestCase' => 'infrastructure/testing/PhabricatorTestCase.php',
|
||||
'PhabricatorTestDataGenerator' => 'applications/lipsum/generator/PhabricatorTestDataGenerator.php',
|
||||
'PhabricatorTestStorageEngine' => 'applications/files/engine/PhabricatorTestStorageEngine.php',
|
||||
'PhabricatorTestWorker' => 'infrastructure/daemon/workers/__tests__/PhabricatorTestWorker.php',
|
||||
'PhabricatorTimelineCursor' => 'infrastructure/daemon/timeline/storage/PhabricatorTimelineCursor.php',
|
||||
|
@ -2886,6 +2888,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'PhabricatorPeopleTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorPhabricatorOAuthConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorPhameConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorPholioConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
$this
|
||||
->setName('generate')
|
||||
->setExamples('**generate**')
|
||||
->setSynopsis('Generate some Lipsum.')
|
||||
->setSynopsis('Generate some lipsum.')
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
|
@ -18,7 +18,13 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
echo "Lipsum Generator";
|
||||
$admin = PhabricatorUser::getOmnipotentUser();
|
||||
$peoplegen = new PhabricatorPeopleTestDataGenerator();
|
||||
$object = $peoplegen->generate();
|
||||
$handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||
$admin);
|
||||
echo "Generated ".$handle->getFullName()."\n";
|
||||
echo "\nRequested data has been generated.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPeopleTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$realname = $this->generateRealname();
|
||||
$username = $this->generateUsername($realname);
|
||||
$email = $this->generateEmail($username);
|
||||
|
||||
$admin = PhabricatorUser::getOmnipotentUser();
|
||||
$user = new PhabricatorUser();
|
||||
$user->setUsername($username);
|
||||
$user->setRealname($realname);
|
||||
|
||||
$email_object = id(new PhabricatorUserEmail())
|
||||
->setAddress($email)
|
||||
->setIsVerified(1);
|
||||
|
||||
id(new PhabricatorUserEditor())
|
||||
->setActor($admin)
|
||||
->createNewUser($user, $email_object);
|
||||
|
||||
return $user;
|
||||
} catch (AphrontQueryDuplicateKeyException $ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateRealname() {
|
||||
$realname_generator = new PhutilRealnameContextFreeGrammar();
|
||||
$random_real_name = $realname_generator->generate();
|
||||
return $random_real_name;
|
||||
}
|
||||
|
||||
protected function generateUsername($random_real_name) {
|
||||
$name = strtolower($random_real_name);
|
||||
$name = preg_replace('/[^a-z]/s' , ' ', $name);
|
||||
$words = explode(" ", $name);
|
||||
$random = rand(0, 4);
|
||||
$reduced = "";
|
||||
if ($random == 0) {
|
||||
foreach ($words as $w) {
|
||||
if ($w == end($words)) {
|
||||
$reduced .= $w;
|
||||
}
|
||||
else {
|
||||
$reduced .= $w[0];
|
||||
}
|
||||
}
|
||||
} elseif ($random == 1) {
|
||||
foreach ($words as $w) {
|
||||
if ($w == $words[0]) {
|
||||
$reduced .= $w;
|
||||
}
|
||||
else {
|
||||
$reduced .= $w[0];
|
||||
}
|
||||
}
|
||||
} elseif ($random == 2) {
|
||||
foreach ($words as $w) {
|
||||
if ($w == $words[0] || $w == end($words)) {
|
||||
$reduced .= $w;
|
||||
}
|
||||
else {
|
||||
$reduced .= $w[0];
|
||||
}
|
||||
}
|
||||
} elseif ($random == 3) {
|
||||
foreach ($words as $w) {
|
||||
if ($w == $words[0] || $w == end($words)) {
|
||||
$reduced .= $w;
|
||||
}
|
||||
else {
|
||||
$reduced .= $w[0].".";
|
||||
}
|
||||
}
|
||||
} elseif ($random == 4) {
|
||||
foreach ($words as $w) {
|
||||
if ($w == $words[0] || $w == end($words)) {
|
||||
$reduced .= $w;
|
||||
}
|
||||
else {
|
||||
$reduced .= $w[0]."_";
|
||||
}
|
||||
}
|
||||
}
|
||||
$random1 = rand(0, 4);
|
||||
if ($random1 >= 1) {
|
||||
$reduced = ucfirst($reduced);
|
||||
}
|
||||
$username = $reduced;
|
||||
return $username;
|
||||
}
|
||||
|
||||
protected function generateEmail($username) {
|
||||
$default_email_domain = "example.com";
|
||||
$email = $username."@".$default_email_domain;
|
||||
return $email;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue