Issue #3253639 by tedbow, longwave: \Drupal\Tests\update\Functional\UpdateTestBase::setUp is not needed for most child classes and makes the test harder to understand

merge-requests/1492/merge
catch 2021-12-13 13:04:50 +00:00
parent 5e93c9c691
commit 42a48a2e2b
4 changed files with 39 additions and 25 deletions

View File

@ -7,7 +7,7 @@ namespace Drupal\Tests\update\Functional;
*
* @group update
*/
class FileTransferAuthorizeFormTest extends UpdateTestBase {
class FileTransferAuthorizeFormTest extends UpdateUploaderTestBase {
/**
* Modules to enable.

View File

@ -2,7 +2,6 @@
namespace Drupal\Tests\update\Functional;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
@ -54,28 +53,6 @@ abstract class UpdateTestBase extends BrowserTestBase {
*/
protected $updateProject;
protected function setUp() {
parent::setUp();
// Change the root path which Update Manager uses to install and update
// projects to be inside the testing site directory. See
// \Drupal\update\UpdateRootFactory::get() for equivalent changes to the
// test child site.
$request = \Drupal::request();
$update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
$this->container->get('update.root')->set($update_root);
// Create the directories within the root path within which the Update
// Manager will install projects.
foreach (drupal_get_updaters() as $updater_info) {
$updater = $updater_info['class'];
$install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
if (!is_dir($install_directory)) {
mkdir($install_directory);
}
}
}
/**
* Refreshes the update status based on the desired available update scenario.
*

View File

@ -12,7 +12,7 @@ use Drupal\Tests\TestFileCreationTrait;
*
* @group update
*/
class UpdateUploadTest extends UpdateTestBase {
class UpdateUploadTest extends UpdateUploaderTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;

View File

@ -0,0 +1,37 @@
<?php
namespace Drupal\Tests\update\Functional;
use Drupal\Core\DrupalKernel;
/**
* Base test class for tests that test project upload functionality.
*/
class UpdateUploaderTestBase extends UpdateTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Change the root path which Update Manager uses to install and update
// projects to be inside the testing site directory. See
// \Drupal\update\UpdateRootFactory::get() for equivalent changes to the
// test child site.
$request = \Drupal::request();
$update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
$this->container->get('update.root')->set($update_root);
// Create the directories within the root path within which the Update
// Manager will install projects.
foreach (drupal_get_updaters() as $updater_info) {
$updater = $updater_info['class'];
$install_directory = $update_root . '/' . $updater::getRootDirectoryRelativePath();
if (!is_dir($install_directory)) {
mkdir($install_directory);
}
}
}
}