diff --git a/search_by_page.module b/search_by_page.module index d37c59c240aff36e890ad0d19351c8c088d6b0a5..38168359efc1c8aacce4593cd8ed25b5df54e3e6 100644 --- a/search_by_page.module +++ b/search_by_page.module @@ -1714,8 +1714,8 @@ function _search_by_page_indexing_users() { if ($account) { db_insert('sbp_index_users') ->fields(array( - 'rid', $rid, - 'uid', $account->uid, + 'rid' => $rid, + 'uid' => $account->uid, )) ->execute(); } diff --git a/tests/search_by_page.test b/tests/search_by_page.test index 9970a4cd2cd7677a8941d72278612554615efdce..3be8b41948b8812010b0fc095b4be5b7c9a6fa0e 100644 --- a/tests/search_by_page.test +++ b/tests/search_by_page.test @@ -931,6 +931,131 @@ class SearchByPageNodesReindexTest extends SearchByPageTester { } } +/** + * Tests that no extra Search by Page indexing users are created. + */ +class SearchByPageExtraUsersTest extends SearchByPageTester { + + public $superuser; + public $nodes; + + public static function getInfo() { + return array( + 'name' => t('Search by Page Extra Users'), + 'description' => t('Test that only the necessary users are created.'), + 'group' => t('Search by Page'), + 'dependencies' => array('search', 'sbp_test', 'sbp_nodes', 'dblog', 'search_by_page', 'comment'), + ); + } + + public function setUp() { + parent::setUp('search', 'search_by_page', 'sbp_nodes', 'sbp_test', 'dblog', 'comment'); + $this->setUpEnvironments(); + + // Set up super-user. + + $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', 'access comments', + 'skip comment approval', 'administer comments')); + + $this->drupalLogin($this->superuser); + + // Set up so "sbp_indexed" nodes are searchable. + // Index them with the super-user. + + $this->drupalPost('admin/config/search/search_by_page/edit/' . $this->envid1, + array( + 'sbp_nodes_types_indexed[sbp_indexed]' => TRUE, + 'sbp_nodes_display_type' => 'excerpts', + 'sbp_nodes_role' => $this->getNewRoleID($this->superuser), + 'button_label' => t('Search pages'), + ), + 'Save configuration'); + cache_clear_all('variables', 'cache_bootstrap'); + variable_initialize(); + + // Create 5 nodes with the same content. + $info = array( + 'body' => array(LANGUAGE_NONE => array(array('value' => 'blah'))), + 'type' => 'sbp_indexed', + 'language' => LANGUAGE_NONE, + 'title' => 'blah', + 'test_private' => FALSE, + ); + + $this->nodes = array(); + for ($i = 0; $i < 5; $i++) { + $this->nodes[] = $this->drupalCreateNode($info); + } + + // Run cron to index these nodes. + $this->doCronrun(); + $this->drupalLogin($this->superuser); + $this->drupalGet('admin/reports/dblog'); + $this->assertText(t('Cron run completed'), 'Log shows cron run completed'); + $this->drupalLogout(); + } + + /** + * Tests that no new users are created when reindexing. + */ + function testReindexingUsers() { + $this->drupalLogin($this->superuser); + $search_path = $this->envinfo1['page_path']; + + // Count the number of users. + $num_before = $this->howManyUsers(); + + // Set to reindex automatically on normal cycle. + $this->drupalPost('admin/config/search/search_by_page/edit/' . $this->envid1, + array( + 'sbp_nodes_min_time' => 1, + 'sbp_nodes_max_time' => 0, + ), + 'Save configuration'); + cache_clear_all('variables', 'cache'); + variable_initialize(); + + // Set search so it only indexes 1 node per cron run. + variable_set('sbp_cron_limit', 1); + + // Figure out the current index times of the nodes. + $orig = $this->getIndexTimes(); + + // In a loop: run cron, and verify each time that something was reindexed. + for ($i = 0; $i < 10; $i++) { + // Run cron - should reindex just one node. + $this->doCronrun(); + $this->drupalLogin($this->superuser); + + // Figure out the current index times of the nodes. + $new = $this->getIndexTimes(); + + // Verify that only one was indexed, and it was the oldest one. + $this->verifyIndexCycling($orig, $new); + $orig = $new; + } + + // Now see how many users there are. + $num_after = $this->howManyUsers(); + + $this->assertEqual($num_before, $num_after, "Number of users before ($num_before) and after ($num_after) is the same"); + } + + // Counts how many user accounts there are. + function howManyUsers() { + $query = db_select('users', 'u'); + $query->addExpression('count(*)'); + return $query->execute() + ->fetchField(); + } +} + /** * Functionality tests for Search by Page Users. */