You are here

public function PatchInfoTest::testUpdateForm in PatchInfo 8.2

Tests exposure of patch information in update manager form.

File

tests/src/Functional/PatchInfoTest.php, line 241

Class

PatchInfoTest
Tests functionality of PatchInfo module.

Namespace

Drupal\Tests\patchinfo\Functional

Code

public function testUpdateForm() {
  $this
    ->exposeTestExtensions(TRUE);

  // Update XML fetch url for update manager to our own test XML source.
  $url = Url::fromUri('base:patchinfo-update-test', [
    'absolute' => TRUE,
  ])
    ->toString();
  $this
    ->config('update.settings')
    ->set('fetch.url', $url)
    ->save();

  // Refresh update information.
  $this
    ->drupalLogin($this->users['patchinfo']);
  $this
    ->drupalGet('admin/reports/updates');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Get update form.
  $this
    ->drupalGet('admin/reports/updates/update');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Assert no XSS via PatchInfo Info source plugin.
  $this
    ->assertSession()
    ->responseNotContains('<IMG SRC=/ onerror="alert(String.fromCharCode(88,83,83))"></img>');
  $this
    ->assertSession()
    ->responseNotContains('<script src=http://xss.rocks/xss.js></script>');
  $this
    ->assertSession()
    ->responseContains('&lt;IMG SRC=/ onerror=&quot;alert(String.fromCharCode(88,83,83))&quot;&gt;&lt;/img&gt;');
  $this
    ->assertSession()
    ->responseContains('&lt;script src=http://xss.rocks/xss.js&gt;&lt;/script&gt;');
  $module_path = $this->container
    ->get('module_handler')
    ->getModule('patchinfo')
    ->getPath();

  // Assert patches added for test_info_source.
  $this
    ->assertPatchInformationInForm('Info source test', 'Issue 1739718, Patch #32', 'https://www.drupal.org/node/1739718', $module_path . '/tests/modules/test_info_source/test_info_source.info.yml');
  $this
    ->assertPatchInformationInForm('Info source test', 'Patch without URL', '', $module_path . '/tests/modules/test_info_source/test_info_source.info.yml');
  $this
    ->assertPatchInformationInForm('Info source test', 'Patch with some special ~!*äöüß()[]{}%$', 'https://www.example.org/', $module_path . '/tests/modules/test_info_source/test_info_source.info.yml');

  // Assert patches added for test_info_source_submodule.
  $this
    ->assertPatchInformationInForm('Info source test', 'Issue 12345678, Patch #90', 'https://www.drupal.org/node/12345678', $module_path . '/tests/modules/test_info_source/submodule/test_info_source_submodule.info.yml');
  $this
    ->assertPatchInformationInForm('Info source test', 'Patch in submodule without URL', '', $module_path . '/tests/modules/test_info_source/submodule/test_info_source_submodule.info.yml');

  // Assert patches added for test_composer_source.
  $json_path = $this->container
    ->get('file_system')
    ->realpath($module_path . '/tests/modules/test_composer_source/composer.json');
  $this
    ->assertPatchInformationInForm('Drupal', 'Add startup configuration for PHP server', 'https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch', $json_path);

  // Assert patches added for test_mixed_sources.
  $json_path = $this->container
    ->get('file_system')
    ->realpath($module_path . '/tests/modules/test_mixed_sources/composer.json');
  $this
    ->assertPatchInformationInForm('Drupal', 'Issue 2556069, Patch #46 (caption element throws TypeError: Cannot read property tagName of null in Drupal.behaviors.filterFilterHtmlUpdating)', 'https://www.drupal.org/files/issues/2018-08-31/2556069-46.patch', $json_path);

  // Assert patches added for test_theme_composer_source.
  $json_path = $this->container
    ->get('file_system')
    ->realpath($module_path . '/tests/themes/test_theme_composer_source/composer.json');
  $this
    ->assertPatchInformationInForm('Drupal', 'Add patch to core to facilitate testing', 'https://www.drupal.org/files/issues/add_a_patch-1643899-62.patch', $json_path);

  // Assert patches added for test_theme_mixed_sources.
  $json_path = $this->container
    ->get('file_system')
    ->realpath($module_path . '/tests/themes/test_theme_mixed_sources/composer.json');
  $this
    ->assertPatchInformationInForm('Drupal', 'Issue 2556069, Patch #46 (caption element throws TypeError: Cannot read property tagName of null in Drupal.behaviors.filterFilterHtmlUpdating)', 'https://www.drupal.org/files/issues/2018-08-31/2556069-46.patch', $json_path);
}