function MediaUiFunctionalTest::testMediaCollectionRoute

Same name in other branches
  1. 9 core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php \Drupal\Tests\media\Functional\MediaUiFunctionalTest::testMediaCollectionRoute()
  2. 8.9.x core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php \Drupal\Tests\media\Functional\MediaUiFunctionalTest::testMediaCollectionRoute()
  3. 10 core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php \Drupal\Tests\media\Functional\MediaUiFunctionalTest::testMediaCollectionRoute()

Tests the media collection route.

File

core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php, line 247

Class

MediaUiFunctionalTest
Ensures that media UI works correctly.

Namespace

Drupal\Tests\media\Functional

Code

public function testMediaCollectionRoute() : void {
    
    /** @var \Drupal\Core\Entity\EntityStorageInterface $media_storage */
    $media_storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('media');
    $this->container
        ->get('module_installer')
        ->uninstall([
        'views',
    ]);
    // Create a media type and media item.
    $media_type = $this->createMediaType('test');
    $media = $media_storage->create([
        'bundle' => $media_type->id(),
        'name' => 'Unnamed',
    ]);
    $media->save();
    $this->drupalGet($media->toUrl('collection'));
    $assert_session = $this->assertSession();
    // Media list table exists.
    $assert_session->elementExists('css', 'th:contains("Media Name")');
    $assert_session->elementExists('css', 'th:contains("Type")');
    $assert_session->elementExists('css', 'th:contains("Operations")');
    // Media item is present.
    $assert_session->elementExists('css', 'td:contains("Unnamed")');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.