DomainVariableSchemeTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Drupal\Tests\domain\Kernel;
  3. use Drupal\KernelTests\KernelTestBase;
  4. use Drupal\Tests\domain\Traits\DomainTestTrait;
  5. /**
  6. * Tests the ability to set a variable scheme on a domain.
  7. *
  8. * @group domain
  9. */
  10. class DomainVariableSchemeTest extends KernelTestBase {
  11. use DomainTestTrait;
  12. /**
  13. * Modules to enable.
  14. *
  15. * @var array
  16. */
  17. public static $modules = ['domain'];
  18. /**
  19. * Domain id key.
  20. *
  21. * @var string
  22. */
  23. public $key = 'example_com';
  24. /**
  25. * The Domain storage handler service.
  26. *
  27. * @var \Drupal\domain\DomainStorageInterface
  28. */
  29. public $domainStorage;
  30. /**
  31. * Test setup.
  32. */
  33. protected function setUp() {
  34. parent::setUp();
  35. // Create a domain.
  36. $this->domainCreateTestDomains();
  37. // Get the services.
  38. $this->domainStorage = \Drupal::entityTypeManager()->getStorage('domain');
  39. }
  40. /**
  41. * Tests domain loading.
  42. */
  43. public function testDomainScheme() {
  44. // Set our testing parameters.
  45. $default_scheme = \Drupal::request()->getScheme();
  46. $alt_scheme = ($default_scheme == 'https') ? 'http' : 'https';
  47. $add_suffix = FALSE;
  48. // Our created domain should have a scheme that matches the request.
  49. $domain = $this->domainStorage->load($this->key);
  50. $this->assertTrue($domain->getScheme($add_suffix) == $default_scheme);
  51. // Swtich the scheme and see if that works.
  52. $domain->set('scheme', $alt_scheme);
  53. $domain->save();
  54. $domain = $this->domainStorage->load($this->key);
  55. $this->assertTrue($domain->getScheme($add_suffix) == $alt_scheme);
  56. // Set the scheme to variable, and that should match the default.
  57. $domain->set('scheme', 'variable');
  58. $domain->save();
  59. $this->assertTrue($domain->getScheme($add_suffix) == $default_scheme);
  60. }
  61. }