class WorkspacesMediaLibraryIntegrationTest

Tests the Media library entity reference widget in a workspace.

@group workspaces

Hierarchy

Expanded class hierarchy of WorkspacesMediaLibraryIntegrationTest

File

core/modules/workspaces/tests/src/FunctionalJavascript/WorkspacesMediaLibraryIntegrationTest.php, line 16

Namespace

Drupal\Tests\workspaces\FunctionalJavascript
View source
class WorkspacesMediaLibraryIntegrationTest extends EntityReferenceWidgetTest {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'workspaces',
    ];
    
    /**
     * An array of test methods that are not relevant for workspaces.
     */
    const SKIP_METHODS = [
        // This test does not assert anything that can be workspace-specific.
'testFocusNotAppliedWithoutSelectionChange',
        // This test does not assert anything that can be workspace-specific.
'testRequiredMediaField',
        // This test tries to edit an entity in Live after it has been edited in a
        // workspace, which is not currently possible.
'testWidgetPreview',
    ];
    
    /**
     * {@inheritdoc}
     */
    public function setUp() : void {
        if (in_array($this->name(), static::SKIP_METHODS, TRUE)) {
            $this->markTestSkipped('Irrelevant for this test');
        }
        parent::setUp();
        // Ensure that all the test methods are executed in the context of a
        // workspace.
        $stage = Workspace::load('stage');
        \Drupal::service('workspaces.manager')->setActiveWorkspace($stage);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function drupalCreateUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []) : UserInterface|false {
        // Ensure that users and roles are managed outside a workspace context.
        return \Drupal::service('workspaces.manager')->executeOutsideWorkspace(function () use ($permissions, $name, $admin, $values) {
            $permissions = array_merge($permissions, [
                'view any workspace',
            ]);
            return parent::drupalCreateUser($permissions, $name, $admin, $values);
        });
    }

}

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