determineBackends(); // load crucial required modules in addition to requested ones. $arg_modules = func_get_args(); $modules = array_merge(array('autoload', 'dbtng', 'ctools', 'views', 'versioncontrol'), $arg_modules, $magic_modules); call_user_func_array(array('VersioncontrolTestCase', 'parent::setUp'), $modules); if (!($this->useBackends & (self::BACKENDS_NONE))) { // If the test requested it, init and attach backends. $this->attachBackends(); } } protected function tearDown() { // For dbtng the prefix is part of the data associated with the // connection, so, when simpletest makes a new prefix to run another // test method, dbtng do not notice it is a _new_ connection, so // removing by hand force it to open a new one with the right changed // prefix. Database::removeConnection('default'); parent::tearDown(); } /** * Set up the testing environment with the appropriate set of backends for the * current test run. * * Due to VCAPI's special relationship with its backends, it can be * advantageous to have VCAPI-owned tests that operate directly on code in * the backends. Such tests need to enable backend modules as appropriate, but * must draw from the list of installed modules, not merely enabled modules, * and therefore cannot rely on hook invocations responses for discovery. So * we have to swim upstream a bit, relying on a custom addition to module * .info files for discovery. * * This method is called only once during setUp(), and does two essential */ private function determineBackends() { if ($this->useBackends & (self::BACKENDS_NONE | self::BACKENDS_DEFAULT)) { // Test requests that we do no magic loading, bail out early. return array(); } $modules = array(); if ($this->useBackends & self::BACKENDS_TEST) { // Test requests the testing backend to be made available. $modules[] = 'versioncontrol_test'; } if ($this->useBackends & (self::BACKENDS_ENABLED | self::BACKENDS_DISABLED)) { // Test requests magic loading of installed backend modules. Query the // system table for a module list, then figure out which ones to add. $result = db_query("SELECT name, status, info FROM {system} WHERE type = 'module'"); $files = array(); while ($module = db_fetch_object($result)) { $module->info = unserialize($module->info); if (!isset($module->info['vcapi-backend'])) { // sloppy check b/c we can't enforce anything effectively // not a vcapi backend module, so skip it. continue; } if (($module->status == TRUE && ($this->useBackends & self::BACKENDS_ENABLED)) || ($modules->status == FALSE && ($this->useBackends & self::BACKENDS_DISABLED))) { $modules[] = $module->name; } } } return $modules; } private function attachBackends() { // Clear the backend static cache and retrieve all backends. $this->backends = versioncontrol_get_backends('', TRUE); // If the test backend was requested, also store it in a special property. if ($this->useBackends & self::BACKENDS_TEST) { $this->testBackend = versioncontrol_get_backends('test'); } } /** * Create a dummy backend, insert it in the database, and return it for use. * * This uses a fake path that doesn't point to any real repository, so * anything that actually tries to interact with the underlying repo will * fail. * * @param string $backend_name * @param array $data */ public function versioncontrolCreateRepository($backend_name = 'test', $data = array()) { static $i = 0; $default_data = array( 'name' => 'test_repo_' . ++$i, 'vcs' => $backend_name, 'root' => '/fake/path/to/repo', 'update_method' => 0, 'updated' => 0, 'locked' => 0, 'data' => array(), 'plugins' => array(), ); $default_plugins = array( 'auth_handler' => 'ffa', ); $data = array_merge_recursive($default_data, $data); foreach ($default_plugins as $plugin_slot => $default_plugin) { if (empty($data['plugins'][$plugin_slot])) { $data['plugins'][$plugin_slot] = $default_plugin; } } $backend = $this->backends[$backend_name]; $repo = $backend->buildEntity('repo', $data); $repo->insert(); return $repo; } public function versioncontrolCreateLabel($type, $backend_name = 'test', $data = array()) { $default_data = array( 'name' => $this->randomName(32), ); $data += $default_data; $backend = $this->backends[$backend_name]; if (!isset($data['repo_id'])) { $repo = $this->versioncontrolCreateRepository($backend_name); $data['repo_id'] = $repo->repo_id; } $label = $backend->buildEntity($type, $data); $label->insert(); return $label; } public function versioncontrolCreateBranch($backend_name = 'test', $data = array()) { return $this->versioncontrolCreateLabel('branch', $backend_name, $data); } public function versioncontrolCreateTag($backend_name = 'test', $data = array()) { return $this->versioncontrolCreateLabel('tag', $backend_name, $data); } }