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:
@@ -1207,6 +1207,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
||||||
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
||||||
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
||||||
|
'PhabricatorPasteTestDataGenerator' => 'applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php',
|
||||||
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
|
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
|
||||||
'PhabricatorPeopleController' => 'applications/people/controller/PhabricatorPeopleController.php',
|
'PhabricatorPeopleController' => 'applications/people/controller/PhabricatorPeopleController.php',
|
||||||
'PhabricatorPeopleEditController' => 'applications/people/controller/PhabricatorPeopleEditController.php',
|
'PhabricatorPeopleEditController' => 'applications/people/controller/PhabricatorPeopleEditController.php',
|
||||||
@@ -1310,6 +1311,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorRepositorySymbol' => 'applications/repository/storage/PhabricatorRepositorySymbol.php',
|
'PhabricatorRepositorySymbol' => 'applications/repository/storage/PhabricatorRepositorySymbol.php',
|
||||||
'PhabricatorRepositoryTestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php',
|
'PhabricatorRepositoryTestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php',
|
||||||
'PhabricatorRepositoryType' => 'applications/repository/constants/PhabricatorRepositoryType.php',
|
'PhabricatorRepositoryType' => 'applications/repository/constants/PhabricatorRepositoryType.php',
|
||||||
|
'PhabricatorRevisionTestDataGenerator' => 'applications/differential/lipsum/PhabricatorRevisionTestDataGenerator.php',
|
||||||
'PhabricatorS3FileStorageEngine' => 'applications/files/engine/PhabricatorS3FileStorageEngine.php',
|
'PhabricatorS3FileStorageEngine' => 'applications/files/engine/PhabricatorS3FileStorageEngine.php',
|
||||||
'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php',
|
'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php',
|
||||||
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
|
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
|
||||||
@@ -2915,6 +2917,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||||
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
|
'PhabricatorPasteTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||||
'PhabricatorPasteViewController' => 'PhabricatorPasteController',
|
'PhabricatorPasteViewController' => 'PhabricatorPasteController',
|
||||||
'PhabricatorPeopleController' => 'PhabricatorController',
|
'PhabricatorPeopleController' => 'PhabricatorController',
|
||||||
'PhabricatorPeopleEditController' => 'PhabricatorPeopleController',
|
'PhabricatorPeopleEditController' => 'PhabricatorPeopleController',
|
||||||
@@ -3022,6 +3025,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
||||||
'PhabricatorRepositorySymbol' => 'PhabricatorRepositoryDAO',
|
'PhabricatorRepositorySymbol' => 'PhabricatorRepositoryDAO',
|
||||||
'PhabricatorRepositoryTestCase' => 'PhabricatorTestCase',
|
'PhabricatorRepositoryTestCase' => 'PhabricatorTestCase',
|
||||||
|
'PhabricatorRevisionTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||||
'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine',
|
'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||||
'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow',
|
'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow',
|
||||||
'PhabricatorSavedQuery' => 'PhabricatorSearchDAO',
|
'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) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
|
$type = "Paste";
|
||||||
|
$classname = "Phabricator".$type."TestDataGenerator";
|
||||||
$admin = PhabricatorUser::getOmnipotentUser();
|
$admin = PhabricatorUser::getOmnipotentUser();
|
||||||
// $peoplegen = new PhabricatorPeopleTestDataGenerator();
|
try {
|
||||||
// $object = $peoplegen->generate();
|
$taskgen = newv($classname, array());
|
||||||
// $handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
|
||||||
// $admin);
|
|
||||||
// echo "Generated ".$handle->getFullName()."\n";
|
|
||||||
|
|
||||||
$taskgen = new PhabricatorManiphestTaskTestDataGenerator();
|
|
||||||
$object = $taskgen->generate();
|
$object = $taskgen->generate();
|
||||||
|
|
||||||
$handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
$handle = PhabricatorObjectHandleData::loadOneHandle($object->getPHID(),
|
||||||
$admin);
|
$admin);
|
||||||
echo "Generated ".$handle->getFullName()."\n";
|
echo "Generated ".$handle->getFullName()."\n";
|
||||||
echo "\nRequested data has been generated.";
|
echo "\nRequested data has been generated.";
|
||||||
|
} catch (PhutilMissingSymbolException $ex) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// $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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user