DomainCheckResponseTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Drupal\Tests\domain\Functional;
  3. /**
  4. * Tests the domain record response check.
  5. *
  6. * @group domain
  7. */
  8. class DomainCheckResponseTest extends DomainTestBase {
  9. /**
  10. * Tests that a domain responds as expected.
  11. */
  12. public function testDomainCheckResponse() {
  13. $this->admin_user = $this->drupalCreateUser(['administer domains', 'create domains']);
  14. $this->drupalLogin($this->admin_user);
  15. $storage = \Drupal::entityTypeManager()->getStorage('domain');
  16. // Make a POST request on admin/config/domain/add.
  17. $edit = $this->domainPostValues();
  18. $this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
  19. // Did it save correctly?
  20. $this->assertNoRaw('The server request to');
  21. $domains = $storage->loadMultiple();
  22. $this->assertTrue(count($domains) == 1, 'Domain record saved via form.');
  23. // Make an invalid POST request on admin/config/domain/add.
  24. $edit = $this->domainPostValues();
  25. // Set a hostname that does not exist on the server.
  26. $edit['hostname'] = 'foo.bar';
  27. $edit['id'] = $storage->createMachineName($edit['hostname']);
  28. $edit['validate_url'] = 1;
  29. try {
  30. $this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
  31. }
  32. catch (\Exception $e) {
  33. // Ensure no test errors.
  34. }
  35. // The domain should not save.
  36. $this->assertRaw('The server request to');
  37. $domains = $storage->loadMultiple();
  38. $this->assertTrue(count($domains) == 1, 'Domain record not saved via form.');
  39. // Bypass the check.
  40. $edit['validate_url'] = 0;
  41. $this->drupalPostForm('admin/config/domain/add', $edit, 'Save');
  42. // The domain should save.
  43. $this->assertNoRaw('The server request to');
  44. $domains = $storage->loadMultiple();
  45. $this->assertTrue(count($domains) == 2, 'Domain record saved via form.');
  46. }
  47. }