MediaTypeCreationTest.php

Same filename in this branch
  1. 11.x core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
Same filename in other branches
  1. 9 core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
  2. 9 core/modules/media/tests/src/Functional/MediaTypeCreationTest.php
  3. 8.9.x core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
  4. 8.9.x core/modules/media/tests/src/Functional/MediaTypeCreationTest.php
  5. 10 core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
  6. 10 core/modules/media/tests/src/Functional/MediaTypeCreationTest.php

Namespace

Drupal\Tests\media\Functional

File

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

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\media\Functional;

use Drupal\media\Entity\MediaType;
use Drupal\TestTools\Random;

/**
 * Ensures that media UI works correctly without JavaScript.
 *
 * @group media
 */
class MediaTypeCreationTest extends MediaFunctionalTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'media_test_source',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests the media type creation form with only the mandatory options.
     *
     * @dataProvider providerMediaTypeCreationForm
     */
    public function testMediaTypeCreationForm($button_label, $address, $machine_name) : void {
        $this->drupalGet('/admin/structure/media/add');
        $this->assertSession()
            ->statusCodeEquals(200);
        $this->assertSession()
            ->fieldExists('label')
            ->setValue($this->randomString());
        $this->assertSession()
            ->fieldExists('id')
            ->setValue($machine_name);
        $this->assertSession()
            ->selectExists('source')
            ->selectOption('test');
        $this->assertSession()
            ->buttonExists($button_label)
            ->press();
        $this->assertSession()
            ->statusCodeEquals(200);
        $this->assertSession()
            ->fieldValueEquals('Test config value', 'This is default value.');
        $this->assertSession()
            ->buttonExists($button_label)
            ->press();
        $this->assertSession()
            ->statusCodeEquals(200);
        $this->assertSession()
            ->addressEquals($address);
        $this->assertInstanceOf(MediaType::class, MediaType::load($machine_name));
    }
    
    /**
     * Data provider for testMediaTypeCreationForm().
     */
    public static function providerMediaTypeCreationForm() {
        $machine_name = Random::machineName();
        return [
            [
                'Save',
                'admin/structure/media',
                $machine_name,
            ],
            [
                'Save and manage fields',
                'admin/structure/media/manage/' . $machine_name . '/fields',
                $machine_name,
            ],
        ];
    }

}

Classes

Title Deprecated Summary
MediaTypeCreationTest Ensures that media UI works correctly without JavaScript.

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