-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDrupalBootstrap.php
More file actions
105 lines (92 loc) · 2.71 KB
/
DrupalBootstrap.php
File metadata and controls
105 lines (92 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Codeception\Module;
use Codeception\Configuration;
use Codeception\Lib\ModuleContainer;
use Codeception\Module;
use Codeception\TestDrupalKernel;
use Symfony\Component\HttpFoundation\Request;
use DrupalFinder\DrupalFinder;
use Codeception\Module\DrupalBootstrap\EventsAssertionsTrait;
/**
* Class DrupalBootstrap.
*
* ### Example
* #### Example (DrupalBootstrap)
* modules:
* - DrupalBootstrap:
* root: './web'
* site_path: 'sites/default'
* http_host: 'mysite.local'
*
* @package Codeception\Module
*/
class DrupalBootstrap extends Module {
use EventsAssertionsTrait;
/**
* Default module configuration.
*
* @var array
*/
protected $config = [
'site_path' => 'sites/default',
];
/**
* Track wether we enabled the webprofiler module or not.
*
* @var bool
*/
protected $enabledWebProfiler = FALSE;
/**
* DrupalBootstrap constructor.
*
* @param \Codeception\Lib\ModuleContainer $container
* Module container.
* @param null|array $config
* Array of configurations or null.
*
* @throws \Codeception\Exception\ModuleConfigException
* @throws \Codeception\Exception\ModuleException
*/
public function __construct(ModuleContainer $container, $config = NULL) {
parent::__construct($container, $config);
if (!isset($this->config['root'])) {
$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(getcwd());
$drupalRoot = $drupalFinder->getDrupalRoot();
// Autodetect Drupal root.
if ($drupalRoot) {
$this->_setConfig(['root' => $drupalRoot]);
}
else {
$this->_setConfig(['root' => Configuration::projectDir() . 'web']);
}
}
chdir($this->_getConfig('root'));
if (isset($this->config['http_host'])) {
$_SERVER['HTTP_HOST'] = $this->config['http_host'];
}
$request = Request::createFromGlobals();
$autoloader = require $this->_getConfig('root') . '/autoload.php';
$kernel = new TestDrupalKernel('prod', $autoloader, $this->_getConfig('root'));
$kernel->bootTestEnvironment($this->_getConfig('site_path'), $request);
}
/**
* Enabled dependent modules.
*/
public function _beforeSuite($settings = []) {
$module_handler = \Drupal::service('module_handler');
if (!$module_handler->moduleExists('webprofiler')) {
$this->enabledWebProfiler = TRUE;
\Drupal::service('module_installer')->install(['webprofiler']);
}
}
/**
* Disable modules which were enabled.
*/
public function _afterSuite($settings = []) {
if ($this->enabledWebProfiler) {
$this->enabledWebProfiler = FALSE;
\Drupal::service('module_installer')->uninstall(['webprofiler']);
}
}
}