protected function FlagTestBase::createFlagWithForm in Flag 8.4
Creates a flag entity using the admin UI.
If you do not provide any bundles in $edit, all bundles for $entity_type are assumed.
Parameters
string|null $entity_type: (optional) A string containing the flaggable entity type, by default 'node'.
array $edit: (optional) An array of form field names and values. If omitted, random strings will be used for the flag ID, label, short and long text.
string|null $link_type: (optional) A string containing the link type ID. Is omitted, assumes 'reload'.
Return value
\Drupal\flag\FlagInterface|null The created flag entity.
1 call to FlagTestBase::createFlagWithForm()
- LinkTypeAjaxTest::testNoJavascriptResponse in tests/
src/ Functional/ LinkTypeAjaxTest.php - Tests the no-js fallback behavior for the AJAX link type.
File
- tests/
src/ Functional/ FlagTestBase.php, line 112
Class
- FlagTestBase
- Provides common methods for Flag tests.
Namespace
Drupal\Tests\flag\FunctionalCode
protected function createFlagWithForm($entity_type = 'node', $edit = [], $link_type = 'reload') {
// Submit the flag add page.
$this
->drupalPostForm('admin/structure/flags/add', [
'flag_entity_type' => $this
->getFlagType($entity_type),
], $this
->t('Continue'));
// Set the link type.
$this
->drupalPostForm(NULL, [
'link_type' => $link_type,
], 'Create Flag');
// Create an array of defaults.
$default_edit = [
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomHTMLString(),
'flag_short' => $this
->randomHTMLString(),
'unflag_short' => $this
->randomHTMLString(),
'flag_long' => $this
->randomHTMLString(16),
'unflag_long' => $this
->randomHTMLString(16),
'flag_message' => $this
->randomHTMLString(32),
'unflag_message' => $this
->randomHTMLString(32),
'unflag_denied_text' => $this
->randomHTMLString(),
'link_type' => $link_type,
];
// Merge the default values with the edit array.
$final_edit = array_merge($default_edit, $edit);
// Submit the flag details form.
$this
->drupalPostForm(NULL, $final_edit, $this
->t('Create Flag'));
// Load the new flag we created.
$flag = Flag::load($final_edit['id']);
// Make sure that we actually did get a flag entity.
$this
->assertTrue($flag instanceof Flag);
// Return the flag.
return $flag;
}