You are here

public function ConfigUpdateTest::testConfigReport in Configuration Update Manager 8

Tests the config report and its linked pages.

File

config_update_ui/tests/src/Functional/ConfigUpdateTest.php, line 82

Class

ConfigUpdateTest
Verify the config revert report and its links.

Namespace

Drupal\Tests\config_update_ui\Functional

Code

public function testConfigReport() {

  // Test links to report page.
  $this
    ->drupalGet('admin/config/development/configuration');
  $this
    ->clickLink('Updates report');
  $this
    ->assertNoReport();

  // Verify the Drush list types command.
  $output = implode("\n", drush_config_update_ui_config_list_types());
  $this
    ->assertTrue(strpos($output, 'search_page') !== FALSE);
  $this
    ->assertTrue(strpos($output, 'node_type') !== FALSE);
  $this
    ->assertTrue(strpos($output, 'user_role') !== FALSE);
  $this
    ->assertTrue(strpos($output, 'block') !== FALSE);

  // Verify some empty reports.
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);
  $this
    ->assertDrushReports('type', 'search_page', [], [], [], []);

  // Module, theme, and profile reports have no 'added' section.
  $this
    ->drupalGet('admin/config/development/configuration/report/module/search');
  $this
    ->assertReport('Search module', [], [], [], [], [
    'added',
  ]);
  $this
    ->assertDrushReports('module', 'search', [], [], [], []);
  $this
    ->drupalGet('admin/config/development/configuration/report/theme/classy');
  $this
    ->assertReport('Classy theme', [], [], [], [], [
    'added',
  ]);
  $this
    ->assertDrushReports('theme', 'classy', [], [], [], []);
  $inactive = [
    'locale.settings' => 'Simple configuration',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/profile');
  $this
    ->assertReport('Testing profile', [], [], [], $inactive, [
    'added',
  ]);

  // The locale.settings line should show that the Testing profile is the
  // provider.
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Testing profile');
  $this
    ->assertDrushReports('profile', '', [], [], [], array_keys($inactive));

  // Verify that the user search page cannot be imported (because it already
  // exists).
  $this
    ->drupalGet('admin/config/development/configuration/report/import/search_page/user_search');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(404);

  // Delete the user search page from the search UI and verify report for
  // both the search page config type and user module.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->clickLink('Delete');
  $this
    ->drupalPostForm(NULL, [], 'Delete');
  $inactive = [
    'search.page.user_search' => 'Users',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], $inactive);

  // The search.page.user_search line should show that the User module is the
  // provider.
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('User module');
  $this
    ->assertDrushReports('type', 'search_page', [], [], [], array_keys($inactive));
  $this
    ->drupalGet('admin/config/development/configuration/report/module/user');
  $this
    ->assertReport('User module', [], [], [], $inactive, [
    'added',
    'changed',
  ]);
  $this
    ->assertDrushReports('module', 'user', [], [], [], [
    'rdf.mapping.user.user',
    'search.page.user_search',
    'views.view.user_admin_people',
    'views.view.who_s_new',
    'views.view.who_s_online',
  ], [
    'changed',
  ]);

  // Verify that the user search page cannot be reverted (because it does
  // not already exist).
  $this
    ->drupalGet('admin/config/development/configuration/report/revert/search_page/user_search');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(404);

  // Verify that the delete URL doesn't work either.
  $this
    ->drupalGet('admin/config/development/configuration/report/delete/search_page/user_search');
  $session = $this
    ->assertSession();
  $session
    ->statusCodeEquals(404);

  // Use the import link to get it back. Do this from the search page
  // report to make sure we are importing the right config.
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->clickLink('Import from source');
  $this
    ->drupalPostForm(NULL, [], 'Import');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('has been imported');
  $this
    ->assertNoReport();
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);
  $this
    ->assertDrushReports('type', 'search_page', [], [], [], []);

  // Verify that after import, there is no config hash generated.
  $this
    ->drupalGet('admin/config/development/configuration/single/export/search_page/user_search');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('id: user_search');
  $session
    ->pageTextNotContains('default_config_hash:');

  // Test importing again, this time using the Drush import command.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->clickLink('Delete');
  $this
    ->drupalPostForm(NULL, [], 'Delete');
  $inactive = [
    'search.page.user_search' => 'Users',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], $inactive);
  drush_config_update_ui_config_import_missing('search.page.user_search');
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);

  // Edit the node search page from the search UI and verify report.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->clickLink('Edit');
  $this
    ->drupalPostForm(NULL, [
    'label' => 'New label',
    'path' => 'new_path',
  ], 'Save search page');
  $changed = [
    'search.page.node_search' => 'New label',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], $changed, []);
  $this
    ->assertDrushReports('type', 'search_page', [], [], array_keys($changed), []);

  // Test the show differences link.
  $this
    ->clickLink('Show differences');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Content');
  $session
    ->pageTextContains('New label');
  $session
    ->pageTextContains('node');
  $session
    ->pageTextContains('new_path');

  // Test the show differences Drush command.
  $output = drush_config_update_ui_config_diff('search.page.node_search');
  $this
    ->assertTrue(strpos($output, 'Content') !== FALSE);
  $this
    ->assertTrue(strpos($output, 'New label') !== FALSE);
  $this
    ->assertTrue(strpos($output, 'node') !== FALSE);
  $this
    ->assertTrue(strpos($output, 'new_path') !== FALSE);

  // Test the Back link.
  $this
    ->clickLink("Back to 'Updates report' page.");
  $this
    ->assertNoReport();

  // Test the export link.
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->clickLink('Export');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Here is your configuration:');
  $session
    ->pageTextContains('id: node_search');
  $session
    ->pageTextContains('New label');
  $session
    ->pageTextContains('path: new_path');
  $session
    ->pageTextContains('search.page.node_search.yml');

  // Grab the uuid and hash lines from the exported config for the next test.
  $text = strip_tags($this
    ->getSession()
    ->getPage()
    ->find('css', 'textarea')
    ->getHtml());
  $matches = [];
  preg_match('|^.*uuid:.*$|m', $text, $matches);
  $uuid_line = trim($matches[0]);
  preg_match('|^.*default_config_hash:.*$|m', $text, $matches);
  $hash_line = trim($matches[0]);

  // Test reverting.
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->clickLink('Revert to source');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Are you sure you want to revert');
  $session
    ->pageTextContains('Search page');
  $session
    ->pageTextContains('node_search');
  $session
    ->pageTextContains('Customizations will be lost. This action cannot be undone');
  $this
    ->drupalPostForm(NULL, [], 'Revert');
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);

  // Verify that the uuid and hash keys were retained in the revert.
  $this
    ->drupalGet('admin/config/development/configuration/single/export/search_page/node_search');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('id: node_search');
  $session
    ->pageTextContains($uuid_line);
  $session
    ->pageTextContains($hash_line);

  // Test reverting again, this time using Drush single revert command.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->clickLink('Edit');
  $this
    ->drupalPostForm(NULL, [
    'label' => 'New label',
    'path' => 'new_path',
  ], 'Save search page');
  $changed = [
    'search.page.node_search' => 'New label',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], $changed, []);
  drush_config_update_ui_config_revert('search.page.node_search');
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);

  // Test reverting again, this time using Drush multiple revert command.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->clickLink('Edit');
  $this
    ->drupalPostForm(NULL, [
    'label' => 'New label',
    'path' => 'new_path',
  ], 'Save search page');
  $changed = [
    'search.page.node_search' => 'New label',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], $changed, []);
  drush_config_update_ui_config_revert_multiple('type', 'search_page');
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);

  // Add a new search page from the search UI and verify report.
  $this
    ->drupalPostForm('admin/config/search/pages', [
    'search_type' => 'node_search',
  ], 'Add search page');
  $this
    ->drupalPostForm(NULL, [
    'label' => 'test',
    'id' => 'test',
    'path' => 'test',
  ], 'Save');
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $added = [
    'search.page.test' => 'test',
  ];
  $this
    ->assertReport('Search page', [], $added, [], []);
  $this
    ->assertDrushReports('type', 'search_page', [], array_keys($added), [], []);

  // Test the export link.
  $this
    ->clickLink('Export');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Here is your configuration:');
  $session
    ->pageTextContains('id: test');
  $session
    ->pageTextContains('label: test');
  $session
    ->pageTextContains('path: test');
  $session
    ->pageTextContains('search.page.test.yml');

  // Test the delete link.
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->clickLink('Delete');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Are you sure');
  $session
    ->pageTextContains('cannot be undone');
  $this
    ->drupalPostForm(NULL, [], 'Delete');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('has been deleted');

  // And verify the report again.
  $this
    ->drupalGet('admin/config/development/configuration/report/type/search_page');
  $this
    ->assertReport('Search page', [], [], [], []);

  // Change the search module config and verify the actions work for
  // simple config.
  $this
    ->drupalPostForm('admin/config/search/pages', [
    'minimum_word_size' => 4,
  ], 'Save configuration');
  $changed = [
    'search.settings' => 'search.settings',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/module/search');
  $this
    ->assertReport('Search module', [], [], $changed, [], [
    'added',
  ]);
  $this
    ->clickLink('Show differences');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('Config difference for Simple configuration search.settings');
  $session
    ->pageTextContains('index::minimum_word_size');
  $session
    ->pageTextContains('4');
  $this
    ->drupalGet('admin/config/development/configuration/report/module/search');
  $this
    ->clickLink('Export');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains('minimum_word_size: 4');

  // Grab the hash line for the next test.
  $text = strip_tags($this
    ->getSession()
    ->getPage()
    ->find('css', 'textarea')
    ->getHtml());
  $matches = [];
  preg_match('|^.*default_config_hash:.*$|m', $text, $matches);
  $hash_line = trim($matches[0]);
  $this
    ->drupalGet('admin/config/development/configuration/report/module/search');
  $this
    ->clickLink('Revert to source');
  $this
    ->drupalPostForm(NULL, [], 'Revert');

  // Verify that the hash was retained in the revert.
  $this
    ->drupalGet('admin/config/development/configuration/single/export/system.simple/search.settings');
  $session = $this
    ->assertSession();
  $session
    ->pageTextContains($hash_line);
  $this
    ->drupalGet('admin/config/development/configuration/report/module/search');
  $this
    ->assertReport('Search module', [], [], [], [], [
    'added',
  ]);

  // Edit the plain_text filter from the filter UI and verify report.
  // The filter_format config type uses a label key other than 'label'.
  $this
    ->drupalPostForm('admin/config/content/formats/manage/plain_text', [
    'name' => 'New label',
  ], 'Save configuration');
  $changed = [
    'filter.format.plain_text' => 'New label',
  ];
  $this
    ->drupalGet('admin/config/development/configuration/report/type/filter_format');
  $this
    ->assertReport('Text format', [], [], $changed, []);

  // Verify that we can revert non-entity configuration in Drush. Issue:
  // https://www.drupal.org/project/config_update/issues/2935395
  drush_config_update_ui_config_revert('system.date');
}