Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/base/PhabricatorApplication.php b/src/applications/base/PhabricatorApplication.php
index f8e1ff8408..6dbcb37662 100644
--- a/src/applications/base/PhabricatorApplication.php
+++ b/src/applications/base/PhabricatorApplication.php
@@ -1,301 +1,294 @@
<?php
/**
* @task info Application Information
* @task ui UI Integration
* @task uri URI Routing
* @task fact Fact Integration
* @task meta Application Management
* @group apps
*/
abstract class PhabricatorApplication {
const GROUP_CORE = 'core';
const GROUP_COMMUNICATION = 'communication';
const GROUP_ORGANIZATION = 'organization';
const GROUP_UTILITIES = 'util';
const GROUP_ADMIN = 'admin';
const GROUP_DEVELOPER = 'developer';
const GROUP_MISC = 'misc';
const TILE_INVISIBLE = 'invisible';
const TILE_HIDE = 'hide';
const TILE_SHOW = 'show';
const TILE_FULL = 'full';
public static function getApplicationGroups() {
return array(
self::GROUP_CORE => pht('Core Applications'),
self::GROUP_COMMUNICATION => pht('Communication'),
self::GROUP_ORGANIZATION => pht('Organization'),
self::GROUP_UTILITIES => pht('Utilities'),
self::GROUP_ADMIN => pht('Administration'),
self::GROUP_DEVELOPER => pht('Developer Tools'),
self::GROUP_MISC => pht('Miscellaneous Applications'),
);
}
public static function getTileDisplayName($constant) {
$names = array(
self::TILE_INVISIBLE => pht('Invisible'),
self::TILE_HIDE => pht('Hidden'),
self::TILE_SHOW => pht('Show Small Tile'),
self::TILE_FULL => pht('Show Large Tile'),
);
return idx($names, $constant);
}
/* -( Application Information )-------------------------------------------- */
public function getName() {
return substr(get_class($this), strlen('PhabricatorApplication'));
}
public function getShortDescription() {
return $this->getName().' Application';
}
public function isInstalled() {
if (!$this->canUninstall()) {
return true;
}
$beta = PhabricatorEnv::getEnvConfig('phabricator.show-beta-applications');
if (!$beta && $this->isBeta()) {
return false;
}
$uninstalled = PhabricatorEnv::getEnvConfig(
'phabricator.uninstalled-applications');
return empty($uninstalled[get_class($this)]);
}
public static function isClassInstalled($class) {
return self::getByClass($class)->isInstalled();
}
public function isBeta() {
return false;
}
public function canUninstall() {
return true;
}
public function getPHID() {
return 'PHID-APPS-'.get_class($this);
}
public function getTypeaheadURI() {
return $this->getBaseURI();
}
public function getBaseURI() {
return null;
}
public function getIconURI() {
return null;
}
public function getIconName() {
return 'application';
}
public function shouldAppearInLaunchView() {
return true;
}
public function getApplicationOrder() {
return PHP_INT_MAX;
}
public function getApplicationGroup() {
return self::GROUP_MISC;
}
public function getTitleGlyph() {
return null;
}
public function getHelpURI() {
// TODO: When these applications get created, link to their docs:
//
// - Drydock
// - OAuth Server
return null;
}
public function getEventListeners() {
return array();
}
public function getDefaultTileDisplay(PhabricatorUser $user) {
switch ($this->getApplicationGroup()) {
case self::GROUP_CORE:
return self::TILE_FULL;
case self::GROUP_UTILITIES:
case self::GROUP_DEVELOPER:
return self::TILE_HIDE;
case self::GROUP_ADMIN:
if ($user->getIsAdmin()) {
return self::TILE_SHOW;
} else {
return self::TILE_INVISIBLE;
}
break;
default:
return self::TILE_SHOW;
}
}
public function getRemarkupRules() {
return array();
}
/* -( URI Routing )-------------------------------------------------------- */
public function getRoutes() {
return array();
}
/* -( Fact Integration )--------------------------------------------------- */
public function getFactObjectsForAnalysis() {
return array();
}
/* -( UI Integration )----------------------------------------------------- */
/**
* Render status elements (like "3 Waiting Reviews") for application list
* views. These provide a way to alert users to new or pending action items
* in applications.
*
* @param PhabricatorUser Viewing user.
* @return list<PhabricatorApplicationStatusView> Application status elements.
* @task ui
*/
public function loadStatus(PhabricatorUser $user) {
return array();
}
/**
* You can provide an optional piece of flavor text for the application. This
* is currently rendered in application launch views if the application has no
* status elements.
*
* @return string|null Flavor text.
* @task ui
*/
public function getFlavorText() {
return null;
}
/**
* Build items for the main menu.
*
* @param PhabricatorUser The viewing user.
* @param AphrontController The current controller. May be null for special
* pages like 404, exception handlers, etc.
* @return list<PhabricatorMainMenuIconView> List of menu items.
* @task ui
*/
public function buildMainMenuItems(
PhabricatorUser $user,
PhabricatorController $controller = null) {
return array();
}
/**
* On the Phabricator homepage sidebar, this function returns the URL for
* a quick create X link which is displayed in the wide button only.
*
* @return string
* @task ui
*/
public function getQuickCreateURI() {
return null;
}
/* -( Application Management )--------------------------------------------- */
public static function getByClass($class_name) {
$selected = null;
$applications = PhabricatorApplication::getAllApplications();
foreach ($applications as $application) {
if (get_class($application) == $class_name) {
$selected = $application;
break;
}
}
if (!$selected) {
throw new Exception("No application '{$class_name}'!");
}
return $selected;
}
public static function getAllApplications() {
- $classes = id(new PhutilSymbolLoader())
- ->setAncestorClass(__CLASS__)
- ->setConcreteOnly(true)
- ->selectAndLoadSymbols();
+ static $applications;
- $apps = array();
+ if ($applications === null) {
+ $apps = id(new PhutilSymbolLoader())
+ ->setAncestorClass(__CLASS__)
+ ->loadObjects();
- foreach ($classes as $class) {
- $app = newv($class['name'], array());
- $apps[] = $app;
+ // Reorder the applications into "application order". Notably, this
+ // ensures their event handlers register in application order.
+ $apps = msort($apps, 'getApplicationOrder');
+ $apps = mgroup($apps, 'getApplicationGroup');
+ $apps = array_select_keys($apps, self::getApplicationGroups()) + $apps;
+ $apps = array_mergev($apps);
+
+ $applications = $apps;
}
- // Reorder the applications into "application order". Notably, this ensures
- // their event handlers register in application order.
- $apps = msort($apps, 'getApplicationOrder');
- $apps = mgroup($apps, 'getApplicationGroup');
- $apps = array_select_keys($apps, self::getApplicationGroups()) + $apps;
- $apps = array_mergev($apps);
- return $apps;
+ return $applications;
}
public static function getAllInstalledApplications() {
- static $applications;
-
- if (empty($applications)) {
- $all_applications = self::getAllApplications();
- $apps = array();
- foreach ($all_applications as $app) {
- if (!$app->isInstalled()) {
- continue;
- }
-
- $apps[] = $app;
+ $all_applications = self::getAllApplications();
+ $apps = array();
+ foreach ($all_applications as $app) {
+ if (!$app->isInstalled()) {
+ continue;
}
- $applications = $apps;
+ $apps[] = $app;
}
- return $applications;
+ return $apps;
}
}
diff --git a/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php b/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
index 60c4695798..70ba05bb4b 100644
--- a/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
+++ b/src/infrastructure/__tests__/PhabricatorInfrastructureTestCase.php
@@ -1,18 +1,27 @@
<?php
final class PhabricatorInfrastructureTestCase
extends PhabricatorTestCase {
/**
* This is more of an acceptance test case instead of a unittest. It verifies
- * that all symbols can be loaded correctly. It can catch problem like missing
- * methods in descendants of abstract base classes.
+ * that all symbols can be loaded correctly. It can catch problems like
+ * missing methods in descendants of abstract base classes.
*/
public function testEverythingImplemented() {
- // Note that we don't have a try catch block around the following because,
- // when it fails, it will cause a HPHP or PHP fatal which won't be caught
- // by try catch.
- $every_class = id(new PhutilSymbolLoader())->selectAndLoadSymbols();
+ id(new PhutilSymbolLoader())->selectAndLoadSymbols();
}
+
+ public function testApplicationsInstalled() {
+ $all = PhabricatorApplication::getAllApplications();
+ $installed = PhabricatorApplication::getAllInstalledApplications();
+
+ $this->assertEqual(
+ count($all),
+ count($installed),
+ 'In test cases, all applications should default to installed.');
+ }
+
+
}
diff --git a/src/infrastructure/testing/PhabricatorTestCase.php b/src/infrastructure/testing/PhabricatorTestCase.php
index 12f18567bc..c2c6d72f08 100644
--- a/src/infrastructure/testing/PhabricatorTestCase.php
+++ b/src/infrastructure/testing/PhabricatorTestCase.php
@@ -1,172 +1,181 @@
<?php
abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
const NAMESPACE_PREFIX = 'phabricator_unittest_';
/**
* If true, put Lisk in process-isolated mode for the duration of the tests so
* that it will establish only isolated, side-effect-free database
* connections. Defaults to true.
*
* NOTE: You should disable this only in rare circumstances. Unit tests should
* not rely on external resources like databases, and should not produce
* side effects.
*/
const PHABRICATOR_TESTCONFIG_ISOLATE_LISK = 'isolate-lisk';
/**
* If true, build storage fixtures before running tests, and connect to them
* during test execution. This will impose a performance penalty on test
* execution (currently, it takes roughly one second to build the fixture)
* but allows you to perform tests which require data to be read from storage
* after writes. The fixture is shared across all test cases in this process.
* Defaults to false.
*
* NOTE: All connections to fixture storage open transactions when established
* and roll them back when tests complete. Each test must independently
* write data it relies on; data will not persist across tests.
*
* NOTE: Enabling this implies disabling process isolation.
*/
const PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES = 'storage-fixtures';
private $configuration;
private $env;
private static $storageFixtureReferences = 0;
private static $storageFixture;
private static $storageFixtureObjectSeed = 0;
protected function getPhabricatorTestCaseConfiguration() {
return array();
}
private function getComputedConfiguration() {
$config = $this->getPhabricatorTestCaseConfiguration() + array(
self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => true,
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => false,
);
if ($config[self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES]) {
// Fixtures don't make sense with process isolation.
$config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK] = false;
}
return $config;
}
public function willRunTestCases(array $test_cases) {
$root = dirname(phutil_get_library_root('phabricator'));
require_once $root.'/scripts/__init_script__.php';
$config = $this->getComputedConfiguration();
if ($config[self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES]) {
++self::$storageFixtureReferences;
if (!self::$storageFixture) {
self::$storageFixture = $this->newStorageFixture();
}
}
}
public function didRunTestCases(array $test_cases) {
if (self::$storageFixture) {
self::$storageFixtureReferences--;
if (!self::$storageFixtureReferences) {
self::$storageFixture = null;
}
}
}
protected function willRunTests() {
$config = $this->getComputedConfiguration();
if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
LiskDAO::beginIsolateAllLiskEffectsToCurrentProcess();
}
$this->env = PhabricatorEnv::beginScopedEnv();
+
+ // NOTE: While running unit tests, we act as though all applications are
+ // installed, regardless of the install's configuration. Tests which need
+ // to uninstall applications are responsible for adjusting state themselves
+ // (such tests are exceedingly rare).
+
+ $this->env->overrideEnvConfig(
+ 'phabricator.uninstalled-applications',
+ array());
}
protected function didRunTests() {
$config = $this->getComputedConfiguration();
if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
LiskDAO::endIsolateAllLiskEffectsToCurrentProcess();
}
try {
if (phutil_is_hiphop_runtime()) {
$this->env->__destruct();
}
unset($this->env);
} catch (Exception $ex) {
throw new Exception(
"Some test called PhabricatorEnv::beginScopedEnv(), but is still ".
"holding a reference to the scoped environment!");
}
}
protected function willRunOneTest($test) {
$config = $this->getComputedConfiguration();
if ($config[self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES]) {
LiskDAO::beginIsolateAllLiskEffectsToTransactions();
}
}
protected function didRunOneTest($test) {
$config = $this->getComputedConfiguration();
if ($config[self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES]) {
LiskDAO::endIsolateAllLiskEffectsToTransactions();
}
}
protected function newStorageFixture() {
$bytes = Filesystem::readRandomCharacters(24);
$name = self::NAMESPACE_PREFIX.$bytes;
return new PhabricatorStorageFixtureScopeGuard($name);
}
protected function getLink($method) {
$phabricator_project = 'PHID-APRJ-3f1fc779edeab89b2171';
return
'https://secure.phabricator.com/diffusion/symbol/'.$method.
'/?lang=php&projects='.$phabricator_project.
'&jump=true&context='.get_class($this);
}
/**
* Returns an integer seed to use when building unique identifiers (e.g.,
* non-colliding usernames). The seed is unstable and its value will change
* between test runs, so your tests must not rely on it.
*
* @return int A unique integer.
*/
protected function getNextObjectSeed() {
self::$storageFixtureObjectSeed += mt_rand(1, 100);
return self::$storageFixtureObjectSeed;
}
protected function generateNewTestUser() {
$seed = $this->getNextObjectSeed();
$user = id(new PhabricatorUser())
->setRealName("Test User {$seed}}")
->setUserName("test{$seed}");
$email = id(new PhabricatorUserEmail())
->setAddress("testuser{$seed}@example.com")
->setIsVerified(1);
$editor = new PhabricatorUserEditor();
$editor->setActor($user);
$editor->createNewUser($user, $email);
return $user;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jul 24, 12:23 AM (11 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
182434
Default Alt Text
(16 KB)

Event Timeline