5 * Contains \Drupal\linkit\Tests\Matchers\UserMatcherTest.
8 namespace Drupal\linkit\Tests\Matchers;
10 use Drupal\linkit\Tests\LinkitTestBase;
17 class UserMatcherTest extends LinkitTestBase {
24 public static $modules = ['user'];
27 * The matcher manager.
29 * @var \Drupal\linkit\MatcherManager
36 protected function setUp() {
38 $this->drupalLogin($this->drupalCreateUser(['access user profiles']));
39 $this->manager = $this->container->get('plugin.manager.linkit.matcher');
41 $custom_role = $this->drupalCreateRole(array(), 'custom_role', 'custom_role');
42 $custom_role_admin = $this->drupalCreateRole(array(), 'custom_role_admin', 'custom_role_admin');
44 $this->drupalCreateUser([], 'lorem');
45 $this->drupalCreateUser([], 'foo');
47 $account = $this->drupalCreateUser([], 'ipsumlorem');
48 $account->addRole($custom_role);
51 $account = $this->drupalCreateUser([], 'lorem_custom_role');
52 $account->addRole($custom_role);
55 $account = $this->drupalCreateUser([], 'lorem_custom_role_admin');
56 $account->addRole($custom_role_admin);
59 $account = $this->drupalCreateUser([], 'blocked_lorem');
67 function testUserMatcherWidthDefaultConfiguration() {
68 /** @var \Drupal\linkit\MatcherInterface $plugin */
69 $plugin = $this->manager->createInstance('entity:user', []);
70 $matches = $plugin->getMatches('Lorem');
71 $this->assertEqual(4, count($matches), 'Correct number of matches');
75 * Tests user matcher with role filer.
77 function testUserMatcherWidthRoleFiler() {
78 /** @var \Drupal\linkit\MatcherInterface $plugin */
79 $plugin = $this->manager->createInstance('entity:user', [
82 'custom_role' => 'custom_role'
87 $matches = $plugin->getMatches('Lorem');
88 $this->assertEqual(2, count($matches), 'Correct number of matches');
92 * Tests user matcher with include blocked setting activated.
94 function testUserMatcherWidthIncludeBlocked() {
95 /** @var \Drupal\linkit\MatcherInterface $plugin */
96 $plugin = $this->manager->createInstance('entity:user', [
98 'include_blocked' => TRUE,
102 // Test without permissions to see blocked users.
103 $matches = $plugin->getMatches('blocked');
104 $this->assertEqual(0, count($matches), 'Correct number of matches');
106 $account = $this->drupalCreateUser(['administer users']);
107 $this->drupalLogin($account);
109 // Test with permissions to see blocked users.
110 $matches = $plugin->getMatches('blocked');
111 $this->assertEqual(1, count($matches), 'Correct number of matches');