DomainListWeightTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Drupal\Tests\domain\Functional;
  3. /**
  4. * Tests behavior for the weight element of the domain list builder.
  5. *
  6. * @group domain
  7. */
  8. class DomainListWeightTest extends DomainTestBase {
  9. /**
  10. * Modules to enable.
  11. *
  12. * @var array
  13. */
  14. public static $modules = ['domain', 'user'];
  15. /**
  16. * {@inheritdoc}
  17. */
  18. protected function setUp() {
  19. parent::setUp();
  20. // Create 60 domains. We paginate at 50.
  21. $this->domainCreateTestDomains(60);
  22. }
  23. /**
  24. * Basic test setup.
  25. */
  26. public function testDomainWeight() {
  27. // Test the default sort values. Should be 1 to 60.
  28. $domains = $this->getDomainsSorted();
  29. $i = 1;
  30. foreach ($domains as $domain) {
  31. $this->assert($domain->getWeight() == $i, 'Weight set to ' . $i);
  32. $i++;
  33. }
  34. // The last domain should be test59_example_com.
  35. $this->assert($domain->id() == 'test59_example_com', 'Last domain is test59');
  36. $domains_old = $domains;
  37. $admin = $this->drupalCreateUser([
  38. 'bypass node access',
  39. 'administer content types',
  40. 'administer node fields',
  41. 'administer node display',
  42. 'administer domains',
  43. ]);
  44. $this->drupalLogin($admin);
  45. $this->drupalGet('admin/config/domain');
  46. $this->assertSession()->statusCodeEquals(200);
  47. // Set one weight to 61.
  48. $locator = 'edit-domains-one-example-com-weight';
  49. $this->fillField($locator, 61);
  50. // Save the form.
  51. $this->pressButton('edit-submit');
  52. $domains = $this->getDomainsSorted();
  53. $i = 1;
  54. foreach ($domains as $domain) {
  55. // Weights should be the same one page 1 except for the one we changed.
  56. if ($domain->id() == 'one_example_com') {
  57. $this->assert($domain->getWeight() == 61, 'Weight set to 61 ' . $domain->getWeight());
  58. }
  59. else {
  60. $this->assert($domain->getWeight() == $domains_old[$domain->id()]->getWeight() . 'Weights unchanged');
  61. }
  62. $i++;
  63. }
  64. // The last domain should be one_example_com.
  65. $this->assert($domain->id() == 'one_example_com', 'Last domain is one');
  66. // Go to page two.
  67. $this->clickLink('Next');
  68. $this->assertSession()->statusCodeEquals(200);
  69. // Set one weight to 2.
  70. $locator = 'edit-domains-one-example-com-weight';
  71. $this->fillField($locator, 2);
  72. // Save the form.
  73. $this->pressButton('edit-submit');
  74. $this->drupalGet('admin/config/domain');
  75. $this->assertSession()->statusCodeEquals(200);
  76. // Go to page two.
  77. $this->clickLink('Next');
  78. $this->assertSession()->statusCodeEquals(200);
  79. // Check the domain sort order.
  80. $domains = $this->getDomainsSorted();
  81. $i = 1;
  82. foreach ($domains as $domain) {
  83. if ($domain->id() == 'one_example_com') {
  84. $this->assert($domain->getWeight() == 2, 'Weight set to 2');
  85. }
  86. else {
  87. $this->assert($domain->getWeight() == $domains_old[$domain->id()]->getWeight() . 'Weights unchanged');
  88. }
  89. }
  90. // The last domain should be test59_example_com.
  91. $this->assert($domain->id() == 'test59_example_com', 'Last domain is test59' . $domain->id());
  92. }
  93. }