You are here

public function LinkitsearchPluginNodeTestCase::testUnpublishedItems in Linkit 7.3

Test how node states are handled.

File

test/linkit_search_plugin_node.test, line 71
Tests for Linkit search plugin node.

Class

LinkitsearchPluginNodeTestCase
Test the the node search plugin.

Code

public function testUnpublishedItems() {

  // Create some nodes.
  $node_1 = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'title' => $this->search_string . $this
      ->randomName(),
    'status' => NODE_NOT_PUBLISHED,
  ));
  $node_2 = $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'title' => $this->search_string . $this
      ->randomName(),
    'status' => NODE_NOT_PUBLISHED,
  ));

  // Call the autocomplete helper method.
  $this
    ->autocompleteCall();

  // Assert that the unpublished node title doesn't appear in the response.
  $this
    ->assertNoRaw($node_1->title, 'Unpublished node was not found in the result array.');
  $this
    ->assertNoRaw($node_2->title, 'Unpublished node was not found in the result array.');

  // Tell the profile to include unpublished nodes.
  $this->_profile->data['entity:node']['include_unpublished'] = 1;
  $this
    ->updateProfile();

  // In order to see unpublished nodes in the result, the user must also have
  // permission to see unpublished nodes.
  // We give the user 'bypass node access' permission as we don't crated the
  // nodes with this user.
  $this->account = $this
    ->drupalCreateUser(array(
    'bypass node access',
  ));
  $this
    ->drupalLogin($this->account);

  // Call the autocomplete helper method.
  $this
    ->autocompleteCall();

  // Assert that the unpublished title appears in the response.
  $this
    ->assertRaw($node_1->title, 'Unpublished node was found in the result array.');
  $this
    ->assertRaw($node_2->title, 'Unpublished node was found in the result array.');
}