mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 02:42:40 +01:00
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
This commit is contained in:
parent
541b4c86b4
commit
76523eec67
4 changed files with 155 additions and 2 deletions
|
@ -2577,6 +2577,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSpacesNamespaceSearchEngine' => 'applications/spaces/query/PhabricatorSpacesNamespaceSearchEngine.php',
|
'PhabricatorSpacesNamespaceSearchEngine' => 'applications/spaces/query/PhabricatorSpacesNamespaceSearchEngine.php',
|
||||||
'PhabricatorSpacesNamespaceTransaction' => 'applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php',
|
'PhabricatorSpacesNamespaceTransaction' => 'applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php',
|
||||||
'PhabricatorSpacesNamespaceTransactionQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceTransactionQuery.php',
|
'PhabricatorSpacesNamespaceTransactionQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceTransactionQuery.php',
|
||||||
|
'PhabricatorSpacesTestCase' => 'applications/spaces/__tests__/PhabricatorSpacesTestCase.php',
|
||||||
'PhabricatorSpacesViewController' => 'applications/spaces/controller/PhabricatorSpacesViewController.php',
|
'PhabricatorSpacesViewController' => 'applications/spaces/controller/PhabricatorSpacesViewController.php',
|
||||||
'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php',
|
'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php',
|
||||||
'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php',
|
'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php',
|
||||||
|
@ -6057,6 +6058,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSpacesDAO',
|
'PhabricatorSpacesDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
'PhabricatorApplicationTransactionInterface',
|
'PhabricatorApplicationTransactionInterface',
|
||||||
|
'PhabricatorDestructibleInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorSpacesNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorSpacesNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorSpacesNamespacePHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorSpacesNamespacePHIDType' => 'PhabricatorPHIDType',
|
||||||
|
@ -6064,6 +6066,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSpacesNamespaceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorSpacesNamespaceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorSpacesNamespaceTransaction' => 'PhabricatorApplicationTransaction',
|
'PhabricatorSpacesNamespaceTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PhabricatorSpacesNamespaceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PhabricatorSpacesNamespaceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
'PhabricatorSpacesTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorSpacesViewController' => 'PhabricatorSpacesController',
|
'PhabricatorSpacesViewController' => 'PhabricatorSpacesController',
|
||||||
'PhabricatorStandardCustomField' => 'PhabricatorCustomField',
|
'PhabricatorStandardCustomField' => 'PhabricatorCustomField',
|
||||||
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
|
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
|
||||||
|
|
135
src/applications/spaces/__tests__/PhabricatorSpacesTestCase.php
Normal file
135
src/applications/spaces/__tests__/PhabricatorSpacesTestCase.php
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorSpacesTestCase extends PhabricatorTestCase {
|
||||||
|
|
||||||
|
protected function getPhabricatorTestCaseConfiguration() {
|
||||||
|
return array(
|
||||||
|
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSpacesAnnihilation() {
|
||||||
|
$this->destroyAllSpaces();
|
||||||
|
|
||||||
|
// Test that our helper methods work correctly.
|
||||||
|
|
||||||
|
$actor = $this->generateNewTestUser();
|
||||||
|
$this->newSpace($actor, pht('Test Space'), true);
|
||||||
|
$this->assertEqual(1, count($this->loadAllSpaces()));
|
||||||
|
$this->destroyAllSpaces();
|
||||||
|
$this->assertEqual(0, count($this->loadAllSpaces()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSpacesSeveralSpaces() {
|
||||||
|
$this->destroyAllSpaces();
|
||||||
|
|
||||||
|
// Try creating a few spaces, one of which is a default space. This should
|
||||||
|
// work fine.
|
||||||
|
|
||||||
|
$actor = $this->generateNewTestUser();
|
||||||
|
$this->newSpace($actor, pht('Default Space'), true);
|
||||||
|
$this->newSpace($actor, pht('Alternate Space'), false);
|
||||||
|
$this->assertEqual(2, count($this->loadAllSpaces()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSpacesRequireNames() {
|
||||||
|
$this->destroyAllSpaces();
|
||||||
|
|
||||||
|
// Spaces must have nonempty names.
|
||||||
|
|
||||||
|
$actor = $this->generateNewTestUser();
|
||||||
|
|
||||||
|
$caught = null;
|
||||||
|
try {
|
||||||
|
$options = array(
|
||||||
|
'continueOnNoEffect' => true,
|
||||||
|
);
|
||||||
|
$this->newSpace($actor, '', true, $options);
|
||||||
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||||
|
$caught = $ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue(($caught instanceof Exception));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSpacesUniqueDefaultSpace() {
|
||||||
|
$this->destroyAllSpaces();
|
||||||
|
|
||||||
|
// It shouldn't be possible to create two default spaces.
|
||||||
|
|
||||||
|
$actor = $this->generateNewTestUser();
|
||||||
|
$this->newSpace($actor, pht('Default Space'), true);
|
||||||
|
|
||||||
|
$caught = null;
|
||||||
|
try {
|
||||||
|
$this->newSpace($actor, pht('Default Space #2'), true);
|
||||||
|
} catch (AphrontDuplicateKeyQueryException $ex) {
|
||||||
|
$caught = $ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue(($caught instanceof Exception));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadAllSpaces() {
|
||||||
|
return id(new PhabricatorSpacesNamespaceQuery())
|
||||||
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function destroyAllSpaces() {
|
||||||
|
$spaces = $this->loadAllSpaces();
|
||||||
|
foreach ($spaces as $space) {
|
||||||
|
$engine = new PhabricatorDestructionEngine();
|
||||||
|
$engine->destroyObject($space);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function newSpace(
|
||||||
|
PhabricatorUser $actor,
|
||||||
|
$name,
|
||||||
|
$is_default,
|
||||||
|
array $options = array()) {
|
||||||
|
|
||||||
|
$space = PhabricatorSpacesNamespace::initializeNewNamespace($actor);
|
||||||
|
|
||||||
|
$type_name = PhabricatorSpacesNamespaceTransaction::TYPE_NAME;
|
||||||
|
$type_default = PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT;
|
||||||
|
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||||
|
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
|
|
||||||
|
$xactions = array();
|
||||||
|
|
||||||
|
$xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
|
||||||
|
->setTransactionType($type_name)
|
||||||
|
->setNewValue($name);
|
||||||
|
|
||||||
|
$xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
|
||||||
|
->setTransactionType($type_view)
|
||||||
|
->setNewValue($actor->getPHID());
|
||||||
|
|
||||||
|
$xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
|
||||||
|
->setTransactionType($type_edit)
|
||||||
|
->setNewValue($actor->getPHID());
|
||||||
|
|
||||||
|
if ($is_default) {
|
||||||
|
$xactions[] = id(new PhabricatorSpacesNamespaceTransaction())
|
||||||
|
->setTransactionType($type_default)
|
||||||
|
->setNewValue($is_default);
|
||||||
|
}
|
||||||
|
|
||||||
|
$content_source = PhabricatorContentSource::newConsoleSource();
|
||||||
|
|
||||||
|
$editor = id(new PhabricatorSpacesNamespaceEditor())
|
||||||
|
->setActor($actor)
|
||||||
|
->setContentSource($content_source);
|
||||||
|
|
||||||
|
if (isset($options['continueOnNoEffect'])) {
|
||||||
|
$editor->setContinueOnNoEffect(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor->applyTransactions($space, $xactions);
|
||||||
|
|
||||||
|
return $space;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,7 +4,8 @@ final class PhabricatorSpacesNamespace
|
||||||
extends PhabricatorSpacesDAO
|
extends PhabricatorSpacesDAO
|
||||||
implements
|
implements
|
||||||
PhabricatorPolicyInterface,
|
PhabricatorPolicyInterface,
|
||||||
PhabricatorApplicationTransactionInterface {
|
PhabricatorApplicationTransactionInterface,
|
||||||
|
PhabricatorDestructibleInterface {
|
||||||
|
|
||||||
protected $namespaceName;
|
protected $namespaceName;
|
||||||
protected $viewPolicy;
|
protected $viewPolicy;
|
||||||
|
@ -103,4 +104,13 @@ final class PhabricatorSpacesNamespace
|
||||||
return $timeline;
|
return $timeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function destroyObjectPermanently(
|
||||||
|
PhabricatorDestructionEngine $engine) {
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,7 +764,12 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
|
|
||||||
$xactions = $this->didApplyInternalEffects($object, $xactions);
|
$xactions = $this->didApplyInternalEffects($object, $xactions);
|
||||||
|
|
||||||
|
try {
|
||||||
$object->save();
|
$object->save();
|
||||||
|
} catch (AphrontDuplicateKeyQueryException $ex) {
|
||||||
|
$object->killTransaction();
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
$xaction->setObjectPHID($object->getPHID());
|
$xaction->setObjectPHID($object->getPHID());
|
||||||
|
|
Loading…
Reference in a new issue