PathMediaFormTest.php 1.6 KB

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