ClassLoaderTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/Module/ClassLoaderTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Module;
use Drupal\module_autoload_test\SomeClass;
use Drupal\Tests\BrowserTestBase;
class ClassLoaderTest extends BrowserTestBase {
protected $expected = 'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.';
protected $apcuEnsureUniquePrefix = TRUE;
protected $defaultTheme = 'stark';
public function testClassLoading() {
\Drupal::service('module_installer')
->install([
'module_test',
'module_autoload_test',
], FALSE);
$this
->resetAll();
for ($i = 0; $i < 2; $i++) {
$this
->drupalGet('module-test/class-loading');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this->expected);
}
}
public function testClassLoadingNotInstalledModules() {
\Drupal::service('module_installer')
->install([
'module_test',
], FALSE);
$this
->resetAll();
for ($i = 0; $i < 2; $i++) {
$this
->drupalGet('module-test/class-loading');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($this->expected);
}
}
public function testClassLoadingDisabledModules() {
\Drupal::service('module_installer')
->install([
'module_test',
'module_autoload_test',
], FALSE);
$this
->resetAll();
$this->container
->get('module_installer')
->uninstall([
'module_autoload_test',
], FALSE);
$this
->resetAll();
for ($i = 0; $i < 2; $i++) {
$this
->drupalGet('module-test/class-loading');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($this->expected);
}
}
public function testMultipleModules() {
$this
->drupalLogin($this->rootUser);
$edit = [
"modules[module_install_class_loader_test1][enable]" => TRUE,
"modules[module_install_class_loader_test2][enable]" => TRUE,
];
$this
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->rebuildContainer();
$this
->assertTrue(\Drupal::moduleHandler()
->moduleExists('module_install_class_loader_test2'), 'The module_install_class_loader_test2 module has been installed.');
}
public function testAutoloadFromModuleFile() {
$this
->assertFalse(defined('MODULE_AUTOLOAD_TEST_CONSTANT'));
$this
->drupalLogin($this->rootUser);
$edit = [
"modules[module_autoload_test][enable]" => TRUE,
];
$this
->drupalGet('admin/modules');
$this
->submitForm($edit, 'Install');
$this
->assertSession()
->statusCodeEquals(200);
$this
->resetAll();
$this
->assertSame(SomeClass::TEST, MODULE_AUTOLOAD_TEST_CONSTANT);
}
}