You are here

protected function NodeMatcherTest::setUp in Linkit 8.5

Overrides LinkitKernelTestBase::setUp

File

tests/src/Kernel/Matchers/NodeMatcherTest.php, line 33

Class

NodeMatcherTest
Tests node matcher.

Namespace

Drupal\Tests\linkit\Kernel\Matchers

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('node');
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this
    ->installConfig([
    'field',
    'node',
  ]);
  $this->manager = $this->container
    ->get('plugin.manager.linkit.matcher');

  // Set the current user to a new user, else the nodes will be created by an
  // anonymous user.
  \Drupal::currentUser()
    ->setAccount($this
    ->createUser());
  $type1 = NodeType::create([
    'type' => 'test1',
    'name' => 'Test1',
  ]);
  $type1
    ->save();
  $type2 = NodeType::create([
    'type' => 'test2',
    'name' => 'Test2',
  ]);
  $type2
    ->save();

  // Nodes with type 1.
  $node = Node::create([
    'title' => 'Lorem Ipsum 1',
    'type' => $type1
      ->id(),
  ]);
  $node
    ->save();
  $node = Node::create([
    'title' => 'Lorem Ipsum 2',
    'type' => $type1
      ->id(),
  ]);
  $node
    ->save();

  // Node with type 2.
  $node = Node::create([
    'title' => 'Lorem Ipsum 3',
    'type' => $type2
      ->id(),
  ]);
  $node
    ->save();

  // Unpublished nodes.
  $node = Node::create([
    'title' => 'Lorem unpublishd',
    'type' => $type1
      ->id(),
    'status' => FALSE,
  ]);
  $node
    ->save();
  $node = Node::create([
    'title' => 'Lorem unpublishd 2',
    'type' => $type2
      ->id(),
    'status' => FALSE,
  ]);
  $node
    ->save();

  // Set the current user to someone that is not the node owner.
  \Drupal::currentUser()
    ->setAccount($this
    ->createUser([], [
    'access content',
  ]));
}