Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / src / Tests / Matchers / NodeMatcherTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Tests\Matchers\NodeMatcherTest.
6  */
7
8 namespace Drupal\linkit\Tests\Matchers;
9
10 use Drupal\linkit\Tests\LinkitTestBase;
11
12 /**
13  * Tests node matcher.
14  *
15  * @group linkit
16  */
17 class NodeMatcherTest extends LinkitTestBase {
18
19   /**
20    * Modules to enable.
21    *
22    * @var array
23    */
24   public static $modules = ['node'];
25
26   /**
27    * The matcher manager.
28    *
29    * @var \Drupal\linkit\MatcherManager
30    */
31   protected $manager;
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function setUp() {
37     parent::setUp();
38     $this->drupalLogin($this->adminUser);
39     $this->manager = $this->container->get('plugin.manager.linkit.matcher');
40
41     $type1 = $this->drupalCreateContentType(['type' => 'test1', 'name' => 'Test1']);
42     $type2 = $this->drupalCreateContentType(['type' => 'test2', 'name' => 'Test2']);
43
44     // Nodes with type 1.
45     $this->drupalCreateNode(['title' => 'Lorem Ipsum 1', 'type' => $type1->id()]);
46     $this->drupalCreateNode(['title' => 'Lorem Ipsum 2', 'type' => $type1->id()]);
47
48     // Nodes with type 1.
49     $this->drupalCreateNode(['title' => 'Lorem Ipsum 3', 'type' => $type2->id()]);
50
51     // Unpublished node.
52     $this->drupalCreateNode(['title' => 'Lorem unpublishd', 'type' => $type1->id(), 'status' => FALSE]);
53   }
54
55   /**
56    * Tests node matcher.
57    */
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');
63   }
64
65   /**
66    * Tests node matcher with bundle filer.
67    */
68   function testNodeMatcherWidthBundleFiler() {
69     /** @var \Drupal\linkit\MatcherInterface $plugin */
70     $plugin = $this->manager->createInstance('entity:node', [
71       'settings' => [
72         'bundles' => [
73           'test1' => 'test1'
74         ],
75       ],
76     ]);
77
78     $matches = $plugin->getMatches('Lorem');
79     $this->assertEqual(2, count($matches), 'Correct number of matches');
80   }
81
82   /**
83    * Tests node matcher with include unpublished setting activated.
84    */
85   function testNodeMatcherWidthIncludeUnpublished() {
86     /** @var \Drupal\linkit\MatcherInterface $plugin */
87     $plugin = $this->manager->createInstance('entity:node', [
88       'settings' => [
89         'include_unpublished' => TRUE,
90       ],
91     ]);
92
93     // Test without permissions to see unpublished nodes.
94     $matches = $plugin->getMatches('Lorem');
95     $this->assertEqual(3, count($matches), 'Correct number of matches');
96
97     $account = $this->drupalCreateUser(['bypass node access']);
98     $this->drupalLogin($account);
99
100     // Test with permissions to see unpublished nodes.
101     $matches = $plugin->getMatches('Lorem');
102     $this->assertEqual(4, count($matches), 'Correct number of matches');
103   }
104
105 }