diff --git a/core/modules/system/src/Tests/Module/PrepareUninstallTest.php b/core/modules/system/src/Tests/Module/PrepareUninstallTest.php index d59673c..f108dc8 100644 --- a/core/modules/system/src/Tests/Module/PrepareUninstallTest.php +++ b/core/modules/system/src/Tests/Module/PrepareUninstallTest.php @@ -3,16 +3,17 @@ namespace Drupal\system\Tests\Module; use Drupal\simpletest\WebTestBase; +use Drupal\taxonomy\Tests\TaxonomyTestTrait; /** - * Tests that modules can be uninstalled. - * - * Here we take the Node module as example to test the prepare uninstallation. + * Tests that modules which provide entity types can be uninstalled. * * @group Module */ class PrepareUninstallTest extends WebTestBase { + use TaxonomyTestTrait; + /** * An array of node objects. * @@ -21,11 +22,18 @@ class PrepareUninstallTest extends WebTestBase { protected $nodes; /** + * An array of taxonomy term objects. + * + * @var \Drupal\taxonomy\TermInterface[] + */ + protected $terms; + + /** * Modules to enable. * * @var array */ - public static $modules = ['node']; + public static $modules = ['node', 'taxonomy']; /** * {@inheritdoc} @@ -41,12 +49,53 @@ public function setUp() { $this->nodes[] = $this->drupalCreateNode(['type' => 'page']); $this->nodes[] = $this->drupalCreateNode(['type' => 'article']); } + + // Create 3 top-level taxonomy terms, each with 4 children. + $vocabulary = $this->createVocabulary(); + for ($i = 1; $i <= 3; $i++) { + $term = $this->createTerm($vocabulary); + $this->terms[] = $term; + for ($j = 1; $j <= 4; $j++) { + $this->terms[] = $this->createTerm($vocabulary, ['parent' => ['target_id' => $term->id()]]); + } + } } /** - * Tests that Node module can be uninstalled. + * Tests that Node and Taxonomy can be uninstalled. */ public function testUninstall() { + // Check that Taxonomy cannot be uninstalled yet. + $this->drupalGet('admin/modules/uninstall'); + $this->assertText('Remove content items'); + $this->assertLinkByHref('admin/modules/uninstall/entity/taxonomy_term'); + + // Delete Taxonomy term data. + $this->drupalGet('admin/modules/uninstall/entity/taxonomy_term'); + for ($i = 14; $i >= 5; $i--) { + $this->assertText($this->terms[$i]->label()); + } + $this->assertText('And 5 more taxonomy term entities.'); + $this->assertText('This action cannot be undone.'); + $this->assertText('Make a backup of your database if you want to be able to restore these items.'); + $this->drupalPostForm(NULL, ['limit' => 1], t('Delete all taxonomy term entities')); + + // Check that we are redirected to the uninstall page and data has been + // removed. + $this->assertUrl('admin/modules/uninstall', []); + $this->assertText('All taxonomy term entities have been deleted.'); + + // Check that there is no more data to be deleted, Taxonomy is ready to be + // disabled. + $this->assertText('Enables the categorization of content.'); + $this->assertNoLinkByHref('admin/modules/uninstall/entity/taxonomy_term'); + + // Uninstall the Taxonomy module. + $this->drupalPostForm('admin/modules/uninstall', ['uninstall[taxonomy]' => TRUE], t('Uninstall')); + $this->drupalPostForm(NULL, [], t('Uninstall')); + $this->assertText('The selected modules have been uninstalled.'); + $this->assertNoText('Enables the categorization of content.'); + // Check Node cannot be uninstalled yet, there is content to be removed. $this->drupalGet('admin/modules/uninstall'); $this->assertText('Remove content items');