diff --git a/core/includes/install.inc b/core/includes/install.inc index 11e4e5fa88a62f884815c98bcb8bc65d551870b6..03dea88c331f91f334db8e972a30da51b43a9899 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 0000000000000000000000000000000000000000..a0e3e4f01d7562453763643174703730ab84310d --- /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 0000000000000000000000000000000000000000..f7935c145c88b51440e491c27a6d5a3929cdaa66 --- /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 0000000000000000000000000000000000000000..56e7e245370bf6c208b74aa187f8e5c1f090f995 --- /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.'); + } + +}