View source
<?php
namespace Drupal\linkit\Tests\Matchers;
use Drupal\linkit\Tests\LinkitTestBase;
class NodeMatcherTest extends LinkitTestBase {
public static $modules = [
'node',
];
protected $manager;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this->manager = $this->container
->get('plugin.manager.linkit.matcher');
$type1 = $this
->drupalCreateContentType([
'type' => 'test1',
'name' => 'Test1',
]);
$type2 = $this
->drupalCreateContentType([
'type' => 'test2',
'name' => 'Test2',
]);
$this
->drupalCreateNode([
'title' => 'Lorem Ipsum 1',
'type' => $type1
->id(),
]);
$this
->drupalCreateNode([
'title' => 'Lorem Ipsum 2',
'type' => $type1
->id(),
]);
$this
->drupalCreateNode([
'title' => 'Lorem Ipsum 3',
'type' => $type2
->id(),
]);
$this
->drupalCreateNode([
'title' => 'Lorem unpublishd',
'type' => $type1
->id(),
'status' => FALSE,
]);
}
function testNodeMatcherWidthDefaultConfiguration() {
$plugin = $this->manager
->createInstance('entity:node', []);
$matches = $plugin
->getMatches('Lorem');
$this
->assertEqual(3, count($matches), 'Correct number of matches');
}
function testNodeMatcherWidthBundleFiler() {
$plugin = $this->manager
->createInstance('entity:node', [
'settings' => [
'bundles' => [
'test1' => 'test1',
],
],
]);
$matches = $plugin
->getMatches('Lorem');
$this
->assertEqual(2, count($matches), 'Correct number of matches');
}
function testNodeMatcherWidthIncludeUnpublished() {
$plugin = $this->manager
->createInstance('entity:node', [
'settings' => [
'include_unpublished' => TRUE,
],
]);
$matches = $plugin
->getMatches('Lorem');
$this
->assertEqual(3, count($matches), 'Correct number of matches');
$account = $this
->drupalCreateUser([
'bypass node access',
]);
$this
->drupalLogin($account);
$matches = $plugin
->getMatches('Lorem');
$this
->assertEqual(4, count($matches), 'Correct number of matches');
}
}