UserFlagTypeTest.php in Flag 8.4
File
tests/src/Functional/UserFlagTypeTest.php
View source
<?php
namespace Drupal\Tests\flag\Functional;
class UserFlagTypeTest extends FlagTestBase {
protected $flag;
public function testFlagSelfCheckbox() {
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('admin/structure/flags/add', [
'flag_entity_type' => 'entity:user',
], $this
->t('Continue'));
$this
->assertText($this
->t('Permissions for users to flag themselves.'));
$this
->assertText($this
->t('Display link on user profile page'));
}
public function testFlagSelf() {
$flag = $this
->createFlagFromArray([
'link_type' => 'reload',
'entity_type' => 'user',
'bundles' => array_keys(\Drupal::service('entity_type.bundle.info')
->getBundleInfo('user')),
'flag_type' => $this
->getFlagType('user'),
'show_on_profile' => TRUE,
'flagTypeConfig' => [
'extra_permissions' => [
'owner',
],
],
]);
$user = $this
->createUser([
'flag ' . $flag
->id() . ' own user account',
'unflag ' . $flag
->id() . ' own user account',
'administer flags',
'administer flagging display',
'administer flagging fields',
'administer node display',
'administer nodes',
]);
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/flags/manage/' . $flag
->id());
$this
->assertFieldChecked('edit-extra-permissions-owner');
$this
->drupalGet('user/' . $user
->id());
$this
->assertLink($flag
->getShortText('flag'));
$edit = [
'extra_permissions[owner]' => FALSE,
];
$this
->drupalPostForm('admin/structure/flags/manage/' . $flag
->id(), $edit, $this
->t('Save Flag'));
$this
->drupalGet('admin/structure/flags/manage/' . $flag
->id());
$this
->assertNoFieldChecked('edit-extra-permissions-owner');
$this
->drupalGet('user/' . $user
->id());
$this
->assertNoLink($flag
->getShortText('flag'));
}
}