DomainNavBlockTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Drupal\Tests\domain\Functional;
  3. use Drupal\Core\Session\AccountInterface;
  4. /**
  5. * Tests the domain navigation block.
  6. *
  7. * @group domain
  8. */
  9. class DomainNavBlockTest extends DomainTestBase {
  10. /**
  11. * Modules to enable.
  12. *
  13. * @var array
  14. */
  15. public static $modules = ['domain', 'node', 'block'];
  16. /**
  17. * Test domain navigation block.
  18. */
  19. public function testDomainNav() {
  20. // Create four new domains programmatically.
  21. $this->domainCreateTestDomains(4);
  22. $domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
  23. // Place the nav block.
  24. $block = $this->drupalPlaceBlock('domain_nav_block');
  25. // Let the anon user view the block.
  26. user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['use domain nav block']);
  27. // Load the homepage. All links should appear.
  28. $this->drupalGet('<front>');
  29. // Confirm domain links.
  30. foreach ($domains as $id => $domain) {
  31. $this->findLink($domain->label());
  32. }
  33. // Disable one of the domains. One link should not appear.
  34. $disabled = $domains['one_example_com'];
  35. $disabled->disable();
  36. // Load the homepage.
  37. $this->drupalGet('<front>');
  38. // Confirm domain links.
  39. foreach ($domains as $id => $domain) {
  40. if ($id != 'one_example_com') {
  41. $this->findLink($domain->label());
  42. }
  43. else {
  44. $this->assertNoRaw($domain->label());
  45. }
  46. }
  47. // Let the anon user view diabled domains. All links should appear.
  48. user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access inactive domains']);
  49. // Load the homepage.
  50. $this->drupalGet('<front>');
  51. // Confirm domain links.
  52. foreach ($domains as $id => $domain) {
  53. $this->findLink($domain->label());
  54. }
  55. // Now update the configuration and test again.
  56. $this->config('block.block.' . $block->id())
  57. ->set('settings.link_options', 'active')
  58. ->set('settings.link_label', 'hostname')
  59. ->save();
  60. // Load the the login page.
  61. $this->drupalGet('user/login');
  62. // Confirm domain links.
  63. foreach ($domains as $id => $domain) {
  64. $this->findLink($domain->getHostname());
  65. $this->assertRaw($domain->buildUrl('/user/login'));
  66. }
  67. // Now update the configuration and test again.
  68. $this->config('block.block.' . $block->id())
  69. ->set('settings.link_options', 'home')
  70. ->set('settings.link_theme', 'menu')
  71. ->set('settings.link_label', 'url')
  72. ->save();
  73. // Load the the login page.
  74. $this->drupalGet('user/login');
  75. // Confirm domain links.
  76. foreach ($domains as $id => $domain) {
  77. $this->findLink($domain->getPath());
  78. $this->assertRaw($domain->getPath());
  79. }
  80. }
  81. }