You are here

public function BundleFormAlterTest::testGroupContentAjax in Organic groups 8

Tests AJAX behavior for selecting group content entity types and bundles.

File

og_ui/tests/src/Functional/BundleFormAlterTest.php, line 110

Class

BundleFormAlterTest
Test making a bundle a group and a group content.

Namespace

Drupal\Tests\og_ui\Functional

Code

public function testGroupContentAjax() {

  // Create two group bundles of different entity types.
  NodeType::create([
    'name' => 'group node',
    'type' => 'group',
  ])
    ->save();
  Og::groupTypeManager()
    ->addGroup('node', 'group');
  Og::groupTypeManager()
    ->addGroup('entity_test', 'entity_test');

  // BrowserTestBase doesn't support JavaScript yet. Replace the following
  // unit test with a functional test once JavaScript support is added.
  // @see https://www.drupal.org/node/2469713
  $form = [];
  $form_state = new FormState();

  // Set the form state as if the 'entity_test' option was chosen with AJAX.
  $form_state
    ->setValue('og_target_type', 'entity_test');
  $entity = $this->entityTypeManager
    ->getStorage('node_type')
    ->create([]);
  (new BundleFormAlter($entity))
    ->formAlter($form, $form_state);

  // Check that the target bundles are set to the test entity bundle.
  $this
    ->assertEquals([
    'entity_test' => 'Entity Test Bundle',
  ], $form['og']['og_target_bundles']['#options']);
}