function DrupalKernelTest::testFindSitePath

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest::testFindSitePath()
  2. 8.9.x core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest::testFindSitePath()
  3. 10 core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest::testFindSitePath()

Tests site path finding.

This test is run in a separate process since it defines DRUPAL_ROOT. This stops any possible pollution of other tests.

@covers ::findSitePath @runInSeparateProcess

File

core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php, line 117

Class

DrupalKernelTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21DrupalKernel.php/class/DrupalKernel/11.x" title="The DrupalKernel class is the core of Drupal itself." class="local">\Drupal\Core\DrupalKernel</a> @group DrupalKernel

Namespace

Drupal\Tests\Core\DrupalKernel

Code

public function testFindSitePath() : void {
    $vfs_root = vfsStream::setup('drupal_root');
    $sites_php = <<<'EOD'
<?php
$sites['8888.www.example.org'] = 'example';
EOD;
    // Create the expected directory structure.
    vfsStream::create([
        'sites' => [
            'sites.php' => $sites_php,
            'example' => [
                'settings.php' => 'test',
            ],
        ],
    ]);
    $request = new Request();
    $request->server
        ->set('SERVER_NAME', 'www.example.org');
    $request->server
        ->set('SERVER_PORT', '8888');
    $request->server
        ->set('SCRIPT_NAME', '/index.php');
    $this->assertEquals('sites/example', DrupalKernel::findSitePath($request, TRUE, $vfs_root->url()));
    $this->assertEquals('sites/example', DrupalKernel::findSitePath($request, FALSE, $vfs_root->url()));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.