public function GroupAudienceTest::testGetAllGroupAudienceFieldsFilterGroupBundle in Organic groups 8
Testing getting group audience fields filtered by group bundle.
File
- tests/
src/ Kernel/ Entity/ GroupAudienceTest.php, line 138
Class
- GroupAudienceTest
- Tests the group audience field.
Namespace
Drupal\Tests\og\Kernel\EntityCode
public function testGetAllGroupAudienceFieldsFilterGroupBundle() {
// Set bundles as groups.
Og::groupTypeManager()
->addGroup('entity_test', $this->bundles[0]);
Og::groupTypeManager()
->addGroup('entity_test', $this->bundles[1]);
$group_bundle1 = $this->bundles[0];
$group_bundle2 = $this->bundles[1];
$bundle = $this->bundles[2];
// Set bundle as group content.
$field_name1 = mb_strtolower($this
->randomMachineName());
$field_name2 = mb_strtolower($this
->randomMachineName());
// Add fields that explicitly references a bundle.
$overrides = [
'field_name' => $field_name1,
'field_config' => [
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$group_bundle1 => $group_bundle1,
],
],
],
],
];
Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test', $bundle, $overrides);
$overrides['field_name'] = $field_name2;
$overrides['field_config']['settings']['handler_settings']['target_bundles'] = [
$group_bundle2 => $group_bundle2,
];
Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'entity_test', $bundle, $overrides);
$field_names = $this->groupAudienceHelper
->getAllGroupAudienceFields('entity_test', $bundle, 'entity_test', $group_bundle1);
$this
->assertEquals([
$field_name1,
], array_keys($field_names));
}