You are here

public function GroupAudienceTest::testGetAllGroupAudienceFields in Organic groups 8

Testing getting all group audience fields.

File

tests/src/Kernel/Entity/GroupAudienceTest.php, line 74

Class

GroupAudienceTest
Tests the group audience field.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testGetAllGroupAudienceFields() {

  // Set bundles as groups.
  Og::groupTypeManager()
    ->addGroup('entity_test', $this->bundles[0]);
  Og::groupTypeManager()
    ->addGroup('entity_test', $this->bundles[1]);
  $bundle = $this->bundles[2];

  // Test no values returned for a non-group content.
  $this
    ->assertEmpty($this->groupAudienceHelper
    ->getAllGroupAudienceFields('entity_test', $bundle));

  // Set bundles as group content.
  $field_name1 = mb_strtolower($this
    ->randomMachineName());
  $field_name2 = mb_strtolower($this
    ->randomMachineName());
  Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test', $bundle, [
    'field_name' => $field_name1,
  ]);
  Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test', $bundle, [
    'field_name' => $field_name2,
  ]);
  $expected_field_names = [
    $field_name1,
    $field_name2,
  ];
  $actual_field_names = array_keys($this->groupAudienceHelper
    ->getAllGroupAudienceFields('entity_test', $bundle));
  sort($expected_field_names);
  sort($actual_field_names);
  $this
    ->assertEquals($expected_field_names, $actual_field_names);

  // Test Og::isGroupContent method, which is just a wrapper around
  // OgGroupAudienceHelper::hasGroupAudienceFields().
  $this
    ->assertTrue(Og::isGroupContent('entity_test', $bundle));
  $bundle = $this->bundles[3];
  $this
    ->assertFalse(Og::isGroupContent('entity_test', $bundle));
}