Chris@0: drupalCreateUser(['administer modules']); Chris@0: $this->drupalLogin($admin_user); Chris@0: Chris@0: // Create 10 nodes. Chris@0: for ($i = 1; $i <= 5; $i++) { Chris@0: $this->nodes[] = $this->drupalCreateNode(['type' => 'page']); Chris@0: $this->nodes[] = $this->drupalCreateNode(['type' => 'article']); Chris@0: } Chris@0: Chris@0: // Create 3 top-level taxonomy terms, each with 11 children. Chris@0: $vocabulary = $this->createVocabulary(); Chris@0: for ($i = 1; $i <= 3; $i++) { Chris@0: $term = $this->createTerm($vocabulary); Chris@0: $this->terms[] = $term; Chris@0: for ($j = 1; $j <= 11; $j++) { Chris@0: $this->terms[] = $this->createTerm($vocabulary, ['parent' => ['target_id' => $term->id()]]); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that Node and Taxonomy can be uninstalled. Chris@0: */ Chris@0: public function testUninstall() { Chris@0: // Check that Taxonomy cannot be uninstalled yet. Chris@0: $this->drupalGet('admin/modules/uninstall'); Chris@0: $this->assertText('Remove content items'); Chris@0: $this->assertLinkByHref('admin/modules/uninstall/entity/taxonomy_term'); Chris@0: Chris@0: // Delete Taxonomy term data. Chris@0: $this->drupalGet('admin/modules/uninstall/entity/taxonomy_term'); Chris@0: $term_count = count($this->terms); Chris@0: for ($i = 1; $i < 11; $i++) { Chris@0: $this->assertText($this->terms[$term_count - $i]->label()); Chris@0: } Chris@0: $term_count = $term_count - 10; Chris@0: $this->assertText("And $term_count more taxonomy term entities."); Chris@0: $this->assertText('This action cannot be undone.'); Chris@0: $this->assertText('Make a backup of your database if you want to be able to restore these items.'); Chris@0: $this->drupalPostForm(NULL, [], t('Delete all taxonomy term entities')); Chris@0: Chris@0: // Check that we are redirected to the uninstall page and data has been Chris@0: // removed. Chris@0: $this->assertUrl('admin/modules/uninstall', []); Chris@0: $this->assertText('All taxonomy term entities have been deleted.'); Chris@0: Chris@0: // Check that there is no more data to be deleted, Taxonomy is ready to be Chris@0: // uninstalled. Chris@0: $this->assertText('Enables the categorization of content.'); Chris@0: $this->assertNoLinkByHref('admin/modules/uninstall/entity/taxonomy_term'); Chris@0: Chris@0: // Uninstall the Taxonomy module. Chris@0: $this->drupalPostForm('admin/modules/uninstall', ['uninstall[taxonomy]' => TRUE], t('Uninstall')); Chris@0: $this->drupalPostForm(NULL, [], t('Uninstall')); Chris@0: $this->assertText('The selected modules have been uninstalled.'); Chris@0: $this->assertNoText('Enables the categorization of content.'); Chris@0: Chris@0: // Check Node cannot be uninstalled yet, there is content to be removed. Chris@0: $this->drupalGet('admin/modules/uninstall'); Chris@0: $this->assertText('Remove content items'); Chris@0: $this->assertLinkByHref('admin/modules/uninstall/entity/node'); Chris@0: Chris@0: // Delete Node data. Chris@0: $this->drupalGet('admin/modules/uninstall/entity/node'); Chris@0: // All 10 nodes should be listed. Chris@0: foreach ($this->nodes as $node) { Chris@0: $this->assertText($node->label()); Chris@0: } Chris@0: Chris@0: // Ensures there is no more count when not necessary. Chris@0: $this->assertNoText('And 0 more content'); Chris@0: $this->assertText('This action cannot be undone.'); Chris@0: $this->assertText('Make a backup of your database if you want to be able to restore these items.'); Chris@0: Chris@0: // Create another node so we have 11. Chris@0: $this->nodes[] = $this->drupalCreateNode(['type' => 'page']); Chris@0: $this->drupalGet('admin/modules/uninstall/entity/node'); Chris@0: // Ensures singular case is used when a single entity is left after listing Chris@0: // the first 10's labels. Chris@0: $this->assertText('And 1 more content item.'); Chris@0: Chris@0: // Create another node so we have 12. Chris@0: $this->nodes[] = $this->drupalCreateNode(['type' => 'article']); Chris@0: $this->drupalGet('admin/modules/uninstall/entity/node'); Chris@0: // Ensures singular case is used when a single entity is left after listing Chris@0: // the first 10's labels. Chris@0: $this->assertText('And 2 more content items.'); Chris@0: Chris@0: $this->drupalPostForm(NULL, [], t('Delete all content items')); Chris@0: Chris@0: // Check we are redirected to the uninstall page and data has been removed. Chris@0: $this->assertUrl('admin/modules/uninstall', []); Chris@0: $this->assertText('All content items have been deleted.'); Chris@0: Chris@0: // Check there is no more data to be deleted, Node is ready to be Chris@0: // uninstalled. Chris@0: $this->assertText('Allows content to be submitted to the site and displayed on pages.'); Chris@0: $this->assertNoLinkByHref('admin/modules/uninstall/entity/node'); Chris@0: Chris@0: // Uninstall Node module. Chris@0: $this->drupalPostForm('admin/modules/uninstall', ['uninstall[node]' => TRUE], t('Uninstall')); Chris@0: $this->drupalPostForm(NULL, [], t('Uninstall')); Chris@0: $this->assertText('The selected modules have been uninstalled.'); Chris@0: $this->assertNoText('Allows content to be submitted to the site and displayed on pages.'); Chris@0: Chris@0: // Ensure the proper response when accessing a non-existent entity type. Chris@0: $this->drupalGet('admin/modules/uninstall/entity/node'); Chris@0: $this->assertResponse(404, 'Entity types that do not exist result in a 404.'); Chris@0: Chris@0: // Test an entity type which does not have any existing entities. Chris@0: $this->drupalGet('admin/modules/uninstall/entity/entity_test_no_label'); Chris@0: $this->assertText('There are 0 entity test without label entities to delete.'); Chris@0: $button_xpath = '//input[@type="submit"][@value="Delete all entity test without label entities"]'; Chris@0: $this->assertNoFieldByXPath($button_xpath, NULL, 'Button with value "Delete all entity test without label entities" not found'); Chris@0: Chris@0: // Test an entity type without a label. Chris@0: /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */ Chris@0: $storage = $this->container->get('entity.manager') Chris@0: ->getStorage('entity_test_no_label'); Chris@0: $storage->create([ Chris@0: 'id' => Unicode::strtolower($this->randomMachineName()), Chris@0: 'name' => $this->randomMachineName(), Chris@0: ])->save(); Chris@0: $this->drupalGet('admin/modules/uninstall/entity/entity_test_no_label'); Chris@0: $this->assertText('This will delete 1 entity test without label.'); Chris@0: $this->assertFieldByXPath($button_xpath, NULL, 'Button with value "Delete all entity test without label entities" found'); Chris@0: $storage->create([ Chris@0: 'id' => Unicode::strtolower($this->randomMachineName()), Chris@0: 'name' => $this->randomMachineName(), Chris@0: ])->save(); Chris@0: $this->drupalGet('admin/modules/uninstall/entity/entity_test_no_label'); Chris@0: $this->assertText('This will delete 2 entity test without label entities.'); Chris@0: } Chris@0: Chris@0: }