You are here

public function FeaturesBundleUiTest::testNewAssignmentConfigure in Features 8.3

Same name and namespace in other branches
  1. 8.4 modules/features_ui/tests/src/Functional/FeaturesBundleUiTest.php \Drupal\Tests\features_ui\Functional\FeaturesBundleUiTest::testNewAssignmentConfigure()

Tests configuring an assignment that didn't exist before.

File

modules/features_ui/tests/src/Functional/FeaturesBundleUiTest.php, line 128

Class

FeaturesBundleUiTest
Tests configuring bundles.

Namespace

Drupal\Tests\features_ui\Functional

Code

public function testNewAssignmentConfigure() {
  $this
    ->removeAssignment('exclude');

  // Is it really removed?
  $all_settings = $this
    ->defaultBundle()
    ->getAssignmentSettings();
  $this
    ->assertFalse(isset($all_settings['exclude']), 'Exclude plugin is unknown');

  // Can still get settings.
  $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');

  // Can we visit the config page with no settings?
  $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');

  // Can we enable the method?
  $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');

  // Check new settings.
  $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');

  // Can we run assignment with no settings?
  $this
    ->drupalGet('admin/config/development/features');

  // Can we configure the method?
  $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');

  // Check form results.
  $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');

  // Check final values.
  $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');
}