function SettingsFormTest::testSettingsForm

Same name in this branch
  1. 11.x core/modules/jsonapi/tests/src/Functional/SettingsFormTest.php \Drupal\Tests\jsonapi\Functional\SettingsFormTest::testSettingsForm()
  2. 11.x core/modules/media_library/tests/src/Functional/SettingsFormTest.php \Drupal\Tests\media_library\Functional\SettingsFormTest::testSettingsForm()
Same name and namespace in other branches
  1. 10 core/modules/jsonapi/tests/src/Functional/SettingsFormTest.php \Drupal\Tests\jsonapi\Functional\SettingsFormTest::testSettingsForm()
  2. 10 core/modules/media_library/tests/src/Functional/SettingsFormTest.php \Drupal\Tests\media_library\Functional\SettingsFormTest::testSettingsForm()

Tests that executable paths can be configured through the settings form.

File

core/modules/package_manager/tests/src/Functional/SettingsFormTest.php, line 31

Class

SettingsFormTest
Tests the Package Manager settings form.

Namespace

Drupal\Tests\package_manager\Functional

Code

public function testSettingsForm() : void {
  $assert_session = $this->assertSession();
  $account = $this->drupalCreateUser([
    'administer software updates',
  ]);
  $this->drupalLogin($account);
  /** @var \PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface $executable_finder */
  $executable_finder = \Drupal::service(ExecutableFinderInterface::class);
  try {
    $composer_path = $executable_finder->find('composer');
    $rsync_path = $executable_finder->find('rsync');
  } catch (LogicException) {
    $this->markTestSkipped('This test requires Composer and rsync to be available in the PATH.');
  }
  $this->drupalGet('/admin/config/system/package-manager');
  $assert_session->statusCodeEquals(200);
  // Submit the settings form with the detected paths, with whitespace added
  // to test that it is trimmed out.
  $this->submitForm([
    'composer' => "{$composer_path}  ",
    'rsync' => " {$rsync_path}",
  ], 'Save configuration');
  $assert_session->pageTextContains('The configuration options have been saved.');
  // Verify the paths were saved in config.
  $config = $this->config('package_manager.settings');
  $this->assertSame($composer_path, $config->get('executables.composer'));
  $this->assertSame($rsync_path, $config->get('executables.rsync'));
  // Verify the paths are shown in the form.
  $this->drupalGet('/admin/config/system/package-manager');
  $assert_session->fieldValueEquals('composer', $composer_path);
  $assert_session->fieldValueEquals('rsync', $rsync_path);
  // Ensure that the executable paths are confirmed to be executable.
  $this->submitForm([
    'composer' => 'rm -rf /',
    'rsync' => 'cat /etc/passwd',
  ], 'Save configuration');
  $assert_session->statusMessageContains('"rm -rf /" is not an executable file.', 'error');
  $assert_session->statusMessageContains('"cat /etc/passwd" is not an executable file.', 'error');
}

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