Skip to content
Snippets Groups Projects
Commit b2679cc1 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3271078 by phenaproxima, tedbow: Tests make requests to...

Issue #3271078 by phenaproxima, tedbow: Tests make requests to updates.drupal.org instead of test fixtures sometimes
parent 15b871ae
No related branches found
No related tags found
No related merge requests found
Showing with 82 additions and 51 deletions
......@@ -54,7 +54,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
*/
protected function setProjectInstalledVersion($version) {
$this->config('update.settings')
->set('fetch.url', $this->baseUrl . '/automatic-update-test')
->set('fetch.url', $this->baseUrl . '/test-release-history')
->save();
$system_info = [
$this->updateProject => [
......
automatic_updates_test.metadata:
path: '/automatic-update-test/{project_name}/{version}'
defaults:
_title: 'Update test'
_controller: '\Drupal\automatic_updates_test\TestController::metadata'
requirements:
_access: 'TRUE'
options:
_maintenance_access: TRUE
automatic_updates_test.update:
path: '/automatic-update-test/update/{to_version}'
defaults:
......
......@@ -6,7 +6,6 @@ use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\Component\Utility\Environment;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\HtmlResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
class TestController extends ControllerBase {
......@@ -62,38 +61,4 @@ class TestController extends ControllerBase {
return new HtmlResponse($content, $status);
}
/**
* Page callback: Prints mock XML for the Update Manager module.
*
* This is a wholesale copy of
* \Drupal\update_test\Controller\UpdateTestController::updateTest() for
* testing automatic updates. This was done in order to use a different
* directory of mock XML files.
*/
public function metadata($project_name = 'drupal', $version = NULL): Response {
$xml_map = $this->config('update_test.settings')->get('xml_map');
if (isset($xml_map[$project_name])) {
$availability_scenario = $xml_map[$project_name];
}
elseif (isset($xml_map['#all'])) {
$availability_scenario = $xml_map['#all'];
}
else {
// The test didn't specify (for example, the webroot has other modules and
// themes installed but they're disabled by the version of the site
// running the test. So, we default to a file we know won't exist, so at
// least we'll get an empty xml response instead of a bunch of Drupal page
// output.
$availability_scenario = '#broken#';
}
$file = __DIR__ . "/../../../fixtures/release-history/$project_name.$availability_scenario.xml";
$headers = ['Content-Type' => 'text/xml; charset=utf-8'];
if (!is_file($file)) {
// Return an empty response.
return new Response('', 200, $headers);
}
return new BinaryFileResponse($file, 200, $headers);
}
}
name: 'Automatic Updates Test - Release history'
type: module
description: 'Provides a mechanism for serving fake release history metadata in functional tests.'
package: Testing
dependencies:
- drupal:update
- drupal:update_test
automatic_updates_test_release_history.metadata:
path: '/test-release-history/{project_name}/{version}'
defaults:
_title: 'Update test'
_controller: '\Drupal\automatic_updates_test_release_history\TestController::metadata'
requirements:
_access: 'TRUE'
options:
_maintenance_access: TRUE
<?php
namespace Drupal\automatic_updates_test_release_history;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
class TestController extends ControllerBase {
/**
* Page callback: Prints mock XML for the Update Manager module.
*
* This is a wholesale copy of
* \Drupal\update_test\Controller\UpdateTestController::updateTest() for
* testing automatic updates. This was done in order to use a different
* directory of mock XML files.
*/
public function metadata($project_name = 'drupal', $version = NULL): Response {
$xml_map = $this->config('update_test.settings')->get('xml_map');
if (isset($xml_map[$project_name])) {
$availability_scenario = $xml_map[$project_name];
}
elseif (isset($xml_map['#all'])) {
$availability_scenario = $xml_map['#all'];
}
else {
// The test didn't specify (for example, the webroot has other modules and
// themes installed but they're disabled by the version of the site
// running the test. So, we default to a file we know won't exist, so at
// least we'll get an empty xml response instead of a bunch of Drupal page
// output.
$availability_scenario = '#broken#';
}
$file = __DIR__ . "/../../../fixtures/release-history/$project_name.$availability_scenario.xml";
$headers = ['Content-Type' => 'text/xml; charset=utf-8'];
if (!is_file($file)) {
// Return an empty response.
return new Response('', 200, $headers);
}
return new BinaryFileResponse($file, 200, $headers);
}
}
......@@ -39,7 +39,7 @@ abstract class UpdateTestBase extends TemplateProjectTestBase {
$this->installModules([
'automatic_updates',
'automatic_updates_test',
'update_test',
'automatic_updates_test_release_history',
]);
}
......@@ -65,7 +65,7 @@ END;
$port = $this->findAvailablePort();
$this->metadataServer = $this->instantiateServer($port);
$code .= <<<END
\$config['update.settings']['fetch']['url'] = 'http://localhost:$port/automatic-update-test';
\$config['update.settings']['fetch']['url'] = 'http://localhost:$port/test-release-history';
END;
}
$this->writeSettings($code);
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\Core\Site\Settings;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base class for functional tests of the Automatic Updates module.
......@@ -16,8 +17,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
protected static $modules = [
'automatic_updates_test_disable_validators',
'package_manager_bypass',
'update',
'update_test',
];
/**
......@@ -54,6 +53,22 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
$this->disableValidators($this->disableValidators);
}
/**
* {@inheritdoc}
*/
protected function installModulesFromClassProperty(ContainerInterface $container) {
$container->get('module_installer')->install([
'automatic_updates_test_release_history',
]);
$this->container = $container->get('kernel')->getContainer();
// To prevent tests from making real requests to the Internet, use fake
// release metadata that exposes a pretend Drupal 9.8.2 release.
$this->setReleaseMetadata(__DIR__ . '/../../fixtures/release-history/drupal.9.8.2.xml');
parent::installModulesFromClassProperty($container);
}
/**
* {@inheritdoc}
*/
......@@ -117,7 +132,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
*/
protected function setReleaseMetadata(string $file): void {
$this->config('update.settings')
->set('fetch.url', $this->baseUrl . '/automatic-update-test')
->set('fetch.url', $this->baseUrl . '/test-release-history')
->save();
[$project, $fixture] = explode('.', basename($file, '.xml'), 2);
......
......@@ -31,7 +31,6 @@ class UpdateLockTest extends AutomaticUpdatesFunctionalTestBase {
protected function setUp(): void {
parent::setUp();
$this->setReleaseMetadata(__DIR__ . '/../../fixtures/release-history/drupal.9.8.2.xml');
$this->drupalLogin($this->rootUser);
$this->checkForUpdates();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment