View source
<?php
namespace Drupal\linkit\Tests\Matchers;
use Drupal\linkit\Tests\LinkitTestBase;
class UserMatcherTest extends LinkitTestBase {
public static $modules = [
'user',
];
protected $manager;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'access user profiles',
]));
$this->manager = $this->container
->get('plugin.manager.linkit.matcher');
$custom_role = $this
->drupalCreateRole(array(), 'custom_role', 'custom_role');
$custom_role_admin = $this
->drupalCreateRole(array(), 'custom_role_admin', 'custom_role_admin');
$this
->drupalCreateUser([], 'lorem');
$this
->drupalCreateUser([], 'foo');
$account = $this
->drupalCreateUser([], 'ipsumlorem');
$account
->addRole($custom_role);
$account
->save();
$account = $this
->drupalCreateUser([], 'lorem_custom_role');
$account
->addRole($custom_role);
$account
->save();
$account = $this
->drupalCreateUser([], 'lorem_custom_role_admin');
$account
->addRole($custom_role_admin);
$account
->save();
$account = $this
->drupalCreateUser([], 'blocked_lorem');
$account
->block();
$account
->save();
}
function testUserMatcherWidthDefaultConfiguration() {
$plugin = $this->manager
->createInstance('entity:user', []);
$matches = $plugin
->getMatches('Lorem');
$this
->assertEqual(4, count($matches), 'Correct number of matches');
}
function testUserMatcherWidthRoleFiler() {
$plugin = $this->manager
->createInstance('entity:user', [
'settings' => [
'roles' => [
'custom_role' => 'custom_role',
],
],
]);
$matches = $plugin
->getMatches('Lorem');
$this
->assertEqual(2, count($matches), 'Correct number of matches');
}
function testUserMatcherWidthIncludeBlocked() {
$plugin = $this->manager
->createInstance('entity:user', [
'settings' => [
'include_blocked' => TRUE,
],
]);
$matches = $plugin
->getMatches('blocked');
$this
->assertEqual(0, count($matches), 'Correct number of matches');
$account = $this
->drupalCreateUser([
'administer users',
]);
$this
->drupalLogin($account);
$matches = $plugin
->getMatches('blocked');
$this
->assertEqual(1, count($matches), 'Correct number of matches');
}
}