Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
index 744a98b621..60c75083b6 100644
--- a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
+++ b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
@@ -1,93 +1,94 @@
<?php
final class PhabricatorPasteTestDataGenerator
extends PhabricatorTestDataGenerator {
// Better Support for this in the future
public $supportedLanguages = array(
'Java' => 'java',
'PHP' => 'php',
);
public function generate() {
- $authorphid = $this->loadPhabrictorUserPHID();
+ $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 = id(new PhabricatorPaste())
+ $paste = PhabricatorPaste::initializeNewPaste($author)
->setParentPHID($parentphid)
- ->setAuthorPHID($authorphid)
->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/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
index 2601284408..a2fb3b38fb 100644
--- a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
+++ b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
@@ -1,110 +1,114 @@
<?php
final class PhabricatorPholioMockTestDataGenerator
extends PhabricatorTestDataGenerator {
public function generate() {
$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) {
- foreach (array_rand($images, $quantity) as $random) {
+ $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 fd797ca1fd..0462bdd790 100644
--- a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
+++ b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
@@ -1,78 +1,77 @@
<?php
final class PhabricatorProjectTestDataGenerator
extends PhabricatorTestDataGenerator {
private $xactions = array();
public function generate() {
$title = $this->generateTitle();
$author = $this->loadPhabrictorUser();
$author_phid = $author->getPHID();
- $project = id(new PhabricatorProject())
- ->setName($title)
- ->setAuthorPHID($author_phid);
+ $project = PhabricatorProject::initializeNewProject($author)
+ ->setName($title);
$this->addTransaction(
PhabricatorProjectTransaction::TYPE_NAME,
$title);
- $this->addTransaction(
- PhabricatorProjectTransaction::TYPE_MEMBERS,
+ $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
Tue, Jul 29, 2:55 AM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
187903
Default Alt Text
(9 KB)

Event Timeline