You are here

public function SearchByPageNodesTest::setUp in Search by Page 8

Overrides SearchByPageTesterTest::setUp

File

tests/src/Functional/search_by_page.test, line 39
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPageNodesTest
Functionality tests for Search by Page Nodes.

Namespace

Drupal\Tests\search_by_page\Functional

Code

public function setUp() {
  parent::setUp('search', 'search_by_page', 'search_by_page_nodes', 'search_by_page_test', 'dblog');
  $this
    ->setUpEnvironments();

  // Set up super-user and other users with different privileges.
  $this->superuser = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'access content',
    'administer content types',
    'administer blocks',
    'administer search',
    'search content',
    'administer search by page',
    'access administration pages',
    $this
      ->searchPerm($this->envinfo1),
    'administer site configuration',
    'administer users',
    'administer permissions',
    'view test private content',
    'access site reports',
    'bypass node access',
  ));
  $this->noprivuser = $this
    ->drupalCreateUser(array(
    'access content',
    'search content',
    $this
      ->searchPerm($this->envinfo1),
  ));
  $this->privuser = $this
    ->drupalCreateUser(array(
    'access content',
    'search content',
    $this
      ->searchPerm($this->envinfo1),
    'view test private content',
  ));
  $this
    ->drupalLogin($this->superuser);

  // Set up so "search_by_page_indexed" nodes are searchable, and "search_by_page_hidden" nodes are
  // not. Index them with the priveleged user.
  $this
    ->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid1, array(
    'search_by_page_nodes_types_indexed[search_by_page_indexed]' => TRUE,
    'search_by_page_nodes_display_type' => 'excerpts',
    'search_by_page_nodes_role' => $this
      ->getNewRoleID($this->privuser),
    'button_label' => t('Search pages'),
  ), 'Save configuration');
  \Drupal::service('cache.bootstrap')
    ->invalidateAll();
  variable_initialize();
  $info = array(
    'body' => array(
      self::LANGUAGE_NONE => array(
        array(
          'value' => 'double trouble',
        ),
      ),
    ),
    'type' => 'page',
    'language' => self::LANGUAGE_NONE,
    'title' => 'first page',
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('trouble', "Node page could be found");

  // Throw in a few nodes that won't match our tests.
  $info = array(
    'body' => array(
      self::LANGUAGE_NONE_ => array(
        array(
          'value' => 'blah',
          'summary' => 'blah',
        ),
      ),
    ),
    'title' => 'blah',
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('blah', "Node page could be found");
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('blah', "Node page could be found");
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('blah', "Node page could be found");

  // Create some content that we'll look for - make sure it has the
  // word "walk" in it.
  $info = array(
    'body' => array(
      self::LANGUAGE_NONE_ => array(
        array(
          'value' => 'I walk through the streets, looking around for trouble',
          'summary' => 'I walk on a path, where it is quiet',
        ),
      ),
    ),
    'type' => 'search_by_page_indexed',
    'test_private' => FALSE,
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->nodetitle1 = $node->title;
  $this->nodeid1 = $node->nid;
  $this
    ->assertFalse($node->test_private, "Created a non-private node");
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('streets', "Streets appears on first node page");
  $this
    ->assertNoText('north', "North does not appear on first node page");
  $this
    ->assertNoText('people', "People does not appear on first node page");

  // Create some "private" content, also with the word "walk" in it
  $info = array(
    'body' => array(
      self::LANGUAGE_NONE_ => array(
        array(
          'value' => 'I can walk really far, maybe even to the north pole.',
          'summary' => 'I will walk to the south pole.',
        ),
      ),
    ),
    'type' => 'search_by_page_indexed',
    'test_private' => TRUE,
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->privnodeid = $node->nid;
  $this
    ->assertTrue($node->test_private, "Created a private node");
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertNoText('streets', "Streets does not appear on second node page");
  $this
    ->assertText('north', "North appears on second node page");
  $this
    ->assertNoText('people', "People does not appear on second node page");

  // Create some non-indexed content, also with the word "walk" in it
  $info = array(
    'body' => array(
      self::LANGUAGE_NONE_ => array(
        array(
          'value' => 'When I walk, I try not to run into people.',
        ),
      ),
    ),
    'type' => 'search_by_page_hidden',
    'test_private' => FALSE,
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertNoText('streets', "Streets does not appear on third node page");
  $this
    ->assertNoText('north', "North does not appear on third node page");
  $this
    ->assertText('people', "People appears on third node page");

  // Create some content with excluded tags. Make sure to use Full HTML
  // input format.
  $excluded = search_by_page_setting_get('exclude_tags', $this->envid1, '');
  $this
    ->assertEqual($excluded, 'tagtoexclude', 'Correct tag is marked excluded');

  // Find the Full HTML format.
  $filters = filter_formats();
  $filternum = 0;
  foreach ($filters as $filter) {
    if ($filter->name == 'Full HTML') {
      $filternum = $filter->format;
      break;
    }
  }
  $info = array(
    'body' => array(
      self::LANGUAGE_NONE_ => array(
        array(
          'value' => 'This content <tagtoexclude>only has walk gobble in the excluded tag</tagtoexclude> and then gobble appears after it.',
          'summary' => 'Short version of this content',
          'format' => $filternum,
        ),
      ),
    ),
    'type' => 'search_by_page_indexed',
    'test_private' => FALSE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->exclnodetitle = $node->title;
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('walk', "walk appears on the excluded node page");
  $this
    ->assertText('gobble', "gobble appears on the excluded node page");
  $this
    ->doCronRun();
  $this
    ->drupalLogin($this->superuser);
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertText(t('Cron run completed'), 'Log shows cron run completed');
}