View source
<?php
namespace Drupal\Tests\features_ui\Functional;
use Drupal\features\FeaturesBundleInterface;
use Drupal\Tests\BrowserTestBase;
class FeaturesBundleUiTest extends BrowserTestBase {
protected $strictConfigSchema = FALSE;
protected $defaultTheme = 'stark';
protected static $modules = [
'block',
'features',
'features_ui',
];
protected $bundleStorage;
public function setUp() : void {
parent::setUp();
$this->bundleStorage = \Drupal::entityTypeManager()
->getStorage('features_bundle');
$admin_user = $this
->createUser([
'administer site configuration',
'export configuration',
'administer modules',
]);
$this
->drupalLogin($admin_user);
$this
->drupalPlaceBlock('local_actions_block');
}
protected function defaultBundle() {
return $this->bundleStorage
->load(FeaturesBundleInterface::DEFAULT_BUNDLE);
}
protected function removeAssignment($method_id) {
$bundle = $this
->defaultBundle();
$assignments = $bundle
->get('assignments');
unset($assignments[$method_id]);
$bundle
->set('assignments', $assignments);
$bundle
->save();
}
public function testAssignmentConfigure() {
$settings = $this
->defaultBundle()
->getAssignmentSettings('exclude');
$this
->assertTrue(isset($settings['types']['config']['features_bundle']), 'Excluding features_bundle');
$this
->assertFalse(isset($settings['types']['config']['system_simple']), 'Not excluding system_simple');
$this
->assertFalse(isset($settings['types']['config']['user_role']), 'Not excluding user_role');
$this
->assertTrue($settings['curated'], 'Excluding curated items');
$this
->assertTrue($settings['module']['namespace'], 'Excluding by namespace');
$this
->drupalGet('admin/config/development/features/bundle/_exclude/default');
$this
->assertFieldChecked('edit-types-config-features-bundle', 'features_bundle is checked');
$this
->assertNoFieldChecked('edit-types-config-system-simple', 'system_simple is not checked');
$this
->assertNoFieldChecked('edit-types-config-user-role', 'user_role is not checked');
$this
->assertFieldChecked('edit-curated', 'curated is checked');
$this
->assertFieldChecked('edit-module-namespace', 'namespace is checked');
$this
->drupalPostForm(NULL, [
'types[config][system_simple]' => TRUE,
'types[config][user_role]' => FALSE,
'curated' => TRUE,
'module[namespace]' => FALSE,
], 'Save settings');
$this
->drupalGet('admin/config/development/features/bundle/_exclude/default');
$this
->assertFieldChecked('edit-types-config-features-bundle', 'Saved, features_bundle is checked');
$this
->assertFieldChecked('edit-types-config-system-simple', 'Saved, system_simple is checked');
$this
->assertNoFieldChecked('edit-types-config-user-role', 'Saved, user_role is not checked');
$this
->assertFieldChecked('edit-curated', 'Saved, curated is checked');
$this
->assertNoFieldChecked('edit-module-namespace', 'Saved, namespace is not checked');
$settings = $this
->defaultBundle()
->getAssignmentSettings('exclude');
$this
->assertTrue(isset($settings['types']['config']['features_bundle']), 'Saved, excluding features_bundle');
$this
->assertTrue(isset($settings['types']['config']['system_simple']), 'Saved, excluding system_simple');
$this
->assertFalse(isset($settings['types']['config']['user_role']), 'Saved, not excluding user_role');
$this
->assertTrue($settings['curated'], 'Saved, excluding curated items');
$this
->assertFalse($settings['module']['namespace'], 'Saved, not excluding by namespace');
}
public function testNewAssignmentConfigure() {
$this
->removeAssignment('exclude');
$all_settings = $this
->defaultBundle()
->getAssignmentSettings();
$this
->assertFalse(isset($all_settings['exclude']), 'Exclude plugin is unknown');
$settings = $this
->defaultBundle()
->getAssignmentSettings('exclude');
$this
->assertFalse($settings['enabled'], 'Disabled exclude plugin');
$this
->assertFalse(isset($settings['types']['config']['features_bundle']), 'Not excluding features_bundle');
$this
->assertFalse(isset($settings['types']['config']['system_simple']), 'Not excluding system_simple');
$this
->assertFalse(isset($settings['types']['config']['user_role']), 'Not excluding user_role');
$this
->assertFalse($settings['curated'], 'Not excluding curated items');
$this
->assertFalse($settings['module']['namespace'], 'Not excluding by namespace');
$this
->drupalGet('admin/config/development/features/bundle/_exclude/default');
$this
->assertNoFieldChecked('edit-types-config-features-bundle', 'features_bundle is not checked');
$this
->assertNoFieldChecked('edit-types-config-system-simple', 'system_simple is not checked');
$this
->assertNoFieldChecked('edit-types-config-user-role', 'user_role is not checked');
$this
->assertNoFieldChecked('edit-curated', 'curated is not checked');
$this
->assertNoFieldChecked('edit-module-namespace', 'namespace is not checked');
$this
->drupalGet('admin/config/development/features/bundle');
$this
->assertNoFieldChecked('edit-enabled-exclude', 'Exclude disabled');
$this
->drupalPostForm(NULL, [
'enabled[exclude]' => TRUE,
], 'Save settings');
$this
->assertFieldChecked('edit-enabled-exclude', 'Exclude enabled');
$settings = $this
->defaultBundle()
->getAssignmentSettings('exclude');
$this
->assertTrue($settings['enabled'], 'Enabled exclude plugin');
$this
->assertFalse(isset($settings['types']['config']['features_bundle']), 'Not excluding features_bundle');
$this
->assertFalse(isset($settings['types']['config']['system_simple']), 'Not excluding system_simple');
$this
->assertFalse(isset($settings['types']['config']['user_role']), 'Not excluding user_role');
$this
->assertFalse($settings['curated'], 'Not excluding curated items');
$this
->assertFalse($settings['module']['namespace'], 'Not excluding by namespace');
$this
->drupalGet('admin/config/development/features');
$this
->drupalPostForm('admin/config/development/features/bundle/_exclude/default', [
'types[config][system_simple]' => TRUE,
'types[config][user_role]' => FALSE,
'curated' => TRUE,
'module[namespace]' => FALSE,
], 'Save settings');
$this
->drupalGet('admin/config/development/features/bundle/_exclude/default');
$this
->assertNoFieldChecked('edit-types-config-features-bundle', 'Saved, features_bundle is not checked');
$this
->assertFieldChecked('edit-types-config-system-simple', 'Saved, system_simple is checked');
$this
->assertNoFieldChecked('edit-types-config-user-role', 'Saved, user_role is not checked');
$this
->assertFieldChecked('edit-curated', 'Saved, curated is checked');
$this
->assertNoFieldChecked('edit-module-namespace', 'Saved, namespace is not checked');
$settings = $this
->defaultBundle()
->getAssignmentSettings('exclude');
$this
->assertFalse(isset($settings['types']['config']['features_bundle']), 'Saved, not excluding features_bundle');
$this
->assertTrue(isset($settings['types']['config']['system_simple']), 'Saved, excluding system_simple');
$this
->assertFalse(isset($settings['types']['config']['user_role']), 'Saved, not excluding user_role');
$this
->assertTrue($settings['curated'], 'Saved, excluding curated items');
$this
->assertFalse($settings['module']['namespace'], 'Saved, not excluding by namespace');
}
}