Chris@0: getAnnotations(); Chris@0: if (!empty($annotations['class']['requires'])) { Chris@0: $this->checkModuleRequirements($root, $annotations['class']['requires']); Chris@0: } Chris@0: if (!empty($annotations['method']['requires'])) { Chris@0: $this->checkModuleRequirements($root, $annotations['method']['requires']); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks missing module requirements. Chris@0: * Chris@0: * Iterates through a list of requires annotations and looks for missing Chris@0: * modules. The test will be skipped if any of the required modules is Chris@0: * missing. Chris@0: * Chris@0: * @param string $root Chris@0: * The path to the root of the Drupal installation to scan. Chris@0: * @param string[] $annotations Chris@0: * A list of requires annotations from either a method or class annotation. Chris@0: * Chris@0: * @throws \PHPUnit_Framework_SkippedTestError Chris@0: * Thrown when the requirements are not met, and this test should be Chris@0: * skipped. Callers should not catch this exception. Chris@0: */ Chris@0: private function checkModuleRequirements($root, array $annotations) { Chris@0: // drupal_valid_ua() might not be loaded. Chris@0: require_once $root . '/core/includes/bootstrap.inc'; Chris@0: Chris@0: // Make a list of required modules. Chris@0: $required_modules = []; Chris@0: foreach ($annotations as $requirement) { Chris@0: if (strpos($requirement, 'module ') === 0) { Chris@0: $required_modules[] = trim(str_replace('module ', '', $requirement)); Chris@0: } Chris@0: } Chris@0: Chris@0: // If there are required modules, check if they're available. Chris@0: if (!empty($required_modules)) { Chris@0: // Scan for modules. Chris@0: $discovery = new ExtensionDiscovery($root, FALSE); Chris@0: $discovery->setProfileDirectories([]); Chris@0: $list = array_keys($discovery->scan('module')); Chris@0: $not_available = array_diff($required_modules, $list); Chris@0: if (!empty($not_available)) { Chris@0: throw new \PHPUnit_Framework_SkippedTestError('Required modules: ' . implode(', ', $not_available)); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }