You are here

public function MediaLibraryUpdateCheckboxClassesTest::testAddNonPrefixedClasses in Drupal 8

Tests that non js prefixes are added to checkboxes in the media view.

See also

media_library_post_update_update_8001_checkbox_classes()

File

core/modules/media_library/tests/src/Functional/Update/MediaLibraryUpdateCheckboxClassesTest.php, line 32

Class

MediaLibraryUpdateCheckboxClassesTest
Tests the media library module updates views checkbox classes.

Namespace

Drupal\Tests\media_library\Functional\Update

Code

public function testAddNonPrefixedClasses() {
  $view = Views::getView('media_library');
  $display_items = [
    [
      'display_id' => 'default',
      'option' => 'element_class',
      'field' => 'media_bulk_form',
    ],
    [
      'display_id' => 'page',
      'option' => 'element_class',
      'field' => 'media_bulk_form',
    ],
    [
      'display_id' => 'widget',
      'option' => 'element_wrapper_class',
      'field' => 'media_library_select_form',
    ],
    [
      'display_id' => 'widget_table',
      'option' => 'element_wrapper_class',
      'field' => 'media_library_select_form',
    ],
  ];
  foreach ($display_items as $item) {
    $display_id = $item['display_id'];
    $option = $item['option'];
    $field = $item['field'];
    $display = $view->storage
      ->getDisplay($display_id);
    $classes_string = $display['display_options']['fields'][$field][$option];
    $classes = preg_split('/\\s+/', $classes_string);
    $this
      ->assertContains('js-click-to-select-checkbox', $classes);
    $this
      ->assertNotContains('media-library-item__click-to-select-checkbox', $classes);
  }
  $this
    ->runUpdates();
  $view = Views::getView('media_library');
  foreach ($display_items as $item) {
    $display_id = $item['display_id'];
    $option = $item['option'];
    $field = $item['field'];
    $display = $view->storage
      ->getDisplay($display_id);
    $classes_string = $display['display_options']['fields'][$field][$option];
    $classes = preg_split('/\\s+/', $classes_string);
    $this
      ->assertContains('js-click-to-select-checkbox', $classes);
    $this
      ->assertContains('media-library-item__click-to-select-checkbox', $classes, "Class 'media-library-item__click-to-select-checkbox' not found in display: {$display_id}");
  }
}