summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJennifer Hodgdon2013-01-19 16:01:00 (GMT)
committer Jennifer Hodgdon2013-01-19 16:01:00 (GMT)
commitd9ccb4958d64cb5f4401aa424c615752dabed776 (patch)
treea344e1e10f2f0352e28c789d6cd11c015b9b84b3
parent8adefdac99465b9b02969d011f8be8d77de3949e (diff)
Issue #1386822 by Jaapx, jhodgdon: Ensure only one indexing user is created per role (and add test for this)
-rw-r--r--search_by_page.module4
-rw-r--r--tests/search_by_page.test125
2 files changed, 127 insertions, 2 deletions
diff --git a/search_by_page.module b/search_by_page.module
index d37c59c..3816835 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 9970a4c..3be8b41 100644
--- a/tests/search_by_page.test
+++ b/tests/search_by_page.test
@@ -932,6 +932,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.
*/
class SearchByPageUsersTest extends SearchByPageTester {