5 * Contains \Drupal\linkit\Tests\Matchers\NodeMatcherTest.
8 namespace Drupal\linkit\Tests\Matchers;
10 use Drupal\linkit\Tests\LinkitTestBase;
17 class NodeMatcherTest extends LinkitTestBase {
24 public static $modules = ['node'];
27 * The matcher manager.
29 * @var \Drupal\linkit\MatcherManager
36 protected function setUp() {
38 $this->drupalLogin($this->adminUser);
39 $this->manager = $this->container->get('plugin.manager.linkit.matcher');
41 $type1 = $this->drupalCreateContentType(['type' => 'test1', 'name' => 'Test1']);
42 $type2 = $this->drupalCreateContentType(['type' => 'test2', 'name' => 'Test2']);
45 $this->drupalCreateNode(['title' => 'Lorem Ipsum 1', 'type' => $type1->id()]);
46 $this->drupalCreateNode(['title' => 'Lorem Ipsum 2', 'type' => $type1->id()]);
49 $this->drupalCreateNode(['title' => 'Lorem Ipsum 3', 'type' => $type2->id()]);
52 $this->drupalCreateNode(['title' => 'Lorem unpublishd', 'type' => $type1->id(), 'status' => FALSE]);
58 function testNodeMatcherWidthDefaultConfiguration() {
59 /** @var \Drupal\linkit\MatcherInterface $plugin */
60 $plugin = $this->manager->createInstance('entity:node', []);
61 $matches = $plugin->getMatches('Lorem');
62 $this->assertEqual(3, count($matches), 'Correct number of matches');
66 * Tests node matcher with bundle filer.
68 function testNodeMatcherWidthBundleFiler() {
69 /** @var \Drupal\linkit\MatcherInterface $plugin */
70 $plugin = $this->manager->createInstance('entity:node', [
78 $matches = $plugin->getMatches('Lorem');
79 $this->assertEqual(2, count($matches), 'Correct number of matches');
83 * Tests node matcher with include unpublished setting activated.
85 function testNodeMatcherWidthIncludeUnpublished() {
86 /** @var \Drupal\linkit\MatcherInterface $plugin */
87 $plugin = $this->manager->createInstance('entity:node', [
89 'include_unpublished' => TRUE,
93 // Test without permissions to see unpublished nodes.
94 $matches = $plugin->getMatches('Lorem');
95 $this->assertEqual(3, count($matches), 'Correct number of matches');
97 $account = $this->drupalCreateUser(['bypass node access']);
98 $this->drupalLogin($account);
100 // Test with permissions to see unpublished nodes.
101 $matches = $plugin->getMatches('Lorem');
102 $this->assertEqual(4, count($matches), 'Correct number of matches');