function StatusCommandTest::testDrupalUriContext

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Kernel/Command/StatusCommandTest.php \Drupal\Tests\system\Kernel\Command\StatusCommandTest::testDrupalUriContext()

Tests variations of the 'DRUPAL_URI' context.

File

core/modules/system/tests/src/Kernel/Command/StatusCommandTest.php, line 33

Class

StatusCommandTest
Tests the 'system:status' command.

Namespace

Drupal\Tests\system\Kernel\Command

Code

public function testDrupalUriContext() : void {
  $tester = $this->applicationTester();
  $this->assertEquals(Command::SUCCESS, $tester->run([
    'command' => 'system:status',
  ]));
  $this->assertStringContainsStringNoWhitespace('Site URL : http://localhost', $tester->getDisplay());
  $this->assertStringContainsStringNoWhitespace('Drupal version : ' . \Drupal::VERSION, $tester->getDisplay());
  // When the host is provided without a port, 80 is used, and this is omitted
  // from generated URLs.
  $tester = $this->applicationTester([
    'DRUPAL_URI' => 'https://example.com',
  ]);
  $this->assertEquals(Command::SUCCESS, $tester->run([
    'command' => 'system:status',
  ]));
  $this->assertStringContainsStringNoWhitespace('Site URL : https://example.com', $tester->getDisplay());
  // Test when a different port is present in generated URLs.
  $tester = $this->applicationTester([
    'DRUPAL_URI' => 'https://example.com:3333',
  ]);
  $this->assertEquals(Command::SUCCESS, $tester->run([
    'command' => 'system:status',
  ]));
  $this->assertStringContainsStringNoWhitespace('Site URL : https://example.com:3333', $tester->getDisplay());
  // Test base URL with a subdirectory.
  $tester = $this->applicationTester([
    'DRUPAL_URI' => 'https://example.com/drupal',
  ]);
  $this->assertEquals(Command::SUCCESS, $tester->run([
    'command' => 'system:status',
  ]));
  $this->assertStringContainsStringNoWhitespace('Site URL : https://example.com/drupal', $tester->getDisplay());
  // Test base URL with a port and a subdirectory.
  $tester = $this->applicationTester([
    'DRUPAL_URI' => 'https://example.com:3333/drupal',
  ]);
  $this->assertEquals(Command::SUCCESS, $tester->run([
    'command' => 'system:status',
  ]));
  $this->assertStringContainsStringNoWhitespace('Site URL : https://example.com:3333/drupal', $tester->getDisplay());
}

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