View source
<?php
namespace Drupal\Tests\flag\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\flag\Entity\Flag;
use Drupal\Tests\flag\Traits\FlagPermissionsTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\flag\Traits\FlagCreateTrait;
abstract class FlagTestBase extends BrowserTestBase {
use FlagCreateTrait;
use FlagPermissionsTrait;
use StringTranslationTrait;
protected $defaultTheme = 'stark';
protected $flagService;
protected $adminUser;
protected $nodeType = 'article';
protected function setUp() {
parent::setUp();
$this->flagService = \Drupal::service('flag');
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
]);
$this
->drupalCreateContentType([
'type' => $this->nodeType,
]);
$this->adminUser = $this
->createUser([
'administer flags',
'administer flagging display',
'administer flagging fields',
'administer node display',
'administer modules',
'administer nodes',
'create ' . $this->nodeType . ' content',
'edit any ' . $this->nodeType . ' content',
'delete any ' . $this->nodeType . ' content',
]);
}
public static $modules = [
'views',
'node',
'user',
'flag',
'node',
'field_ui',
'text',
'block',
'contextual',
'flag_event_test',
];
protected function createFlagWithForm($entity_type = 'node', $edit = [], $link_type = 'reload') {
$this
->drupalPostForm('admin/structure/flags/add', [
'flag_entity_type' => $this
->getFlagType($entity_type),
], $this
->t('Continue'));
$this
->drupalPostForm(NULL, [
'link_type' => $link_type,
], 'Create Flag');
$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,
];
$final_edit = array_merge($default_edit, $edit);
$this
->drupalPostForm(NULL, $final_edit, $this
->t('Create Flag'));
$flag = Flag::load($final_edit['id']);
$this
->assertTrue($flag instanceof Flag);
return $flag;
}
}