DomainFormsTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Drupal\Tests\domain\Functional;
  3. /**
  4. * Tests the domain record form interface.
  5. *
  6. * @group domain
  7. */
  8. class DomainFormsTest extends DomainTestBase {
  9. /**
  10. * Create, edit and delete a domain via the user interface.
  11. */
  12. public function testDomainInterface() {
  13. $this->admin_user = $this->drupalCreateUser(['administer domains', 'create domains']);
  14. $this->drupalLogin($this->admin_user);
  15. $storage = \Drupal::entityTypeManager()->getStorage('domain');
  16. // No domains should exist.
  17. $this->domainTableIsEmpty();
  18. // Visit the main domain administration page.
  19. $this->drupalGet('admin/config/domain');
  20. // Check for the add message.
  21. if (substr_count(\Drupal::VERSION, '8.5') > 0) {
  22. $this->assertText('There is no Domain record yet.', 'Text for no domains found.');
  23. }
  24. else {
  25. $this->assertText('There are no domain record entities yet.', 'Text for no domains found.');
  26. }
  27. // Visit the add domain administration page.
  28. $this->drupalGet('admin/config/domain/add');
  29. // Make a POST request on admin/config/domain/add.
  30. $edit = $this->domainPostValues();
  31. $this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
  32. // Did it save correctly?
  33. $default_id = $storage->loadDefaultId();
  34. $this->assertTrue(!empty($default_id), 'Domain record saved via form.');
  35. // Does it load correctly?
  36. $storage->resetCache([$default_id]);
  37. $new_domain = $storage->load($default_id);
  38. $this->assertTrue($new_domain->id() == $default_id, 'Domain loaded properly.');
  39. // Has a UUID been set?
  40. $this->assertTrue(!empty($new_domain->uuid()), 'Entity UUID set properly.');
  41. // Visit the edit domain administration page.
  42. $editUrl = 'admin/config/domain/edit/' . $new_domain->id();
  43. $this->drupalGet($editUrl);
  44. // Update the record.
  45. $edit = [];
  46. $edit['name'] = 'Foo';
  47. $edit['validate_url'] = 0;
  48. $this->drupalPostForm($editUrl, $edit, 'Save');
  49. // Check that the update succeeded.
  50. $storage->resetCache([$default_id]);
  51. $domain = $storage->load($default_id);
  52. $this->assertTrue($domain->label() == 'Foo', 'Domain record updated via form.');
  53. // Visit the delete domain administration page.
  54. $deleteUrl = 'admin/config/domain/delete/' . $new_domain->id();
  55. $this->drupalGet($deleteUrl);
  56. // Delete the record.
  57. $this->drupalPostForm($deleteUrl, [], 'Delete');
  58. $storage->resetCache([$default_id]);
  59. $domain = $storage->load($default_id);
  60. $this->assertTrue(empty($domain), 'Domain record deleted.');
  61. // No domains should exist.
  62. $this->domainTableIsEmpty();
  63. }
  64. }