Page MenuHomePhorge

No OneTemporary

diff --git a/scripts/lipsum/manage_lipsum.php b/scripts/lipsum/manage_lipsum.php
index c2fa8f3a3b..9d45b573d4 100755
--- a/scripts/lipsum/manage_lipsum.php
+++ b/scripts/lipsum/manage_lipsum.php
@@ -1,21 +1,21 @@
#!/usr/bin/env php
<?php
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
-$args->setTagline(pht('manage lipsum'));
+$args->setTagline(pht('synthetic data generator'));
$args->setSynopsis(<<<EOSYNOPSIS
**lipsum** __command__ [__options__]
- Manage Phabricator Test Data Generator.
+ Generate synthetic test data to make development easier.
EOSYNOPSIS
);
$args->parseStandardArguments();
$workflows = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorLipsumManagementWorkflow')
->execute();
$workflows[] = new PhutilHelpArgumentWorkflow();
$args->parseWorkflows($workflows);
diff --git a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
index ec346f26ae..2620216d9f 100644
--- a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
+++ b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
@@ -1,104 +1,108 @@
<?php
final class PhabricatorDifferentialRevisionTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Differential Revisions');
+ }
+
+ public function generateObject() {
$author = $this->loadPhabrictorUser();
$revision = DifferentialRevision::initializeNewRevision($author);
$revision->attachReviewerStatus(array());
$revision->attachActiveDiff(null);
// This could be a bit richer and more formal than it is.
$revision->setTitle($this->generateTitle());
$revision->setSummary($this->generateDescription());
$revision->setTestPlan($this->generateDescription());
$diff = $this->generateDiff($author);
$xactions = array();
$xactions[] = id(new DifferentialTransaction())
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
->setNewValue($diff->getPHID());
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LIPSUM,
array());
id(new DifferentialTransactionEditor())
->setActor($author)
->setContentSource($content_source)
->applyTransactions($revision, $xactions);
return $revision;
}
public function getCCPHIDs() {
$ccs = array();
for ($i = 0; $i < rand(1, 4);$i++) {
$ccs[] = $this->loadPhabrictorUserPHID();
}
return $ccs;
}
public function generateDiff($author) {
$paste_generator = new PhabricatorPasteTestDataGenerator();
$languages = $paste_generator->supportedLanguages;
$lang = array_rand($languages);
$code = $paste_generator->generateContent($lang);
$altcode = $paste_generator->generateContent($lang);
$newcode = $this->randomlyModify($code, $altcode);
$diff = id(new PhabricatorDifferenceEngine())
->generateRawDiffFromFileContent($code, $newcode);
$call = new ConduitCall(
'differential.createrawdiff',
array(
'diff' => $diff,
));
$call->setUser($author);
$result = $call->execute();
$thediff = id(new DifferentialDiff())->load(
$result['id']);
$thediff->setDescription($this->generateTitle())->save();
return $thediff;
}
public function generateDescription() {
return id(new PhutilLipsumContextFreeGrammar())
->generate(10, 20);
}
public function generateTitle() {
return id(new PhutilLipsumContextFreeGrammar())
->generate();
}
public function randomlyModify($code, $altcode) {
$codearr = explode("\n", $code);
$altcodearr = explode("\n", $altcode);
$no_lines_to_delete = rand(1,
min(count($codearr) - 2, 5));
$randomlines = array_rand($codearr,
count($codearr) - $no_lines_to_delete);
$newcode = array();
foreach ($randomlines as $lineno) {
$newcode[] = $codearr[$lineno];
}
$newlines_count = rand(2,
min(count($codearr) - 2, count($altcodearr) - 2, 5));
$randomlines_orig = array_rand($codearr, $newlines_count);
$randomlines_new = array_rand($altcodearr, $newlines_count);
$newcode2 = array();
$c = 0;
for ($i = 0; $i < count($newcode);$i++) {
$newcode2[] = $newcode[$i];
if (in_array($i, $randomlines_orig)) {
$newcode2[] = $altcodearr[$randomlines_new[$c++]];
}
}
return implode($newcode2, "\n");
}
}
diff --git a/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php b/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
index cc5e6fe195..cf084d32a7 100644
--- a/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
+++ b/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
@@ -1,20 +1,24 @@
<?php
final class PhabricatorFileTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Files');
+ }
+
+ public function generateObject() {
$author_phid = $this->loadPhabrictorUserPHID();
$dimension = 1 << rand(5, 12);
$image = id(new PhabricatorLipsumMondrianArtist())
->generate($dimension, $dimension);
$file = PhabricatorFile::newFromFileData(
$image,
array(
'name' => 'rand-'.rand(1000, 9999),
));
$file->setAuthorPHID($author_phid);
$file->setMimeType('image/jpeg');
return $file->save();
}
}
diff --git a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
index 9bff25a068..695e3e6e8f 100644
--- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
+++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
@@ -1,30 +1,29 @@
<?php
abstract class PhabricatorTestDataGenerator extends Phobject {
- public function generate() {
- return;
- }
+ abstract public function getGeneratorName();
+ abstract public function generateObject();
public function loadOneRandom($classname) {
try {
return newv($classname, array())
->loadOneWhere('1 = 1 ORDER BY RAND() LIMIT 1');
} catch (PhutilMissingSymbolException $ex) {
throw new PhutilMissingSymbolException(
pht(
'Unable to load symbol %s: this class does not exit.',
$classname));
}
}
public function loadPhabrictorUserPHID() {
return $this->loadOneRandom('PhabricatorUser')->getPHID();
}
public function loadPhabrictorUser() {
return $this->loadOneRandom('PhabricatorUser');
}
}
diff --git a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
index ca0b63e263..215f99402e 100644
--- a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
+++ b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
@@ -1,95 +1,142 @@
<?php
final class PhabricatorLipsumGenerateWorkflow
extends PhabricatorLipsumManagementWorkflow {
protected function didConstruct() {
$this
->setName('generate')
->setExamples('**generate**')
- ->setSynopsis(pht('Generate some lipsum.'))
+ ->setSynopsis(pht('Generate synthetic test objects.'))
->setArguments(
array(
array(
'name' => 'args',
'wildcard' => true,
),
));
}
public function execute(PhutilArgumentParser $args) {
- $console = PhutilConsole::getConsole();
+ $config_key = 'phabricator.developer-mode';
+ if (!PhabricatorEnv::getEnvConfig($config_key)) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'lipsum is a development and testing tool and may only be run '.
+ 'on installs in developer mode. Enable "%s" in your configuration '.
+ 'to enable lipsum.',
+ $config_key));
+ }
- $supported_types = id(new PhutilClassMapQuery())
+ $all_generators = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorTestDataGenerator')
->execute();
- $console->writeOut(
- "%s:\n\t%s\n",
- pht('These are the types of data you can generate'),
- implode("\n\t", array_keys($supported_types)));
+ $argv = $args->getArg('args');
+ $all = 'all';
- $prompt = pht('Are you sure you want to generate lots of test data?');
- if (!phutil_console_confirm($prompt, true)) {
- return;
+ if (!$argv) {
+ $names = mpull($all_generators, 'getGeneratorName');
+ sort($names);
+
+ $list = id(new PhutilConsoleList())
+ ->setWrap(false)
+ ->addItems($names);
+
+ id(new PhutilConsoleBlock())
+ ->addParagraph(
+ pht(
+ 'Choose which type or types of test data you want to generate, '.
+ 'or select "%s".',
+ $all))
+ ->addList($list)
+ ->draw();
+
+ return 0;
}
- $argv = $args->getArg('args');
- if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) {
- $this->infinitelyGenerate($supported_types);
- } else {
- $new_supported_types = array();
- for ($i = 0; $i < count($argv); $i++) {
- $arg = $argv[$i];
- if (array_key_exists($arg, $supported_types)) {
- $new_supported_types[$arg] = $supported_types[$arg];
- } else {
- $console->writeErr(
- "%s\n",
- pht(
- 'The type %s is not supported by the lipsum generator.',
- $arg));
+ $generators = array();
+ foreach ($argv as $arg_original) {
+ $arg = phutil_utf8_strtolower($arg_original);
+
+ $match = false;
+ foreach ($all_generators as $generator) {
+ $name = phutil_utf8_strtolower($generator->getGeneratorName());
+
+ if ($arg == $all) {
+ $generators[] = $generator;
+ $match = true;
+ break;
+ }
+
+ if (strpos($name, $arg) !== false) {
+ $generators[] = $generator;
+ $match = true;
+ break;
}
}
- $this->infinitelyGenerate($new_supported_types);
+
+ if (!$match) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Argument "%s" does not match the name of any generators.',
+ $arg_original));
+ }
}
- $console->writeOut(
- "%s\n%s:\n%s\n",
- pht('None of the input types were supported.'),
- pht('The supported types are'),
- implode("\n", array_keys($supported_types)));
- }
+ echo tsprintf(
+ "**<bg:blue> %s </bg>** %s\n",
+ pht('GENERATORS'),
+ pht(
+ 'Selected generators: %s.',
+ implode(', ', mpull($generators, 'getGeneratorName'))));
- protected function infinitelyGenerate(array $supported_types) {
- $console = PhutilConsole::getConsole();
+ echo tsprintf(
+ "**<bg:yellow> %s </bg>** %s\n",
+ pht('WARNING'),
+ pht(
+ 'This command generates synthetic test data, including user '.
+ 'accounts. It is intended for use in development environments '.
+ 'so you can test features more easily. There is no easy way to '.
+ 'delete this data or undo the effects of this command. If you run '.
+ 'it in a production environment, it will pollute your data with '.
+ 'large amounts of meaningless garbage that you can not get rid of.'));
- if (count($supported_types) == 0) {
+ $prompt = pht('Are you sure you want to generate piles of garbage?');
+ if (!phutil_console_confirm($prompt, true)) {
return;
}
- $console->writeOut(
- "%s: %s\n",
- pht('GENERATING'),
- implode(', ', array_keys($supported_types)));
+
+ echo tsprintf(
+ "**<bg:green> %s </bg>** %s\n",
+ pht('LIPSUM'),
+ pht(
+ 'Generating synthetic test objects forever. '.
+ 'Use ^C to stop when satisfied.'));
+
+ $this->generate($generators);
+ }
+
+ protected function generate(array $generators) {
+ $viewer = $this->getViewer();
while (true) {
- $type = $supported_types[array_rand($supported_types)];
- $admin = $this->getViewer();
-
- $taskgen = newv($type, array());
- $object = $taskgen->generate();
- $handle = id(new PhabricatorHandleQuery())
- ->setViewer($admin)
- ->withPHIDs(array($object->getPHID()))
- ->executeOne();
-
- $console->writeOut(
- "%s: %s\n",
- pht('Generated %s', $handle->getTypeName()),
- $handle->getFullName());
-
- usleep(200000);
+ $generator = $generators[array_rand($generators)];
+
+ $object = $generator->generateObject();
+ $object_phid = $object->getPHID();
+
+ $handles = $viewer->loadHandles(array($object_phid));
+
+ echo tsprintf(
+ "%s\n",
+ pht(
+ 'Generated "%s": %s',
+ $handles[$object_phid]->getTypeName(),
+ $handles[$object_phid]->getFullName()));
+
+ sleep(1);
}
}
}
diff --git a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
index 0e6a94beba..e4147ad223 100644
--- a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
+++ b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
@@ -1,118 +1,122 @@
<?php
final class PhabricatorManiphestTaskTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Maniphest Tasks');
+ }
+
+ public function generateObject() {
$author_phid = $this->loadPhabrictorUserPHID();
$author = id(new PhabricatorUser())
->loadOneWhere('phid = %s', $author_phid);
$task = ManiphestTask::initializeNewTask($author)
->setSubPriority($this->generateTaskSubPriority())
->setTitle($this->generateTitle());
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_UNKNOWN,
array());
$template = new ManiphestTransaction();
// Accumulate Transactions
$changes = array();
$changes[ManiphestTransaction::TYPE_TITLE] =
$this->generateTitle();
$changes[ManiphestTransaction::TYPE_DESCRIPTION] =
$this->generateDescription();
$changes[ManiphestTransaction::TYPE_OWNER] =
$this->loadOwnerPHID();
$changes[ManiphestTransaction::TYPE_STATUS] =
$this->generateTaskStatus();
$changes[ManiphestTransaction::TYPE_PRIORITY] =
$this->generateTaskPriority();
$changes[PhabricatorTransactions::TYPE_SUBSCRIBERS] =
array('=' => $this->getCCPHIDs());
$transactions = array();
foreach ($changes as $type => $value) {
$transaction = clone $template;
$transaction->setTransactionType($type);
$transaction->setNewValue($value);
$transactions[] = $transaction;
}
$transactions[] = id(new ManiphestTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue(
'edge:type',
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)
->setNewValue(
array(
'=' => array_fuse($this->getProjectPHIDs()),
));
// Apply Transactions
$editor = id(new ManiphestTransactionEditor())
->setActor($author)
->setContentSource($content_source)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($task, $transactions);
return $task;
}
public function getCCPHIDs() {
$ccs = array();
for ($i = 0; $i < rand(1, 4);$i++) {
$ccs[] = $this->loadPhabrictorUserPHID();
}
return $ccs;
}
public function getProjectPHIDs() {
$projects = array();
for ($i = 0; $i < rand(1, 4);$i++) {
$project = $this->loadOneRandom('PhabricatorProject');
if ($project) {
$projects[] = $project->getPHID();
}
}
return $projects;
}
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::getDefaultStatus();
} else {
return array_rand($statuses);
}
}
}
diff --git a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
index 60c75083b6..4647d72a30 100644
--- a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
+++ b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
@@ -1,94 +1,98 @@
<?php
final class PhabricatorPasteTestDataGenerator
extends PhabricatorTestDataGenerator {
+ public function getGeneratorName() {
+ return pht('Pastes');
+ }
+
// Better Support for this in the future
public $supportedLanguages = array(
'Java' => 'java',
'PHP' => 'php',
);
- public function generate() {
+ public function generateObject() {
$author = $this->loadPhabrictorUser();
$authorphid = $author->getPHID();
$language = $this->generateLanguage();
$content = $this->generateContent($language);
$title = $this->generateTitle($language);
$paste_file = PhabricatorFile::newFromFileData(
$content,
array(
'name' => $title,
'mime-type' => 'text/plain; charset=utf-8',
'authorPHID' => $authorphid,
));
$policy = $this->generatePolicy();
$filephid = $paste_file->getPHID();
$parentphid = $this->loadPhabrictorPastePHID();
$paste = PhabricatorPaste::initializeNewPaste($author)
->setParentPHID($parentphid)
->setTitle($title)
->setLanguage($language)
->setViewPolicy($policy)
->setEditPolicy($policy)
->setFilePHID($filephid)
->save();
return $paste;
}
private function loadPhabrictorPastePHID() {
$random = rand(0, 1);
if ($random == 1) {
$paste = id($this->loadOneRandom('PhabricatorPaste'));
if ($paste) {
return $paste->getPHID();
}
}
return null;
}
public function generateTitle($language = null) {
$taskgen = new PhutilLipsumContextFreeGrammar();
// Remove Punctuation
$title = preg_replace('/[^a-zA-Z 0-9]+/', '', $taskgen->generate());
// Capitalize First Letters
$title = ucwords($title);
// Remove Spaces
$title = preg_replace('/\s+/', '', $title);
if ($language == null ||
!in_array($language, array_keys($this->supportedLanguages))) {
return $title.'.txt';
} else {
return $title.'.'.$this->supportedLanguages[$language];
}
}
public function generateLanguage() {
$supplemented_lang = $this->supportedLanguages;
$supplemented_lang['lipsum'] = 'txt';
return array_rand($supplemented_lang);
}
public function generateContent($language = null) {
if ($language == null ||
!in_array($language, array_keys($this->supportedLanguages))) {
return id(new PhutilLipsumContextFreeGrammar())
->generateSeveral(rand(30, 40));
} else {
$cfg_class = 'Phutil'.$language.'CodeSnippetContextFreeGrammar';
return newv($cfg_class, array())->generate();
}
}
public function generatePolicy() {
// Make sure 4/5th of all generated Pastes are viewable to all
switch (rand(0, 4)) {
case 0:
return PhabricatorPolicies::POLICY_PUBLIC;
case 1:
return PhabricatorPolicies::POLICY_NOONE;
default:
return PhabricatorPolicies::POLICY_USER;
}
}
}
diff --git a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
index bb7e73ceef..9b05b4acb1 100644
--- a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
+++ b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
@@ -1,99 +1,103 @@
<?php
final class PhabricatorPeopleTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('User Accounts');
+ }
+
+ public function generateObject() {
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 (AphrontDuplicateKeyQueryException $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);
$name = preg_replace('/\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];
}
}
} else if ($random == 1) {
foreach ($words as $w) {
if ($w == $words[0]) {
$reduced .= $w;
} else {
$reduced .= $w[0];
}
}
} else if ($random == 2) {
foreach ($words as $w) {
if ($w == $words[0] || $w == end($words)) {
$reduced .= $w;
} else {
$reduced .= $w[0];
}
}
} else if ($random == 3) {
foreach ($words as $w) {
if ($w == $words[0] || $w == end($words)) {
$reduced .= $w;
} else {
$reduced .= $w[0].'.';
}
}
} else if ($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;
}
}
diff --git a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
index a2fb3b38fb..ce620a0d3a 100644
--- a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
+++ b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
@@ -1,114 +1,118 @@
<?php
final class PhabricatorPholioMockTestDataGenerator
extends PhabricatorTestDataGenerator {
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Pholio Mocks');
+ }
+
+ public function generateObject() {
$author_phid = $this->loadPhabrictorUserPHID();
$author = id(new PhabricatorUser())
->loadOneWhere('phid = %s', $author_phid);
$mock = PholioMock::initializeNewMock($author);
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_UNKNOWN,
array());
$template = id(new PholioTransaction())
->setContentSource($content_source);
// Accumulate Transactions
$changes = array();
$changes[PholioTransaction::TYPE_NAME] =
$this->generateTitle();
$changes[PholioTransaction::TYPE_DESCRIPTION] =
$this->generateDescription();
$changes[PhabricatorTransactions::TYPE_VIEW_POLICY] =
PhabricatorPolicies::POLICY_PUBLIC;
$changes[PhabricatorTransactions::TYPE_SUBSCRIBERS] =
array('=' => $this->getCCPHIDs());
// Get Files and make Images
$file_phids = $this->generateImages();
$files = id(new PhabricatorFileQuery())
->setViewer($author)
->withPHIDs($file_phids)
->execute();
$mock->setCoverPHID(head($files)->getPHID());
$sequence = 0;
$images = array();
foreach ($files as $file) {
$image = new PholioImage();
$image->setFilePHID($file->getPHID());
$image->setSequence($sequence++);
$image->attachMock($mock);
$images[] = $image;
}
// Apply Transactions
$transactions = array();
foreach ($changes as $type => $value) {
$transaction = clone $template;
$transaction->setTransactionType($type);
$transaction->setNewValue($value);
$transactions[] = $transaction;
}
$mock->openTransaction();
$editor = id(new PholioMockEditor())
->setContentSource($content_source)
->setContinueOnNoEffect(true)
->setActor($author)
->applyTransactions($mock, $transactions);
foreach ($images as $image) {
$image->setMockID($mock->getID());
$image->save();
}
$mock->saveTransaction();
return $mock->save();
}
public function generateTitle() {
return id(new PhutilLipsumContextFreeGrammar())
->generate();
}
public function generateDescription() {
return id(new PhutilLipsumContextFreeGrammar())
->generateSeveral(rand(30, 40));
}
public function getCCPHIDs() {
$ccs = array();
for ($i = 0; $i < rand(1, 4);$i++) {
$ccs[] = $this->loadPhabrictorUserPHID();
}
return $ccs;
}
public function generateImages() {
$images = newv('PhabricatorFile', array())
->loadAllWhere('mimeType = %s', 'image/jpeg');
$rand_images = array();
$quantity = rand(2, 10);
$quantity = min($quantity, count($images));
if ($quantity) {
$random_images = $quantity === 1 ?
array(array_rand($images, $quantity)) :
array_rand($images, $quantity);
foreach ($random_images as $random) {
$rand_images[] = $images[$random]->getPHID();
}
}
// This means you don't have any JPEGs yet. We'll just use a built-in image.
if (empty($rand_images)) {
$default = PhabricatorFile::loadBuiltin(
PhabricatorUser::getOmnipotentUser(),
'profile.png');
$rand_images[] = $default->getPHID();
}
return $rand_images;
}
}
diff --git a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
index 0462bdd790..8ffa66e331 100644
--- a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
+++ b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
@@ -1,77 +1,81 @@
<?php
final class PhabricatorProjectTestDataGenerator
extends PhabricatorTestDataGenerator {
private $xactions = array();
- public function generate() {
+ public function getGeneratorName() {
+ return pht('Projects');
+ }
+
+ public function generateObject() {
$title = $this->generateTitle();
$author = $this->loadPhabrictorUser();
$author_phid = $author->getPHID();
$project = PhabricatorProject::initializeNewProject($author)
->setName($title);
$this->addTransaction(
PhabricatorProjectTransaction::TYPE_NAME,
$title);
$project->attachMemberPHIDs(
$this->loadMembersWithAuthor($author_phid));
$this->addTransaction(
PhabricatorProjectTransaction::TYPE_STATUS,
$this->generateProjectStatus());
$this->addTransaction(
PhabricatorTransactions::TYPE_VIEW_POLICY,
PhabricatorPolicies::POLICY_PUBLIC);
$this->addTransaction(
PhabricatorTransactions::TYPE_EDIT_POLICY,
PhabricatorPolicies::POLICY_PUBLIC);
$this->addTransaction(
PhabricatorTransactions::TYPE_JOIN_POLICY,
PhabricatorPolicies::POLICY_PUBLIC);
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($author)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContinueOnNoEffect(true)
->applyTransactions($project, $this->xactions);
return $project->save();
}
private function addTransaction($type, $value) {
$this->xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType($type)
->setNewValue($value);
}
public function loadMembersWithAuthor($author) {
$members = array($author);
for ($i = 0; $i < rand(10, 20);$i++) {
$members[] = $this->loadPhabrictorUserPHID();
}
return $members;
}
public function generateTitle() {
return id(new PhutilLipsumContextFreeGrammar())
->generate();
}
public function generateDescription() {
return id(new PhutilLipsumContextFreeGrammar())
->generateSeveral(rand(30, 40));
}
public function generateProjectStatus() {
$statuses = array_keys(PhabricatorProjectStatus::getStatusMap());
// Make sure 4/5th of all generated Projects are active
$random = rand(0, 4);
if ($random != 0) {
return $statuses[0];
} else {
return $statuses[1];
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Jan 19 2025, 20:39 (6 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1128524
Default Alt Text
(30 KB)

Event Timeline