MediaContextualLinksTest.php

Same filename in other branches
  1. 9 core/modules/media/tests/src/Functional/MediaContextualLinksTest.php
  2. 10 core/modules/media/tests/src/Functional/MediaContextualLinksTest.php
  3. 11.x core/modules/media/tests/src/Functional/MediaContextualLinksTest.php

Namespace

Drupal\Tests\media\Functional

File

core/modules/media/tests/src/Functional/MediaContextualLinksTest.php

View source
<?php

namespace Drupal\Tests\media\Functional;

use Drupal\media\Entity\Media;

/**
 * Tests views contextual links on media items.
 *
 * @group media
 */
class MediaContextualLinksTest extends MediaFunctionalTestBase {
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'contextual',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests contextual links.
     */
    public function testMediaContextualLinks() {
        \Drupal::configFactory()->getEditable('media.settings')
            ->set('standalone_url', TRUE)
            ->save(TRUE);
        $this->container
            ->get('router.builder')
            ->rebuild();
        // Create a media type.
        $mediaType = $this->createMediaType('test');
        // Create a media item.
        $media = Media::create([
            'bundle' => $mediaType->id(),
            'name' => 'Unnamed',
        ]);
        $media->save();
        $user = $this->drupalCreateUser([
            'administer media',
            'access contextual links',
        ]);
        $this->drupalLogin($user);
        $this->drupalGet('media/' . $media->id());
        $this->assertSession()
            ->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'media:media=' . $media->id() . ':');
    }

}

Classes

Title Deprecated Summary
MediaContextualLinksTest Tests views contextual links on media items.

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