Skip to content

Commit

Permalink
Fix/1.x/150 support reinstall (#153)
Browse files Browse the repository at this point in the history
* Added this module as a dependency of the install config so it gets removed on uninstall.
* Added test to prove reinstall works.
* Removed commented code. πŸ‘¨β€πŸ’» 
* Removed the localgov_publications_heading_ids filter before trying to remove the module.
  • Loading branch information
rupertj committed Apr 16, 2024
1 parent 50e333c commit 440dbb6
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ dependencies:
- media.type.document
module:
- file
- localgov_publications
enforced:
module:
- localgov_publications
id: media.document.publication
targetEntityType: media
bundle: document
Expand Down
4 changes: 4 additions & 0 deletions config/install/core.entity_view_mode.media.publication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- media
- localgov_publications
enforced:
module:
- localgov_publications
id: media.publication
label: Publication
description: ''
Expand Down
4 changes: 4 additions & 0 deletions config/install/field.storage.node.localgov_documents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ dependencies:
module:
- media
- node
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_documents
field_name: localgov_documents
entity_type: node
Expand Down
4 changes: 4 additions & 0 deletions config/install/field.storage.node.localgov_page_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ dependencies:
- entity_reference_revisions
- node
- paragraphs
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_page_content
field_name: localgov_page_content
entity_type: node
Expand Down
4 changes: 4 additions & 0 deletions config/install/field.storage.node.localgov_publication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- node
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_publication
field_name: localgov_publication
entity_type: node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ dependencies:
- entity_reference_revisions
- node
- paragraphs
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_publication_content
field_name: localgov_publication_content
entity_type: node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ dependencies:
- entity_reference_revisions
- node
- paragraphs
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_publications_banner
field_name: localgov_publications_banner
entity_type: node
Expand Down
4 changes: 4 additions & 0 deletions config/install/field.storage.node.localgov_published_date.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ dependencies:
module:
- datetime
- node
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_published_date
field_name: localgov_published_date
entity_type: node
Expand Down
4 changes: 4 additions & 0 deletions config/install/field.storage.node.localgov_updated_date.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ dependencies:
module:
- datetime
- node
- localgov_publications
enforced:
module:
- localgov_publications
id: node.localgov_updated_date
field_name: localgov_updated_date
entity_type: node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- paragraphs
- localgov_publications
enforced:
module:
- localgov_publications
id: paragraph.localgov_publications_text
field_name: localgov_publications_text
entity_type: paragraph
Expand Down
4 changes: 4 additions & 0 deletions config/install/node.type.localgov_publication_cover_page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- menu_ui
- localgov_publications
enforced:
module:
- localgov_publications
third_party_settings:
menu_ui:
available_menus:
Expand Down
4 changes: 4 additions & 0 deletions config/install/node.type.localgov_publication_page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- menu_ui
- localgov_publications
enforced:
module:
- localgov_publications
third_party_settings:
menu_ui:
available_menus:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
langcode: en
status: true
dependencies: { }
dependencies:
module:
- localgov_publications
enforced:
module:
- localgov_publications
id: localgov_publications_banner
label: 'Publications Banner'
icon_uuid: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- node
- localgov_publications
enforced:
module:
- localgov_publications
id: localgov_publication_cover_page
label: 'Publication cover page'
type: 'canonical_entities:node'
Expand Down
4 changes: 4 additions & 0 deletions config/install/pathauto.pattern.publication_page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ status: true
dependencies:
module:
- node
- localgov_publications
enforced:
module:
- localgov_publications
id: publication_page
label: 'Publication page'
type: 'canonical_entities:node'
Expand Down
4 changes: 4 additions & 0 deletions config/install/views.view.documents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ dependencies:
- entity_reference_revisions
- media
- user
- localgov_publications
enforced:
module:
- localgov_publications
id: documents
label: Documents
module: views
Expand Down
84 changes: 84 additions & 0 deletions tests/src/Functional/ReinstallTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Drupal\Tests\localgov_publications\Functional;

use Drupal\filter\Entity\FilterFormat;
use Drupal\filter\FilterFormatInterface;
use Drupal\Tests\BrowserTestBase;

/**
* Tests module reinstallation.
*
* This checks that the module cleans up after itself when uninstalled. If it
* can be successfully reinstalled, we'll assume the cleanup was sufficient.
*
* @group localgov_publications
*/
class ReinstallTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'localgov_base';

/**
* {@inheritdoc}
*/
protected $profile = 'localgov';

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

/**
* Test that the module can be reinstalled.
*/
public function testReinstall() {

/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = $this->container->get('module_handler');

/** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
$moduleInstaller = $this->container->get('module_installer');

// Confirm module has been installed.
$this->assertTrue($moduleHandler->moduleExists('localgov_publications'));

// Remove the localgov_publications_heading_ids filter.
$this->removeFilter();

// Uninstall module.
$moduleInstaller->uninstall(['localgov_publications']);

// Confirm module has been uninstalled.
$this->assertFalse($moduleHandler->moduleExists('localgov_publications'));

// Install module.
$this->assertTrue($moduleInstaller->install(['localgov_publications']));
}

/**
* Removes the localgov_publications_heading_ids filter.
*
* To allow localgov_publications to be uninstalled, the
* localgov_publications_heading_ids filter must be removed from the wysiwyg
* filter format. People that wish to remove this module will need
* to do it manually, but we'll automate it for the purposes of letting this
* test run.
*/
protected function removeFilter(): void {
$wysiwygFormat = FilterFormat::load('wysiwyg');
$this->assertInstanceOf(FilterFormatInterface::class, $wysiwygFormat);

// We need to call this to let the next call to removeFilter() work. If you
// don't call this first, the object's filterCollection property isn't set.
$wysiwygFormat->filters('localgov_publications_heading_ids');

$wysiwygFormat->removeFilter('localgov_publications_heading_ids');
$wysiwygFormat->save();
}

}

0 comments on commit 440dbb6

Please sign in to comment.