[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/customfield/ -> DifferentialTestPlanField.php (source)

   1  <?php
   2  
   3  final class DifferentialTestPlanField
   4    extends DifferentialCoreCustomField {
   5  
   6    public function getFieldKey() {
   7      return 'differential:test-plan';
   8    }
   9  
  10    public function getFieldKeyForConduit() {
  11      return 'testPlan';
  12    }
  13  
  14    public function getFieldName() {
  15      return pht('Test Plan');
  16    }
  17  
  18    public function getFieldDescription() {
  19      return pht('Actions performed to verify the behavior of the change.');
  20    }
  21  
  22    protected function readValueFromRevision(
  23      DifferentialRevision $revision) {
  24      if (!$revision->getID()) {
  25        return null;
  26      }
  27      return $revision->getTestPlan();
  28    }
  29  
  30    protected function writeValueToRevision(
  31      DifferentialRevision $revision,
  32      $value) {
  33      $revision->setTestPlan($value);
  34    }
  35  
  36    protected function isCoreFieldRequired() {
  37      return PhabricatorEnv::getEnvConfig('differential.require-test-plan-field');
  38    }
  39  
  40    public function canDisableField() {
  41      return true;
  42    }
  43  
  44    protected function getCoreFieldRequiredErrorString() {
  45      return pht(
  46        'You must provide a test plan. Describe the actions you performed '.
  47        'to verify the behavior of this change.');
  48    }
  49  
  50    public function readValueFromRequest(AphrontRequest $request) {
  51      $this->setValue($request->getStr($this->getFieldKey()));
  52    }
  53  
  54    public function renderEditControl(array $handles) {
  55      return id(new PhabricatorRemarkupControl())
  56        ->setUser($this->getViewer())
  57        ->setName($this->getFieldKey())
  58        ->setValue($this->getValue())
  59        ->setError($this->getFieldError())
  60        ->setLabel($this->getFieldName());
  61    }
  62  
  63    public function getApplicationTransactionTitle(
  64      PhabricatorApplicationTransaction $xaction) {
  65      $author_phid = $xaction->getAuthorPHID();
  66      $old = $xaction->getOldValue();
  67      $new = $xaction->getNewValue();
  68  
  69      return pht(
  70        '%s updated the test plan for this revision.',
  71        $xaction->renderHandleLink($author_phid));
  72    }
  73  
  74    public function getApplicationTransactionTitleForFeed(
  75      PhabricatorApplicationTransaction $xaction,
  76      PhabricatorFeedStory $story) {
  77  
  78      $object_phid = $xaction->getObjectPHID();
  79      $author_phid = $xaction->getAuthorPHID();
  80      $old = $xaction->getOldValue();
  81      $new = $xaction->getNewValue();
  82  
  83      return pht(
  84        '%s updated the test plan for %s.',
  85        $xaction->renderHandleLink($author_phid),
  86        $xaction->renderHandleLink($object_phid));
  87    }
  88  
  89    public function getApplicationTransactionHasChangeDetails(
  90      PhabricatorApplicationTransaction $xaction) {
  91      return true;
  92    }
  93  
  94    public function getApplicationTransactionChangeDetails(
  95      PhabricatorApplicationTransaction $xaction,
  96      PhabricatorUser $viewer) {
  97      return $xaction->renderTextCorpusChangeDetails(
  98        $viewer,
  99        $xaction->getOldValue(),
 100        $xaction->getNewValue());
 101    }
 102  
 103    public function shouldHideInApplicationTransactions(
 104      PhabricatorApplicationTransaction $xaction) {
 105      return ($xaction->getOldValue() === null);
 106    }
 107  
 108    public function shouldAppearInGlobalSearch() {
 109      return true;
 110    }
 111  
 112    public function updateAbstractDocument(
 113      PhabricatorSearchAbstractDocument $document) {
 114      if (strlen($this->getValue())) {
 115        $document->addField('plan', $this->getValue());
 116      }
 117    }
 118  
 119    public function shouldAppearInPropertyView() {
 120      return true;
 121    }
 122  
 123    public function renderPropertyViewLabel() {
 124      return $this->getFieldName();
 125    }
 126  
 127    public function getStyleForPropertyView() {
 128      return 'block';
 129    }
 130  
 131    public function getIconForPropertyView() {
 132      return PHUIPropertyListView::ICON_TESTPLAN;
 133    }
 134  
 135    public function renderPropertyViewValue(array $handles) {
 136      if (!strlen($this->getValue())) {
 137        return null;
 138      }
 139  
 140      return PhabricatorMarkupEngine::renderOneObject(
 141        id(new PhabricatorMarkupOneOff())
 142          ->setPreserveLinebreaks(true)
 143          ->setContent($this->getValue()),
 144        'default',
 145        $this->getViewer());
 146    }
 147  
 148    public function getApplicationTransactionRemarkupBlocks(
 149      PhabricatorApplicationTransaction $xaction) {
 150      return array($xaction->getNewValue());
 151    }
 152  
 153    public function shouldAppearInCommitMessage() {
 154      return true;
 155    }
 156  
 157    public function shouldAppearInCommitMessageTemplate() {
 158      return true;
 159    }
 160  
 161    public function shouldOverwriteWhenCommitMessageIsEdited() {
 162      return true;
 163    }
 164  
 165    public function getCommitMessageLabels() {
 166      return array(
 167        'Test Plan',
 168        'Testplan',
 169        'Tested',
 170        'Tests',
 171      );
 172    }
 173  
 174    public function validateCommitMessageValue($value) {
 175      if (!strlen($value) && $this->isCoreFieldRequired()) {
 176        throw new DifferentialFieldValidationException(
 177          $this->getCoreFieldRequiredErrorString());
 178      }
 179    }
 180  
 181    public function shouldAppearInTransactionMail() {
 182      return true;
 183    }
 184  
 185    public function updateTransactionMailBody(
 186      PhabricatorMetaMTAMailBody $body,
 187      PhabricatorApplicationTransactionEditor $editor,
 188      array $xactions) {
 189  
 190      if (!$editor->getIsNewObject()) {
 191        return;
 192      }
 193  
 194      $test_plan = $this->getValue();
 195      if (!strlen(trim($test_plan))) {
 196        return;
 197      }
 198  
 199      $body->addTextSection(pht('TEST PLAN'), $test_plan);
 200    }
 201  
 202  
 203  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1