You are here

public function PatchInfoTest::testUpdateReport in PatchInfo 8.2

Tests exposure of patch information in update report.

File

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

Class

PatchInfoTest
Tests functionality of PatchInfo module.

Namespace

Drupal\Tests\patchinfo\Functional

Code

public function testUpdateReport() {
  $this
    ->installTestThemes();
  $this
    ->exposeTestExtensions();
  $this
    ->drupalLogin($this->users['patchinfo']);
  $this
    ->drupalGet('admin/reports/updates');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Patches:');
  $this
    ->assertElementByCssSelector('.patchinfo-patches');
  $this
    ->assertElementByCssSelector('.patchinfo-patches-title');
  $module_path = $this->container
    ->get('module_handler')
    ->getModule('patchinfo')
    ->getPath();

  // 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;');

  // Assert patches added for test_info_source.
  $this
    ->assertPatchInformationInReport('test_info_source', '8.x-1.0', 'Issue 1739718, Patch #32', 'https://www.drupal.org/node/1739718', $module_path . '/tests/modules/test_info_source/test_info_source.info.yml');
  $this
    ->assertPatchInformationInReport('test_info_source', '8.x-1.0', 'Patch without URL', '', $module_path . '/tests/modules/test_info_source/test_info_source.info.yml');
  $this
    ->assertPatchInformationInReport('test_info_source', '8.x-1.0', '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
    ->assertPatchInformationInReport('test_info_source', '8.x-1.0', '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
    ->assertPatchInformationInReport('test_info_source', '8.x-1.0', '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
    ->assertPatchInformationInReport('test_composer_source', '8.x-1.0', 'Add startup configuration for PHP server', 'https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch', $json_path);
  $this
    ->assertPatchInformationInReport('Drupal core', '8.0.0', 'Add startup configuration for PHP server', 'https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch', $json_path);

  // Assert no XSS via PatchInfo Composer source plugin.
  $this
    ->assertSession()
    ->responseNotContains('<IMG SRC=/ onerror=\'alert(String.fromCharCode(88,83,83))\'></img>');
  $this
    ->assertSession()
    ->responseContains('&lt;IMG SRC=/ onerror=&#039;alert(String.fromCharCode(88,83,83))&#039;&gt;&lt;/img&gt;');

  // 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
    ->assertPatchInformationInReport('test_mixed_sources', '8.x-1.0', 'Issue 2739718, Patch #42', 'https://www.drupal.org/node/2739718', $module_path . '/tests/modules/test_mixed_sources/test_mixed_sources.info.yml');
  $this
    ->assertPatchInformationInReport('test_mixed_sources', '8.x-1.0', 'Patch with-out URLs', '', $module_path . '/tests/modules/test_mixed_sources/test_mixed_sources.info.yml');
  $this
    ->assertPatchInformationInReport('test_mixed_sources', '8.x-1.0', 'Patch with some special $()äöüß[]~!*{}%', 'https://www.example.net/', $module_path . '/tests/modules/test_mixed_sources/test_mixed_sources.info.yml');
  $this
    ->assertPatchInformationInReport('test_mixed_sources', '8.x-1.0', 'Issue #3013512 by brtamas: Php 7.2 each() deprecated', 'https://git.drupalcode.org/project/draggableviews/commit/b973bfaf33b37ca5e473edddf20e25da1f9df163.diff', $json_path);
  $this
    ->assertPatchInformationInReport('Drupal core', '8.0.0', '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 warning logged for syntax errors in composer.json.
  $json_path = $this->container
    ->get('file_system')
    ->realpath($module_path . '/tests/modules/test_composer_syntax_error/composer.json');
  $this
    ->assertWatchdogMessage('patchinfo_source_composer', RfcLogLevel::WARNING, strtr('Unable to parse @json_path. Check your JSON syntax.', [
    '@json_path' => $json_path,
  ]));

  // Assert patches added for test_theme_info_source.
  $this
    ->assertPatchInformationInReport('test_theme_info_source', '8.x-1.0', 'Issue 2239723, Patch #14', 'https://www.drupal.org/node/2239723', $module_path . '/tests/themes/test_theme_info_source/test_theme_info_source.info.yml');
  $this
    ->assertPatchInformationInReport('test_theme_info_source', '8.x-1.0', 'Patch in theme without URL', '', $module_path . '/tests/themes/test_theme_info_source/test_theme_info_source.info.yml');
  $this
    ->assertPatchInformationInReport('test_theme_info_source', '8.x-1.0', 'Theme patch with some special ~!*äöüß()[]{}%$', 'https://www.example.net/', $module_path . '/tests/themes/test_theme_info_source/test_theme_info_source.info.yml');

  // Assert patches added for test_subtheme_info_source.
  $this
    ->assertPatchInformationInReport('test_theme_info_source', '8.x-1.0', 'Patch in sub-theme without URL', '', $module_path . '/tests/themes/test_subtheme_info_source/test_subtheme_info_source.info.yml');

  // 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
    ->assertPatchInformationInReport('test_theme_composer_source', '8.x-1.0', 'Add patch to test theme to facilitate testing', 'https://www.drupal.org/files/issues/add_a_patch-1643831-40.patch', $json_path);
  $this
    ->assertPatchInformationInReport('Drupal core', '8.0.0', '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
    ->assertPatchInformationInReport('test_theme_mixed_sources', '8.x-1.0', 'Issue #3013512 by brtamas: Php 7.2 each() deprecated', 'https://git.drupalcode.org/project/draggableviews/commit/b973bfaf33b37ca5e473edddf20e25da1f9df163.diff', $json_path);
  $this
    ->assertPatchInformationInReport('Drupal core', '8.0.0', '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);
}