From 04a706f63dd606f658f10c435db731f0dc42f159 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 19 Oct 2018 22:51:28 +0100 Subject: [PATCH] Issue #2309731 by bendeguz.csirmaz, phenaproxima, alexpott: drupal_check_profile() does not invoke the profile's hook_requirements() --- core/includes/install.inc | 6 +++ .../testing_requirements.info.yml | 6 +++ .../testing_requirements.install | 23 +++++++++++ .../InstallerProfileRequirementsTest.php | 38 +++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 core/profiles/testing_requirements/testing_requirements.info.yml create mode 100644 core/profiles/testing_requirements/testing_requirements.install create mode 100644 core/tests/Drupal/FunctionalTests/Installer/InstallerProfileRequirementsTest.php diff --git a/core/includes/install.inc b/core/includes/install.inc index 11e4e5fa88a6..03dea88c331f 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -991,6 +991,12 @@ function drupal_check_profile($profile) { } } + // Add the profile requirements. + $function = $profile . '_requirements'; + if (function_exists($function)) { + $requirements = array_merge($requirements, $function('install')); + } + return $requirements; } diff --git a/core/profiles/testing_requirements/testing_requirements.info.yml b/core/profiles/testing_requirements/testing_requirements.info.yml new file mode 100644 index 000000000000..a0e3e4f01d75 --- /dev/null +++ b/core/profiles/testing_requirements/testing_requirements.info.yml @@ -0,0 +1,6 @@ +name: 'Testing requirements' +type: profile +description: 'Profile for testing hook_requirements().' +version: VERSION +core: 8.x +hidden: true diff --git a/core/profiles/testing_requirements/testing_requirements.install b/core/profiles/testing_requirements/testing_requirements.install new file mode 100644 index 000000000000..f7935c145c88 --- /dev/null +++ b/core/profiles/testing_requirements/testing_requirements.install @@ -0,0 +1,23 @@ +<?php + +/** + * @file + * Install hooks for test profile. + */ + +/** + * Implements hook_requirements(). + */ +function testing_requirements_requirements($phase) { + $requirements = []; + + if ($phase === 'install') { + $requirements['testing_requirements'] = [ + 'title' => t('Testing requirements'), + 'severity' => REQUIREMENT_ERROR, + 'description' => t('Testing requirements failed requirements.'), + ]; + } + + return $requirements; +} diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerProfileRequirementsTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerProfileRequirementsTest.php new file mode 100644 index 000000000000..56e7e245370b --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerProfileRequirementsTest.php @@ -0,0 +1,38 @@ +<?php + +namespace Drupal\FunctionalTests\Installer; + +/** + * Tests that an install profile can implement hook_requirements(). + * + * @group Installer + */ +class InstallerProfileRequirementsTest extends InstallerTestBase { + + /** + * {@inheritdoc} + */ + protected $profile = 'testing_requirements'; + + /** + * {@inheritdoc} + */ + protected function setUpSettings() { + // This form will never be reached. + } + + /** + * {@inheritdoc} + */ + protected function setUpSite() { + // This form will never be reached. + } + + /** + * Assert that the profile failed hook_requirements(). + */ + public function testHookRequirementsFailure() { + $this->assertSession()->pageTextContains('Testing requirements failed requirements.'); + } + +} -- GitLab