You are here

public function EntityDisplayTest::testGetDisplayModeOptions in Drupal 10

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

Tests getDisplayModeOptions().

File

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

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
    ->assertEquals([
    'default' => 'Default',
  ], $view_modes);
  $display_teaser
    ->setStatus(TRUE)
    ->save();
  $view_modes = \Drupal::service('entity_display.repository')
    ->getViewModeOptionsByBundle('node', 'article');
  $this
    ->assertEquals([
    'default' => 'Default',
    'teaser' => 'Teaser',
  ], $view_modes);

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