You are here

public function EntityDisplayTest::testGetDisplayModeOptions in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testGetDisplayModeOptions()

Test getDisplayModeOptions().

File

core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php, line 489

Class

EntityDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\Tests\field_ui\Kernel

Code

public function testGetDisplayModeOptions() {
  NodeType::create([
    'type' => 'article',
  ])
    ->save();
  EntityViewDisplay::create([
    'targetEntityType' => 'node',
    'bundle' => 'article',
    'mode' => 'default',
  ])
    ->setStatus(TRUE)
    ->save();
  $display_teaser = EntityViewDisplay::create([
    'targetEntityType' => 'node',
    'bundle' => 'article',
    'mode' => 'teaser',
  ]);
  $display_teaser
    ->save();
  EntityFormDisplay::create([
    'targetEntityType' => 'user',
    'bundle' => 'user',
    'mode' => 'default',
  ])
    ->setStatus(TRUE)
    ->save();
  $form_display_teaser = EntityFormDisplay::create([
    'targetEntityType' => 'user',
    'bundle' => 'user',
    'mode' => 'register',
  ]);
  $form_display_teaser
    ->save();

  // Test getViewModeOptionsByBundle().
  $view_modes = \Drupal::service('entity_display.repository')
    ->getViewModeOptionsByBundle('node', 'article');
  $this
    ->assertEqual($view_modes, [
    'default' => 'Default',
  ]);
  $display_teaser
    ->setStatus(TRUE)
    ->save();
  $view_modes = \Drupal::service('entity_display.repository')
    ->getViewModeOptionsByBundle('node', 'article');
  $this
    ->assertEqual($view_modes, [
    'default' => 'Default',
    'teaser' => 'Teaser',
  ]);

  // Test getFormModeOptionsByBundle().
  $form_modes = \Drupal::service('entity_display.repository')
    ->getFormModeOptionsByBundle('user', 'user');
  $this
    ->assertEqual($form_modes, [
    'default' => 'Default',
  ]);
  $form_display_teaser
    ->setStatus(TRUE)
    ->save();
  $form_modes = \Drupal::service('entity_display.repository')
    ->getFormModeOptionsByBundle('user', 'user');
  $this
    ->assertEqual($form_modes, [
    'default' => 'Default',
    'register' => 'Register',
  ]);
}