@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement DestructibleInterface on Spaces, add some basic tests

Summary: Ref T8377. Mostly just a framework for test coverage.

Test Plan: Tests pass.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8377

Differential Revision: https://secure.phabricator.com/D13102

+155 -2
+3
src/__phutil_library_map__.php
··· 2577 2577 'PhabricatorSpacesNamespaceSearchEngine' => 'applications/spaces/query/PhabricatorSpacesNamespaceSearchEngine.php', 2578 2578 'PhabricatorSpacesNamespaceTransaction' => 'applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php', 2579 2579 'PhabricatorSpacesNamespaceTransactionQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceTransactionQuery.php', 2580 + 'PhabricatorSpacesTestCase' => 'applications/spaces/__tests__/PhabricatorSpacesTestCase.php', 2580 2581 'PhabricatorSpacesViewController' => 'applications/spaces/controller/PhabricatorSpacesViewController.php', 2581 2582 'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php', 2582 2583 'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php', ··· 6057 6058 'PhabricatorSpacesDAO', 6058 6059 'PhabricatorPolicyInterface', 6059 6060 'PhabricatorApplicationTransactionInterface', 6061 + 'PhabricatorDestructibleInterface', 6060 6062 ), 6061 6063 'PhabricatorSpacesNamespaceEditor' => 'PhabricatorApplicationTransactionEditor', 6062 6064 'PhabricatorSpacesNamespacePHIDType' => 'PhabricatorPHIDType', ··· 6064 6066 'PhabricatorSpacesNamespaceSearchEngine' => 'PhabricatorApplicationSearchEngine', 6065 6067 'PhabricatorSpacesNamespaceTransaction' => 'PhabricatorApplicationTransaction', 6066 6068 'PhabricatorSpacesNamespaceTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6069 + 'PhabricatorSpacesTestCase' => 'PhabricatorTestCase', 6067 6070 'PhabricatorSpacesViewController' => 'PhabricatorSpacesController', 6068 6071 'PhabricatorStandardCustomField' => 'PhabricatorCustomField', 6069 6072 'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
+135
src/applications/spaces/__tests__/PhabricatorSpacesTestCase.php
··· 1 + <?php 2 + 3 + final class PhabricatorSpacesTestCase extends PhabricatorTestCase { 4 + 5 + protected function getPhabricatorTestCaseConfiguration() { 6 + return array( 7 + self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true, 8 + ); 9 + } 10 + 11 + public function testSpacesAnnihilation() { 12 + $this->destroyAllSpaces(); 13 + 14 + // Test that our helper methods work correctly. 15 + 16 + $actor = $this->generateNewTestUser(); 17 + $this->newSpace($actor, pht('Test Space'), true); 18 + $this->assertEqual(1, count($this->loadAllSpaces())); 19 + $this->destroyAllSpaces(); 20 + $this->assertEqual(0, count($this->loadAllSpaces())); 21 + } 22 + 23 + public function testSpacesSeveralSpaces() { 24 + $this->destroyAllSpaces(); 25 + 26 + // Try creating a few spaces, one of which is a default space. This should 27 + // work fine. 28 + 29 + $actor = $this->generateNewTestUser(); 30 + $this->newSpace($actor, pht('Default Space'), true); 31 + $this->newSpace($actor, pht('Alternate Space'), false); 32 + $this->assertEqual(2, count($this->loadAllSpaces())); 33 + } 34 + 35 + public function testSpacesRequireNames() { 36 + $this->destroyAllSpaces(); 37 + 38 + // Spaces must have nonempty names. 39 + 40 + $actor = $this->generateNewTestUser(); 41 + 42 + $caught = null; 43 + try { 44 + $options = array( 45 + 'continueOnNoEffect' => true, 46 + ); 47 + $this->newSpace($actor, '', true, $options); 48 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 49 + $caught = $ex; 50 + } 51 + 52 + $this->assertTrue(($caught instanceof Exception)); 53 + } 54 + 55 + public function testSpacesUniqueDefaultSpace() { 56 + $this->destroyAllSpaces(); 57 + 58 + // It shouldn't be possible to create two default spaces. 59 + 60 + $actor = $this->generateNewTestUser(); 61 + $this->newSpace($actor, pht('Default Space'), true); 62 + 63 + $caught = null; 64 + try { 65 + $this->newSpace($actor, pht('Default Space #2'), true); 66 + } catch (AphrontDuplicateKeyQueryException $ex) { 67 + $caught = $ex; 68 + } 69 + 70 + $this->assertTrue(($caught instanceof Exception)); 71 + } 72 + 73 + private function loadAllSpaces() { 74 + return id(new PhabricatorSpacesNamespaceQuery()) 75 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 76 + ->execute(); 77 + } 78 + 79 + private function destroyAllSpaces() { 80 + $spaces = $this->loadAllSpaces(); 81 + foreach ($spaces as $space) { 82 + $engine = new PhabricatorDestructionEngine(); 83 + $engine->destroyObject($space); 84 + } 85 + } 86 + 87 + private function newSpace( 88 + PhabricatorUser $actor, 89 + $name, 90 + $is_default, 91 + array $options = array()) { 92 + 93 + $space = PhabricatorSpacesNamespace::initializeNewNamespace($actor); 94 + 95 + $type_name = PhabricatorSpacesNamespaceTransaction::TYPE_NAME; 96 + $type_default = PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT; 97 + $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; 98 + $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 99 + 100 + $xactions = array(); 101 + 102 + $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 103 + ->setTransactionType($type_name) 104 + ->setNewValue($name); 105 + 106 + $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 107 + ->setTransactionType($type_view) 108 + ->setNewValue($actor->getPHID()); 109 + 110 + $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 111 + ->setTransactionType($type_edit) 112 + ->setNewValue($actor->getPHID()); 113 + 114 + if ($is_default) { 115 + $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) 116 + ->setTransactionType($type_default) 117 + ->setNewValue($is_default); 118 + } 119 + 120 + $content_source = PhabricatorContentSource::newConsoleSource(); 121 + 122 + $editor = id(new PhabricatorSpacesNamespaceEditor()) 123 + ->setActor($actor) 124 + ->setContentSource($content_source); 125 + 126 + if (isset($options['continueOnNoEffect'])) { 127 + $editor->setContinueOnNoEffect(true); 128 + } 129 + 130 + $editor->applyTransactions($space, $xactions); 131 + 132 + return $space; 133 + } 134 + 135 + }
+11 -1
src/applications/spaces/storage/PhabricatorSpacesNamespace.php
··· 4 4 extends PhabricatorSpacesDAO 5 5 implements 6 6 PhabricatorPolicyInterface, 7 - PhabricatorApplicationTransactionInterface { 7 + PhabricatorApplicationTransactionInterface, 8 + PhabricatorDestructibleInterface { 8 9 9 10 protected $namespaceName; 10 11 protected $viewPolicy; ··· 101 102 PhabricatorApplicationTransactionView $timeline, 102 103 AphrontRequest $request) { 103 104 return $timeline; 105 + } 106 + 107 + 108 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 109 + 110 + 111 + public function destroyObjectPermanently( 112 + PhabricatorDestructionEngine $engine) { 113 + $this->delete(); 104 114 } 105 115 106 116 }
+6 -1
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 764 764 765 765 $xactions = $this->didApplyInternalEffects($object, $xactions); 766 766 767 - $object->save(); 767 + try { 768 + $object->save(); 769 + } catch (AphrontDuplicateKeyQueryException $ex) { 770 + $object->killTransaction(); 771 + throw $ex; 772 + } 768 773 769 774 foreach ($xactions as $xaction) { 770 775 $xaction->setObjectPHID($object->getPHID());