You are here

public function EntityDisplayTest::testGetDisplayModeOptions in Zircon Profile 8

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

Test getDisplayModeOptions().

File

core/modules/field_ui/src/Tests/EntityDisplayTest.php, line 434
Contains \Drupal\field_ui\Tests\EntityDisplayTest.

Class

EntityDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\field_ui\Tests

Code

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

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

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