DomainActionsTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Drupal\Tests\domain\Functional;
  3. /**
  4. * Tests the domain record actions.
  5. *
  6. * @group domain
  7. */
  8. class DomainActionsTest extends DomainTestBase {
  9. /**
  10. * Tests bulk actions through the domain overview page.
  11. */
  12. public function testDomainActions() {
  13. $this->admin_user = $this->drupalCreateUser(['administer domains', 'access administration pages']);
  14. $this->drupalLogin($this->admin_user);
  15. $path = 'admin/config/domain';
  16. // Create test domains.
  17. $this->domainCreateTestDomains(4);
  18. // Visit the domain overview administration page.
  19. $this->drupalGet($path);
  20. $this->assertResponse(200);
  21. // Test the domains.
  22. $storage = \Drupal::entityTypeManager()->getStorage('domain');
  23. $domains = $storage->loadMultiple();
  24. $this->assertTrue(count($domains) == 4, 'Four domain records found.');
  25. // Check the default domain.
  26. $default = $storage->loadDefaultId();
  27. $key = 'example_com';
  28. $this->assertTrue($default == $key, 'Default domain set correctly.');
  29. // Test some text on the page.
  30. foreach ($domains as $domain) {
  31. $name = $domain->label();
  32. $this->assertText($name, 'Name found properly.');
  33. }
  34. // Test the list of actions.
  35. $actions = ['delete', 'disable', 'default'];
  36. foreach ($actions as $action) {
  37. $this->assertRaw("/domain/{$action}/", 'Actions found properly.');
  38. }
  39. // Check that all domains are active.
  40. $this->assertNoRaw('Inactive', 'Inactive domain not found.');
  41. // Disable a domain and test the enable link.
  42. $this->clickLink('Disable', 0);
  43. $this->assertRaw('Inactive', 'Inactive domain found.');
  44. // Visit the domain overview administration page to clear cache.
  45. $this->drupalGet($path);
  46. $this->assertResponse(200);
  47. foreach ($storage->loadMultiple() as $domain) {
  48. if ($domain->id() == 'one_example_com') {
  49. $this->assertEmpty($domain->status(), 'One domain inactive.');
  50. }
  51. else {
  52. $this->assertNotEmpty($domain->status(), 'Other domains active.');
  53. }
  54. }
  55. // Test the list of actions.
  56. $actions = ['enable', 'delete', 'disable', 'default'];
  57. foreach ($actions as $action) {
  58. $this->assertRaw("/domain/{$action}/", 'Actions found properly.');
  59. }
  60. // Re-enable the domain.
  61. $this->clickLink('Enable', 0);
  62. $this->assertNoRaw('Inactive', 'Inactive domain not found.');
  63. // Visit the domain overview administration page to clear cache.
  64. $this->drupalGet($path);
  65. $this->assertResponse(200);
  66. foreach ($storage->loadMultiple() as $domain) {
  67. $this->assertNotEmpty($domain->status(), 'All domains active.');
  68. }
  69. // Set a new default domain.
  70. $this->clickLink('Make default', 0);
  71. // Visit the domain overview administration page to clear cache.
  72. $this->drupalGet($path);
  73. $this->assertResponse(200);
  74. // Check the default domain.
  75. $storage->resetCache();
  76. $default = $storage->loadDefaultId();
  77. $key = 'one_example_com';
  78. $this->assertTrue($default == $key, 'Default domain set correctly.');
  79. }
  80. }