public function BundleFormAlterTest::testCreate in Organic groups 8
Test that group and group content bundles can be created through the UI.
File
- og_ui/
tests/ src/ Functional/ BundleFormAlterTest.php, line 65
Class
- BundleFormAlterTest
- Test making a bundle a group and a group content.
Namespace
Drupal\Tests\og_ui\FunctionalCode
public function testCreate() {
// Create a custom block and define it as a group type. We make sure the
// group and group content are of different entity types so we can test that
// the correct entity type is referenced.
$edit = [
'label' => 'school',
'id' => 'school',
'og_is_group' => 1,
];
$this
->drupalGet('admin/structure/block/block-content/types/add');
$this
->submitForm($edit, new TranslatableMarkup('Save'));
$edit = [
'name' => 'class',
'type' => 'class',
'og_group_content_bundle' => 1,
'og_target_type' => 'block_content',
'og_target_bundles[]' => [
'school',
],
];
$this
->drupalGet('admin/structure/types/add');
$this
->submitForm($edit, new TranslatableMarkup('Save content type'));
$this->content = $this
->drupalGet('admin/structure/types/manage/class');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-og-target-bundles', 'school')
->isSelected());
$this
->assertTargetType('block_content', 'The target type is set to the "Custom Block" entity type.');
$this
->assertTargetBundles([
'school' => 'school',
], 'The target bundles are set to the "school" bundle.');
// Test that if the target bundles are unselected, the value for the target
// bundles becomes NULL rather than an empty array. The entity reference
// selection plugin considers the value NULL to mean 'all bundles', while an
// empty array means 'no bundles are allowed'.
// @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::buildEntityQuery()
$edit = [
'name' => 'class',
'og_group_content_bundle' => 1,
'og_target_type' => 'block_content',
'og_target_bundles[]' => [],
];
$this
->drupalGet('admin/structure/types/manage/class');
$this
->submitForm($edit, new TranslatableMarkup('Save content type'));
$this
->assertTargetBundles(NULL, 'When the target bundle field is cleared from all values, it takes on the value NULL.');
}