function SearchByPageUsersReindexTest::testReindexingOnUpdate in Search by Page 8
Tests that user reindexing happens in the right order on user update.
File
- tests/
src/ Functional/ search_by_page.test, line 909 - Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Class
- SearchByPageUsersReindexTest
- Tests when users are reindexed.
Namespace
Drupal\Tests\search_by_page\FunctionalCode
function testReindexingOnUpdate() {
$this
->drupalLogin($this->superuser);
$search_path = $this->envinfo2['page_path'];
// Set to never reindex automatically.
$this
->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid2, array(
'search_by_page_users_min_time' => 0,
'search_by_page_users_max_time' => 0,
), 'Save configuration');
drupal_flush_all_caches();
variable_initialize();
// Set search so it only indexes 1 user per cron run.
\Drupal::state()
->set('search_by_page_cron_limit', 1);
// Run this test several times...
for ($j = 0; $j < 10; $j++) {
// Choose a random user name.
$newname = $this
->randomName();
$i = rand(0, count($this->users) - 1);
user_save($this->users[$i], array(
'name' => $newname,
));
// Verify user can be loaded and has right name.
$acct = Drupal\user\Entity\User::load($this->users[$i]->uid);
$this
->assertEqual($acct->name, $newname, "New user name was saved");
// Verify new name shows on user page
$this
->drupalGet('user/' . $this->users[$i]->uid);
$this
->assertText($newname, 'New user name appears on user page');
// Verify new name is not searchable.
$this
->drupalPostForm($search_path, array(
'keys' => $newname,
), t('Search pages'));
$this
->assertNoText($newname, 'New user name not found in search');
// Run cron - should reindex just this user.
$this
->doCronrun();
$this
->drupalLogin($this->superuser);
$this
->drupalGet('admin/reports/dblog');
$this
->assertText(t('Cron run completed'), 'Log shows cron run completed');
// Verify new name is searchable.
$this
->drupalPostForm($search_path, array(
'keys' => $newname,
), t('Search pages'));
$this
->assertText($newname, 'New user name found in search after reindex');
}
}