mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 23:01:04 +01:00
Completed Paste Generation
Summary: Ref T2903 Test Plan: Pastes being generated with all types of parents, view policies, code, etc. Reviewers: epriestley, AnhNhan Reviewed By: epriestley CC: AnhNhan, aran, Korvin Maniphest Tasks: T2903 Differential Revision: https://secure.phabricator.com/D5707
This commit is contained in:
parent
eaa4362979
commit
1b4dde8027
4 changed files with 130 additions and 17 deletions
|
@ -1207,6 +1207,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
||||
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
||||
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
||||
'PhabricatorPasteTestDataGenerator' => 'applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php',
|
||||
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
|
||||
'PhabricatorPeopleController' => 'applications/people/controller/PhabricatorPeopleController.php',
|
||||
'PhabricatorPeopleEditController' => 'applications/people/controller/PhabricatorPeopleEditController.php',
|
||||
|
@ -1310,6 +1311,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositorySymbol' => 'applications/repository/storage/PhabricatorRepositorySymbol.php',
|
||||
'PhabricatorRepositoryTestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php',
|
||||
'PhabricatorRepositoryType' => 'applications/repository/constants/PhabricatorRepositoryType.php',
|
||||
'PhabricatorRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorRevisionTestDataGenerator.php',
|
||||
'PhabricatorS3FileStorageEngine' => 'applications/files/engine/PhabricatorS3FileStorageEngine.php',
|
||||
'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php',
|
||||
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
|
||||
|
@ -2915,6 +2917,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorPasteTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorPasteViewController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPeopleController' => 'PhabricatorController',
|
||||
'PhabricatorPeopleEditController' => 'PhabricatorPeopleController',
|
||||
|
@ -3022,6 +3025,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
||||
'PhabricatorRepositorySymbol' => 'PhabricatorRepositoryDAO',
|
||||
'PhabricatorRepositoryTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||
'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow',
|
||||
'PhabricatorSavedQuery' => 'PhabricatorSearchDAO',
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRevisionTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
try {
|
||||
$revision = new DifferentialRevision();
|
||||
echo id(new PhutilLipsumContextFreeGrammar())->generate();
|
||||
return $revision;
|
||||
} catch (AphrontQueryDuplicateKeyException $ex) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,26 +18,21 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$type = "Paste";
|
||||
$classname = "Phabricator".$type."TestDataGenerator";
|
||||
$admin = PhabricatorUser::getOmnipotentUser();
|
||||
// $peoplegen = new PhabricatorPeopleTestDataGenerator();
|
||||
// $object = $peoplegen->generate();
|
||||
// $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||
// $admin);
|
||||
// echo "Generated ".$handle->getFullName()."\n";
|
||||
try {
|
||||
$taskgen = newv($classname, array());
|
||||
$object = $taskgen->generate();
|
||||
|
||||
$handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||
$admin);
|
||||
echo "Generated ".$handle->getFullName()."\n";
|
||||
echo "\nRequested data has been generated.";
|
||||
} catch (PhutilMissingSymbolException $ex) {
|
||||
}
|
||||
|
||||
$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,100 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPasteTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
// Better Support for this in the future
|
||||
private $supportedLanguages = array(
|
||||
"Java" => "java",
|
||||
"PHP" => "php");
|
||||
|
||||
public function generate() {
|
||||
$authorphid = $this->loadAuthorPHID();
|
||||
$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 = id(new PhabricatorPaste())
|
||||
->setParentPHID($parentphid)
|
||||
->setAuthorPHID($authorphid)
|
||||
->setTitle($title)
|
||||
->setLanguage($language)
|
||||
->setViewPolicy($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;
|
||||
}
|
||||
|
||||
private function loadPhabrictorUserPHID() {
|
||||
return id($this->loadOneRandom("PhabricatorUser"))->getPHID();
|
||||
}
|
||||
|
||||
public function loadAuthorPHID() {
|
||||
return $this->loadPhabrictorUserPHID();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue