View source
<?php
namespace Drupal\system\Tests\Module;
use Drupal\Core\Cache\Cache;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\simpletest\WebTestBase;
class UninstallTest extends WebTestBase {
public static $modules = array(
'module_test',
'user',
'views',
'node',
);
function testUserPermsUninstalled() {
$this->container
->get('module_installer')
->uninstall(array(
'module_test',
));
$this
->assertFalse(user_roles(FALSE, 'module_test perm'), 'Permissions were all removed.');
}
function testUninstallPage() {
$account = $this
->drupalCreateUser(array(
'administer modules',
));
$this
->drupalLogin($account);
$node_type = entity_create('node_type', array(
'type' => 'uninstall_blocker',
'name' => 'Uninstall blocker',
));
$node_type
->setThirdPartySetting('module_test', 'key', 'value');
$node_type
->save();
$node = entity_create('node', array(
'type' => 'uninstall_blocker',
'title' => $this
->randomString(),
));
$node
->save();
$this
->drupalGet('admin/modules/uninstall');
$this
->assertTitle(t('Uninstall') . ' | Drupal');
$this
->assertRaw('<label for="edit-uninstall-node" class="module-name table-filter-text-source">Node</label>');
$this
->assertText(\Drupal::translation()
->translate('The following reason prevents Node from being uninstalled:'));
$this
->assertText(\Drupal::translation()
->translate('There is content for the entity type: Content'));
$node
->delete();
$edit = array();
$edit['uninstall[module_test]'] = TRUE;
$this
->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this
->assertNoText(\Drupal::translation()
->translate('Configuration deletions'), 'No configuration deletions listed on the module install confirmation page.');
$this
->assertText(\Drupal::translation()
->translate('Configuration updates'), 'Configuration updates listed on the module install confirmation page.');
$this
->assertText($node_type
->label());
$this
->drupalPostForm(NULL, NULL, t('Uninstall'));
$this
->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
$node_dependencies = \Drupal::service('config.manager')
->findConfigEntityDependentsAsEntities('module', array(
'node',
));
$edit = array();
$edit['uninstall[node]'] = TRUE;
$this
->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this
->assertText(\Drupal::translation()
->translate('Configuration deletions'), 'Configuration deletions listed on the module install confirmation page.');
$this
->assertNoText(\Drupal::translation()
->translate('Configuration updates'), 'No configuration updates listed on the module install confirmation page.');
$entity_types = array();
foreach ($node_dependencies as $entity) {
$label = $entity
->label() ?: $entity
->id();
$this
->assertText($label);
$entity_types[] = $entity
->getEntityTypeId();
}
$entity_types = array_unique($entity_types);
foreach ($entity_types as $entity_type_id) {
$entity_type = \Drupal::entityManager()
->getDefinition($entity_type_id);
$this
->assertRaw('<h3>' . $entity_type
->getLabel() . '</h3>');
}
\Drupal::cache()
->set('uninstall_test', 'test_uninstall_page', Cache::PERMANENT);
$cached = \Drupal::cache()
->get('uninstall_test');
$this
->assertEqual($cached->data, 'test_uninstall_page', SafeMarkup::format('Cache entry found: @bin', array(
'@bin' => $cached->data,
)));
$this
->drupalPostForm(NULL, NULL, t('Uninstall'));
$this
->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
$this
->assertNoRaw('<label', 'The page does not have double escaped HTML tags.');
$cached = \Drupal::cache()
->get('uninstall_test');
$this
->assertFalse($cached, 'Cache entry not found');
$this
->drupalGet('admin/modules/uninstall/confirm');
$this
->assertText(t('The selected modules could not be uninstalled, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'Module uninstall confirmation form displays error message');
$this
->drupalGet('admin/modules/uninstall/confirm');
$this
->assertUrl('admin/modules/uninstall');
$this
->assertTitle(t('Uninstall') . ' | Drupal');
}
public function testFailedInstallStatus() {
$account = $this
->drupalCreateUser(array(
'administer modules',
));
$this
->drupalLogin($account);
$message = 'Exception thrown when installing module_installer_config_test with an invalid configuration file.';
try {
$this->container
->get('module_installer')
->install(array(
'module_installer_config_test',
));
$this
->fail($message);
} catch (EntityMalformedException $e) {
$this
->pass($message);
}
$this
->drupalGet('admin/modules/uninstall');
$this
->assertText('Module installer config test');
$edit['uninstall[module_installer_config_test]'] = TRUE;
$this
->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this
->drupalPostForm(NULL, NULL, t('Uninstall'));
$this
->assertText(t('The selected modules have been uninstalled.'));
$this
->assertNoText('Module installer config test');
}
}