Commit ee24f8d2 authored by catch's avatar catch
Browse files

Issue #3496867 by dcam, drunken monkey, smustgrave, nicxvan: Uninstalling a...

Issue #3496867 by dcam, drunken monkey, smustgrave, nicxvan: Uninstalling a module deletes all views that have third-party settings by that module

(cherry picked from commit db6ddf92)
parent 60d98a67
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -477,7 +477,7 @@ public function invalidateCaches() {
   * {@inheritdoc}
   */
  public function onDependencyRemoval(array $dependencies) {
    $changed = FALSE;
    $changed = parent::onDependencyRemoval($dependencies);

    // Don't intervene if the views module is removed.
    if (isset($dependencies['module']) && in_array('views', $dependencies['module'])) {
+37 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  module:
    - node
    - views_third_party_settings_test
third_party_settings:
  views_third_party_settings_test:
    example_setting: true
id: test_third_party_uninstall
label: test_third_party_uninstall
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
  default:
    display_options:
      access:
        type: none
      cache:
        type: tag
      exposed_form:
        type: basic
      pager:
        type: full
      query:
        type: views_query
      style:
        type: default
      row:
        type: fields
    display_plugin: default
    display_title: Defaults
    id: default
    position: 0
+7 −0
Original line number Diff line number Diff line
views.view.*.third_party.views_third_party_settings_test:
  type: config_entity
  label: "Example settings"
  mapping:
    example_setting:
      type: boolean
      label: "Example setting"
+8 −0
Original line number Diff line number Diff line
name: 'Third Party Settings Test'
type: module
description: 'A dummy module that third party settings tests can depend on'
package: Testing
version: VERSION
dependencies:
  - drupal:node
  - drupal:views
+55 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\views\Kernel;

use Drupal\views\Entity\View;

/**
 * Tests proper removal of third-party settings from views.
 *
 * @group views
 */
class ThirdPartyUninstallTest extends ViewsKernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['node', 'views_third_party_settings_test'];

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = ['test_third_party_uninstall'];

  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    $this->installEntitySchema('user');
    $this->installSchema('user', ['users_data']);
  }

  /**
   * Tests removing third-party settings when a provider module is uninstalled.
   */
  public function testThirdPartyUninstall(): void {
    $view = View::load('test_third_party_uninstall');
    $this->assertNotEmpty($view);
    $this->assertContains('views_third_party_settings_test', $view->getDependencies()['module']);
    $this->assertTrue($view->getThirdPartySetting('views_third_party_settings_test', 'example_setting'));

    \Drupal::service('module_installer')->uninstall(['views_third_party_settings_test']);

    $view = View::load('test_third_party_uninstall');
    $this->assertNotEmpty($view);
    $this->assertNotContains('views_third_party_settings_test', $view->getDependencies()['module']);
    $this->assertNull($view->getThirdPartySetting('views_third_party_settings_test', 'example_setting'));
  }

}