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