You are here

public function SearchByPagePathsNodesTest::setUp in Search by Page 8

Overrides SearchByPageTesterTest::setUp

File

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

Class

SearchByPagePathsNodesTest
Tests for Search by Page Paths - searching nodes.

Namespace

Drupal\Tests\search_by_page\Functional

Code

public function setUp() {
  parent::setUp('search', 'search_by_page', 'search_by_page_paths', 'search_by_page_test', 'dblog');
  $this
    ->setUpEnvironments();
  $this->superuser = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'access content',
    'administer blocks',
    'administer search',
    'search content',
    'administer search by page',
    'access administration pages',
    $this
      ->searchPerm($this->envinfo2),
    'administer site configuration',
    'administer users',
    'administer permissions',
    'administer filters',
    'access site reports',
  ));
  $this
    ->drupalLogin($this->superuser);

  // Set up Search by Page button name
  $this
    ->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid2, array(
    'button_label' => t('Search pages'),
  ), 'Save configuration');
  \Drupal::service('cache.bootstrap')
    ->invalidateAll();
  variable_initialize();

  // 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_,
  );
  $this
    ->drupalCreateNode($info);
  $this
    ->drupalCreateNode($info);
  $this
    ->drupalCreateNode($info);
  $this
    ->drupalCreateNode($info);

  // Create some content with different input formats and add to SBP Paths.
  $format_to_use = filter_default_format($this->superuser);
  $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',
          'format' => $format_to_use,
        ),
      ),
    ),
    'type' => 'page',
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('walk', 'Walk found on node page');
  $path_add_path = 'admin/config/search/search_by_page/edit/' . $this->envid2 . '/paths/add';
  $rid = $this
    ->getNewRoleID($this->superuser);
  $this
    ->drupalPostForm($path_add_path, array(
    'path' => 'node/' . $node->nid,
    'title' => t($node->title),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $rid,
  ), t('Create new indexed page'));

  // Make sure there's a second text format.
  $this
    ->drupalPostForm('admin/config/content/formats/add', array(
    'name' => $this
      ->randomName(10),
    'roles[' . $rid . ']' => TRUE,
  ), t('Save configuration'));

  // Pick out a new format to use.
  $formats = filter_formats($this->superuser);
  foreach ($formats as $fid => $info) {
    if ($fid != $format_to_use) {
      $format_to_use = $fid;
      break;
    }
  }
  $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.',
          'format' => $format_to_use,
        ),
      ),
    ),
    'type' => 'page',
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('walk', 'Walk found on node page');
  $this
    ->drupalPostForm($path_add_path, array(
    'path' => 'node/' . $node->nid,
    'title' => t($node->title),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $this
      ->getNewRoleID($this->superuser),
  ), 'Create new indexed page');
  $this
    ->doCronRun();
  $this
    ->drupalLogin($this->superuser);
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertText(t('Cron run completed'), 'Log shows cron run completed');
}