public function NodeMatcherTest::testNodeMatcherWidthIncludeUnpublished in Linkit 8.5
Tests node matcher with include unpublished setting activated.
File
- tests/
src/ Kernel/ Matchers/ NodeMatcherTest.php, line 127
Class
- NodeMatcherTest
- Tests node matcher.
Namespace
Drupal\Tests\linkit\Kernel\MatchersCode
public function testNodeMatcherWidthIncludeUnpublished() {
/** @var \Drupal\linkit\MatcherInterface $plugin */
$plugin = $this->manager
->createInstance('entity:node', [
'settings' => [
'include_unpublished' => TRUE,
],
]);
// Test without permissions to see unpublished nodes.
$suggestions = $plugin
->execute('Lorem');
$this
->assertEquals(3, count($suggestions
->getSuggestions()), 'Correct number of suggestions');
// Set the current user to a user with 'bypass node access' permission.
\Drupal::currentUser()
->setAccount($this
->createUser([], [
'bypass node access',
]));
// Test with permissions to see unpublished nodes.
$suggestions = $plugin
->execute('Lorem');
$this
->assertEquals(5, count($suggestions
->getSuggestions()), 'Correct number of suggestions');
// Test with permissions to see own unpublished nodes.
\Drupal::currentUser()
->setAccount($this
->createUser([], [
'access content',
'view own unpublished content',
]));
$nodes = $this->container
->get('entity_type.manager')
->getStorage('node')
->loadByProperties([
'title' => 'Lorem unpublishd',
]);
$node4 = reset($nodes);
/** @var \Drupal\node\NodeInterface $node4 */
$node4
->setOwnerId(\Drupal::currentUser()
->id());
$node4
->save();
$suggestions = $plugin
->execute('Lorem');
$this
->assertEquals(4, count($suggestions
->getSuggestions()), 'Correct number of suggestions');
// Test with permissions to see any unpublished nodes.
\Drupal::currentUser()
->setAccount($this
->createUser([], [
'access content',
'view any unpublished content',
]));
$suggestions = $plugin
->execute('Lorem');
$this
->assertEquals(5, count($suggestions
->getSuggestions()), 'Correct number of suggestions');
}