DomainAccessAllAffiliatesTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Drupal\Tests\domain_access\Functional;
  3. use Drupal\Tests\domain\Functional\DomainTestBase;
  4. /**
  5. * Tests the domain access entity reference field type.
  6. *
  7. * @group domain_access
  8. */
  9. class DomainAccessAllAffiliatesTest extends DomainTestBase {
  10. /**
  11. * Modules to enable.
  12. *
  13. * @var array
  14. */
  15. public static $modules = ['domain', 'domain_access', 'field', 'field_ui'];
  16. /**
  17. * Tests that the module installed its field correctly.
  18. */
  19. public function testDomainAccessAllField() {
  20. $label = 'Send to all affiliates';
  21. $this->admin_user = $this->drupalCreateUser([
  22. 'administer content types',
  23. 'administer node fields',
  24. 'administer node display',
  25. 'administer domains',
  26. ]);
  27. $this->drupalLogin($this->admin_user);
  28. // Visit the article field administration page.
  29. $this->drupalGet('admin/structure/types/manage/article/fields');
  30. $this->assertResponse(200, 'Manage fields page accessed.');
  31. // Check for the field.
  32. $this->assertText($label, 'Domain form field found.');
  33. // Visit the article field display administration page.
  34. $this->drupalGet('admin/structure/types/manage/article/display');
  35. $this->assertResponse(200, 'Manage field display page accessed.');
  36. // Check for the field.
  37. $this->assertText($label, 'Domain form field found.');
  38. }
  39. /**
  40. * Tests the storage of the domain access field.
  41. */
  42. public function testDomainAccessAllFieldStorage() {
  43. $label = 'Send to all affiliates';
  44. $this->admin_user = $this->drupalCreateUser([
  45. 'bypass node access',
  46. 'administer content types',
  47. 'administer node fields',
  48. 'administer node display',
  49. 'administer domains',
  50. 'publish to any domain',
  51. ]);
  52. $this->drupalLogin($this->admin_user);
  53. // Create 5 domains.
  54. $this->domainCreateTestDomains(5);
  55. // Visit the article field display administration page.
  56. $this->drupalGet('node/add/article');
  57. $this->assertResponse(200);
  58. // Check the new field exists on the page.
  59. $this->assertText($label, 'Found the domain field instance.');
  60. // We expect to find 5 domain options.
  61. $domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
  62. foreach ($domains as $domain) {
  63. $string = 'value="' . $domain->id() . '"';
  64. $this->assertRaw($string, 'Found the domain option.');
  65. if (!isset($one)) {
  66. $one = $domain->id();
  67. continue;
  68. }
  69. if (!isset($two)) {
  70. $two = $domain->id();
  71. }
  72. }
  73. // Try to post a node, assigned to the first two domains.
  74. $edit['title[0][value]'] = 'Test node';
  75. $edit["field_domain_access[{$one}]"] = TRUE;
  76. $edit["field_domain_access[{$two}]"] = TRUE;
  77. $edit["field_domain_all_affiliates[value]"] = 1;
  78. $this->drupalPostForm('node/add/article', $edit, 'Save');
  79. $this->assertResponse(200);
  80. $node = \Drupal::entityTypeManager()->getStorage('node')->load(1);
  81. // Check that two values are set.
  82. $values = \Drupal::service('domain_access.manager')->getAccessValues($node);
  83. $this->assertTrue(count($values) == 2, 'Node saved with two domain records.');
  84. // Check that all affiliates is set.
  85. $this->assertTrue(!empty($node->get(DOMAIN_ACCESS_ALL_FIELD)->value), 'Node assigned to all affiliates.');
  86. }
  87. }