You are here

public function SearchByPagePathsAliasTest::setUp in Search by Page 8

Overrides SearchByPageTesterTest::setUp

File

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

Class

SearchByPagePathsAliasTest
Tests for Search by Page Paths - searching nodes with aliases.

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', 'path', '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->envinfo1),
    'administer site configuration',
    'administer users',
    'administer permissions',
    'administer url aliases',
    'create url aliases',
    'access site reports',
  ));
  $this
    ->drupalLogin($this->superuser);

  // Set up Search by Page button name
  $this
    ->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid1, 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 a path alias and add to SBP Paths.
  // Create the content.
  $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' => 'page',
    'language' => self::LANGUAGE_NONE_,
  );
  $node = $this
    ->drupalCreateNode($info);

  // Add a URL alias to the system.
  $alias = $this
    ->randomName();
  $this
    ->drupalPostForm('admin/config/search/path/add', array(
    'source' => 'node/' . $node->nid,
    'alias' => $alias,
  ), t('Save'));

  // Add it to Search by Page Paths.
  $path_add_path = 'admin/config/search/search_by_page/edit/' . $this->envid1 . '/paths/add';
  $this
    ->drupalPostForm($path_add_path, array(
    'path' => $alias,
    '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');
}