1<?php
2
3namespace Drupal\Tests\path\Functional;
4
5use Drupal\media\Entity\MediaType;
6
7/**
8 * Tests the path media form UI.
9 *
10 * @group path
11 */
12class PathMediaFormTest extends PathTestBase {
13
14  /**
15   * {@inheritdoc}
16   */
17  protected static $modules = ['media', 'media_test_source'];
18
19  /**
20   * {@inheritdoc}
21   */
22  protected $defaultTheme = 'classy';
23
24  /**
25   * {@inheritdoc}
26   */
27  protected function setUp(): void {
28    parent::setUp();
29
30    // Create test user and log in.
31    $web_user = $this->drupalCreateUser(['create media', 'create url aliases']);
32    $this->drupalLogin($web_user);
33  }
34
35  /**
36   * Tests the media form UI.
37   */
38  public function testMediaForm() {
39    $assert_session = $this->assertSession();
40
41    // Create media type.
42    $media_type_id = 'foo';
43    $media_type = MediaType::create([
44      'id' => $media_type_id,
45      'label' => $media_type_id,
46      'source' => 'test',
47      'source_configuration' => [],
48      'field_map' => [],
49      'new_revision' => FALSE,
50    ]);
51    $media_type->save();
52
53    $this->drupalGet('media/add/' . $media_type_id);
54
55    // Make sure we have a vertical tab fieldset and 'Path' field.
56    $assert_session->elementContains('css', '.form-type-vertical-tabs #edit-path-0 summary', 'URL alias');
57    $assert_session->fieldExists('path[0][alias]');
58
59    // Disable the 'Path' field for this content type.
60    \Drupal::service('entity_display.repository')->getFormDisplay('media', $media_type_id, 'default')
61      ->removeComponent('path')
62      ->save();
63
64    $this->drupalGet('media/add/' . $media_type_id);
65
66    // See if the whole fieldset is gone now.
67    $assert_session->elementNotExists('css', '.form-type-vertical-tabs #edit-path-0');
68    $assert_session->fieldNotExists('path[0][alias]');
69  }
70
71}
72