UninstallTest.php in Node Option Premium 8
File
tests/src/Functional/UninstallTest.php
View source
<?php
namespace Drupal\Tests\nopremium\Functional;
use Drupal\Tests\BrowserTestBase;
class UninstallTest extends BrowserTestBase {
public static $modules = [
'nopremium',
];
protected $defaultTheme = 'stark';
public $moduleHandler;
public $moduleInstaller;
protected function setUp() {
parent::setUp();
$this->moduleHandler = $this->container
->get('module_handler');
$this->moduleInstaller = $this->container
->get('module_installer');
}
protected function reloadServices() {
$this
->rebuildContainer();
$this->moduleHandler = $this->container
->get('module_handler');
$this->moduleInstaller = $this->container
->get('module_installer');
}
public function testUninstall() {
$this
->assertTrue($this->moduleHandler
->moduleExists('nopremium'));
$this
->drupalCreateContentType([
'type' => 'foo',
]);
$fields = $this->container
->get('entity_field.manager')
->getFieldDefinitions('node', 'foo');
$fields['premium']
->getConfig('foo')
->setDefaultValue(TRUE)
->save();
$config_id = 'core.base_field_override.node.foo.premium';
$this
->assertTrue($this->container
->get('config.storage')
->exists($config_id), "Config {$config_id} has been created.");
$this->moduleInstaller
->uninstall([
'nopremium',
]);
$this
->assertFalse($this->moduleHandler
->moduleExists('nopremium'));
$this
->assertFalse($this->container
->get('config.storage')
->exists($config_id), "Config {$config_id} no longer exists.");
}
public function testReinstall() {
$this->moduleInstaller
->uninstall([
'nopremium',
]);
$this
->assertTrue($this->moduleInstaller
->install([
'nopremium',
]));
$this
->reloadServices();
$this
->assertTrue($this->moduleHandler
->moduleExists('nopremium'));
}
}