Commit 12415865 authored by alexpott's avatar alexpott

Issue #2380429 by tibbsa, hussainweb, jhodgdon, markat: Clean-up search module...

Issue #2380429 by tibbsa, hussainweb, jhodgdon, markat: Clean-up search module test members - ensure property definition and use of camelCase naming convention
parent 1d29fd0a
......@@ -13,6 +13,12 @@
* @group search
*/
class SearchAdvancedSearchFormTest extends SearchTestBase {
/**
* A node to use for testing.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
protected function setUp() {
......
......@@ -30,25 +30,36 @@ class SearchCommentCountToggleTest extends SearchTestBase {
*/
public static $modules = array('node', 'comment');
protected $searching_user;
protected $searchable_nodes;
/**
* A user with permission to search and post comments.
*
* @var \Drupal\user\UserInterface
*/
protected $searchingUser;
/**
* Array of nodes available to search.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $searchableNodes;
protected function setUp() {
parent::setUp();
// Create searching user.
$this->searching_user = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'post comments', 'skip comment approval'));
$this->searchingUser = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'post comments', 'skip comment approval'));
// Login with sufficient privileges.
$this->drupalLogin($this->searching_user);
$this->drupalLogin($this->searchingUser);
// Add a comment field.
$this->container->get('comment.manager')->addDefaultField('node', 'article');
// Create initial nodes.
$node_params = array('type' => 'article', 'body' => array(array('value' => 'SearchCommentToggleTestCase')));
$this->searchable_nodes['1 comment'] = $this->drupalCreateNode($node_params);
$this->searchable_nodes['0 comments'] = $this->drupalCreateNode($node_params);
$this->searchableNodes['1 comment'] = $this->drupalCreateNode($node_params);
$this->searchableNodes['0 comments'] = $this->drupalCreateNode($node_params);
// Create a comment array
$edit_comment = array();
......@@ -56,7 +67,7 @@ protected function setUp() {
$edit_comment['comment_body[0][value]'] = $this->randomMachineName();
// Post comment to the test node with comment
$this->drupalPostForm('comment/reply/node/' . $this->searchable_nodes['1 comment']->id() . '/comment', $edit_comment, t('Save'));
$this->drupalPostForm('comment/reply/node/' . $this->searchableNodes['1 comment']->id() . '/comment', $edit_comment, t('Save'));
// First update the index. This does the initial processing.
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
......@@ -83,20 +94,20 @@ function testSearchCommentCountToggle() {
$this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open');
// Test comment count display for nodes with comment status set to Closed
$this->searchable_nodes['0 comments']->set('comment', CommentItemInterface::CLOSED);
$this->searchable_nodes['0 comments']->save();
$this->searchable_nodes['1 comment']->set('comment', CommentItemInterface::CLOSED);
$this->searchable_nodes['1 comment']->save();
$this->searchableNodes['0 comments']->set('comment', CommentItemInterface::CLOSED);
$this->searchableNodes['0 comments']->save();
$this->searchableNodes['1 comment']->set('comment', CommentItemInterface::CLOSED);
$this->searchableNodes['1 comment']->save();
$this->drupalPostForm(NULL, $edit, t('Search'));
$this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Closed');
$this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed');
// Test comment count display for nodes with comment status set to Hidden
$this->searchable_nodes['0 comments']->set('comment', CommentItemInterface::HIDDEN);
$this->searchable_nodes['0 comments']->save();
$this->searchable_nodes['1 comment']->set('comment', CommentItemInterface::HIDDEN);
$this->searchable_nodes['1 comment']->save();
$this->searchableNodes['0 comments']->set('comment', CommentItemInterface::HIDDEN);
$this->searchableNodes['0 comments']->save();
$this->searchableNodes['1 comment']->set('comment', CommentItemInterface::HIDDEN);
$this->searchableNodes['1 comment']->save();
$this->drupalPostForm(NULL, $edit, t('Search'));
$this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Hidden');
......
......@@ -25,7 +25,33 @@ class SearchCommentTest extends SearchTestBase {
*/
public static $modules = array('filter', 'node', 'comment');
protected $admin_user;
/**
* Test subject for comments.
*
* @var string
*/
protected $commentSubject;
/**
* ID for the administrator role.
*
* @var string
*/
protected $adminRole;
/**
* A user with various administrative permissions.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Test node for searching.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
protected function setUp() {
parent::setUp();
......@@ -49,8 +75,8 @@ protected function setUp() {
'skip comment approval',
'access comments',
);
$this->admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->admin_user);
$this->adminUser = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->adminUser);
// Add a comment field.
$this->container->get('comment.manager')->addDefaultField('node', 'article');
}
......@@ -124,7 +150,7 @@ function testSearchResultsComment() {
$this->assertNoEscaped($edit_comment['comment_body[0][value]'], 'HTML in comment body is not escaped.');
// Hide comments.
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$node->set('comment', CommentItemInterface::HIDDEN);
$node->save();
......@@ -142,9 +168,9 @@ function testSearchResultsComment() {
*/
function testSearchResultsCommentAccess() {
$comment_body = 'Test comment body';
$this->comment_subject = 'Test comment subject';
$roles = $this->admin_user->getRoles(TRUE);
$this->admin_role = $roles[0];
$this->commentSubject = 'Test comment subject';
$roles = $this->adminUser->getRoles(TRUE);
$this->adminRole = $roles[0];
// Create a node.
// Make preview optional.
......@@ -155,7 +181,7 @@ function testSearchResultsCommentAccess() {
// Post a comment using 'Full HTML' text format.
$edit_comment = array();
$edit_comment['subject[0][value]'] = $this->comment_subject;
$edit_comment['subject[0][value]'] = $this->commentSubject;
$edit_comment['comment_body[0][value]'] = '<h1>' . $comment_body . '</h1>';
$this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', $edit_comment, t('Save'));
......@@ -166,17 +192,17 @@ function testSearchResultsCommentAccess() {
$this->setRolePermissions(DRUPAL_ANONYMOUS_RID, TRUE);
$this->assertCommentAccess(TRUE, 'Anon user has search permission and access comments permission, comments should be indexed');
$this->drupalLogin($this->admin_user);
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/people/permissions');
// Disable search access for authenticated user to test admin user.
$this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, FALSE, FALSE);
$this->setRolePermissions($this->admin_role);
$this->setRolePermissions($this->adminRole);
$this->assertCommentAccess(FALSE, 'Admin user has search permission but no access comments permission, comments should not be indexed');
$this->drupalGet('node/' . $this->node->id());
$this->setRolePermissions($this->admin_role, TRUE);
$this->setRolePermissions($this->adminRole, TRUE);
$this->assertCommentAccess(TRUE, 'Admin user has search permission and access comments permission, comments should be indexed');
$this->setRolePermissions(DRUPAL_AUTHENTICATED_RID);
......@@ -188,13 +214,13 @@ function testSearchResultsCommentAccess() {
// Verify that access comments permission is inherited from the
// authenticated role.
$this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, FALSE);
$this->setRolePermissions($this->admin_role);
$this->setRolePermissions($this->adminRole);
$this->assertCommentAccess(TRUE, 'Admin user has search permission and no access comments permission, but comments should be indexed because admin user inherits authenticated user\'s permission to access comments');
// Verify that search content permission is inherited from the authenticated
// role.
$this->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, TRUE);
$this->setRolePermissions($this->admin_role, TRUE, FALSE);
$this->setRolePermissions($this->adminRole, TRUE, FALSE);
$this->assertCommentAccess(TRUE, 'Admin user has access comments permission and no search permission, but comments should be indexed because admin user inherits authenticated user\'s permission to search');
}
......@@ -219,13 +245,13 @@ function assertCommentAccess($assume_access, $message) {
// Search for the comment subject.
$edit = array(
'keys' => "'" . $this->comment_subject . "'",
'keys' => "'" . $this->commentSubject . "'",
);
$this->drupalPostForm('search/node', $edit, t('Search'));
if ($assume_access) {
$expected_node_result = $this->assertText($this->node->label());
$expected_comment_result = $this->assertText($this->comment_subject);
$expected_comment_result = $this->assertText($this->commentSubject);
}
else {
$expected_node_result = $this->assertText(t('Your search yielded no results.'));
......
......@@ -26,25 +26,25 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
*
* @var \Drupal\user\UserInterface
*/
public $search_user;
protected $searchUser;
/**
* Node indexed for searching.
*
* @var \Drupal\node\NodeInterface
*/
public $search_node;
protected $searchNode;
protected function setUp() {
parent::setUp();
// Login as a user that can create and search content.
$this->search_user = $this->drupalCreateUser(array('search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks', 'access site reports'));
$this->drupalLogin($this->search_user);
$this->searchUser = $this->drupalCreateUser(array('search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks', 'access site reports'));
$this->drupalLogin($this->searchUser);
// Add a single piece of content and index it.
$node = $this->drupalCreateNode();
$this->search_node = $node;
$this->searchNode = $node;
// Link the node to itself to test that it's only indexed once. The content
// also needs the word "pizza" so we can use it as the search keyword.
$body_key = 'body[0][value]';
......@@ -133,11 +133,11 @@ function testSearchModuleDisabling() {
$plugin_info = array(
'node_search' => array(
'keys' => 'pizza',
'text' => $this->search_node->label(),
'text' => $this->searchNode->label(),
),
'user_search' => array(
'keys' => $this->search_user->getUsername(),
'text' => $this->search_user->getEmail(),
'keys' => $this->searchUser->getUsername(),
'text' => $this->searchUser->getEmail(),
),
'dummy_search_type' => array(
'keys' => 'foo',
......
......@@ -23,13 +23,17 @@ class SearchEmbedFormTest extends SearchTestBase {
/**
* Node used for testing.
*
* @var \Drupal\node\NodeInterface
*/
public $node;
protected $node;
/**
* Count of how many times the form has been submitted.
*
* @var int
*/
public $submit_count = 0;
protected $submitCount = 0;
protected function setUp() {
parent::setUp();
......@@ -44,7 +48,7 @@ protected function setUp() {
search_update_totals();
// Set up a dummy initial count of times the form has been submitted.
$this->submit_count = \Drupal::state()->get('search_embedded_form.submit_count');
$this->submitCount = \Drupal::state()->get('search_embedded_form.submit_count');
$this->refreshVariables();
}
......@@ -58,8 +62,8 @@ function testEmbeddedForm() {
t('Send away'));
$this->assertText(t('Test form was submitted'), 'Form message appears');
$count = \Drupal::state()->get('search_embedded_form.submit_count');
$this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct');
$this->submit_count = $count;
$this->assertEqual($this->submitCount + 1, $count, 'Form submission count is correct');
$this->submitCount = $count;
// Now verify that we can see and submit the form from the search results.
$this->drupalGet('search/node', array('query' => array('keys' => $this->node->label())));
......@@ -69,8 +73,8 @@ function testEmbeddedForm() {
t('Send away'));
$this->assertText(t('Test form was submitted'), 'Form message appears');
$count = \Drupal::state()->get('search_embedded_form.submit_count');
$this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct');
$this->submit_count = $count;
$this->assertEqual($this->submitCount + 1, $count, 'Form submission count is correct');
$this->submitCount = $count;
// Now verify that if we submit the search form, it doesn't count as
// our form being submitted.
......@@ -79,7 +83,7 @@ function testEmbeddedForm() {
t('Search'));
$this->assertNoText(t('Test form was submitted'), 'Form message does not appear');
$count = \Drupal::state()->get('search_embedded_form.submit_count');
$this->assertEqual($this->submit_count, $count, 'Form submission count is correct');
$this->submit_count = $count;
$this->assertEqual($this->submitCount, $count, 'Form submission count is correct');
$this->submitCount = $count;
}
}
......@@ -25,13 +25,20 @@ class SearchKeywordsConditionsTest extends SearchTestBase {
*/
public static $modules = array('comment', 'search_extra_type');
/**
* A user with permission to search and post comments.
*
* @var \Drupal\user\UserInterface
*/
protected $searchingUser;
protected function setUp() {
parent::setUp();
// Create searching user.
$this->searching_user = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval'));
$this->searchingUser = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval'));
// Login with sufficient privileges.
$this->drupalLogin($this->searching_user);
$this->drupalLogin($this->searchingUser);
}
/**
......
......@@ -24,6 +24,13 @@ class SearchLanguageTest extends SearchTestBase {
*/
public static $modules = array('language');
/**
* Array of nodes available to search.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $searchableNodes;
protected function setUp() {
parent::setUp();
......@@ -63,20 +70,20 @@ protected function setUp() {
'langcode' => 'en',
),
);
$this->searchable_nodes = array();
$this->searchableNodes = [];
foreach ($nodes as $setting) {
$this->searchable_nodes[] = $this->drupalCreateNode($setting);
$this->searchableNodes[] = $this->drupalCreateNode($setting);
}
// Add English translation to the second node.
$translation = $this->searchable_nodes[1]->addTranslation('en', array('title' => 'Second node en'));
$translation = $this->searchableNodes[1]->addTranslation('en', array('title' => 'Second node en'));
$translation->body->value = $this->randomMachineName(32);
$this->searchable_nodes[1]->save();
$this->searchableNodes[1]->save();
// Add Spanish translation to the third node.
$translation = $this->searchable_nodes[2]->addTranslation('es', array('title' => 'Third node es'));
$translation = $this->searchableNodes[2]->addTranslation('es', array('title' => 'Third node es'));
$translation->body->value = $this->randomMachineName(32);
$this->searchable_nodes[2]->save();
$this->searchableNodes[2]->save();
// Update the index and then run the shutdown method.
$plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
......
......@@ -20,9 +20,9 @@ class SearchMultilingualEntityTest extends SearchTestBase {
/**
* List of searchable nodes.
*
* @var array
* @var \Drupal\node\NodeInterface[]
*/
protected $searchable_nodes = array();
protected $searchableNodes = array();
/**
* Node search plugin.
......@@ -97,22 +97,22 @@ protected function setUp() {
array(
),
);
$this->searchable_nodes = array();
$this->searchableNodes = array();
foreach ($nodes as $setting) {
$this->searchable_nodes[] = $this->drupalCreateNode($setting);
$this->searchableNodes[] = $this->drupalCreateNode($setting);
}
// Add a single translation to the second node.
$translation = $this->searchable_nodes[1]->addTranslation('hu', array('title' => 'Second node hu'));
$translation = $this->searchableNodes[1]->addTranslation('hu', array('title' => 'Second node hu'));
$translation->body->value = $this->randomMachineName(32);
$this->searchable_nodes[1]->save();
$this->searchableNodes[1]->save();
// Add two translations to the third node.
$translation = $this->searchable_nodes[2]->addTranslation('hu', array('title' => 'Third node this is the Hungarian title'));
$translation = $this->searchableNodes[2]->addTranslation('hu', array('title' => 'Third node this is the Hungarian title'));
$translation->body->value = $this->randomMachineName(32);
$translation = $this->searchable_nodes[2]->addTranslation('sv', array('title' => 'Third node sv'));
$translation = $this->searchableNodes[2]->addTranslation('sv', array('title' => 'Third node sv'));
$translation->body->value = $this->randomMachineName(32);
$this->searchable_nodes[2]->save();
$this->searchableNodes[2]->save();
// Verify that we have 8 nodes left to do.
$this->assertIndexCounts(8, 8, 'before updating the search index');
......@@ -196,7 +196,7 @@ function testMultilingualSearch() {
// Mark one of the nodes for reindexing, using the API function, and
// verify indexing status.
search_mark_for_reindex('node_search', $this->searchable_nodes[0]->id());
search_mark_for_reindex('node_search', $this->searchableNodes[0]->id());
$this->assertIndexCounts(1, 8, 'after marking one node to reindex via API function');
// Update the index and verify the totals again.
......@@ -206,7 +206,7 @@ function testMultilingualSearch() {
$this->assertIndexCounts(0, 8, 'after indexing again');
// Mark one node for reindexing by saving it, and verify indexing status.
$this->searchable_nodes[1]->save();
$this->searchableNodes[1]->save();
$this->assertIndexCounts(1, 8, 'after marking one node to reindex via save');
// The request time is always the same throughout test runs. Update the
......@@ -220,11 +220,11 @@ function testMultilingualSearch() {
->execute();
// Save the node again. Verify that the request time on it is not updated.
$this->searchable_nodes[1]->save();
$this->searchableNodes[1]->save();
$result = db_select('search_dataset', 'd')
->fields('d', array('reindex'))
->condition('type', 'node_search')
->condition('sid', $this->searchable_nodes[1]->id())
->condition('sid', $this->searchableNodes[1]->id())
->execute()
->fetchField();
$this->assertEqual($result, $old, 'Reindex time was not updated if node was already marked');
......@@ -232,7 +232,7 @@ function testMultilingualSearch() {
// Add a bogus entry to the search index table using a different search
// type. This will not appear in the index status, because it is not
// managed by a plugin.
search_index('foo', $this->searchable_nodes[0]->id(), 'en', 'some text');
search_index('foo', $this->searchableNodes[0]->id(), 'en', 'some text');
$this->assertIndexCounts(1, 8, 'after adding a different index item');
// Mark just this "foo" index for reindexing.
......@@ -245,13 +245,13 @@ function testMultilingualSearch() {
// Clear one item from the index, but with wrong language.
$this->assertDatabaseCounts(8, 1, 'before clear');
search_index_clear('node_search', $this->searchable_nodes[0]->id(), 'hu');
search_index_clear('node_search', $this->searchableNodes[0]->id(), 'hu');
$this->assertDatabaseCounts(8, 1, 'after clear with wrong language');
// Clear using correct language.
search_index_clear('node_search', $this->searchable_nodes[0]->id(), 'en');
search_index_clear('node_search', $this->searchableNodes[0]->id(), 'en');
$this->assertDatabaseCounts(7, 1, 'after clear with right language');
// Don't specify language.
search_index_clear('node_search', $this->searchable_nodes[1]->id());
search_index_clear('node_search', $this->searchableNodes[1]->id());
$this->assertDatabaseCounts(6, 1, 'unspecified language clear');
// Clear everything in 'foo'.
search_index_clear('foo');
......
......@@ -14,15 +14,20 @@
*/
class SearchNodePunctuationTest extends SearchTestBase {
public $test_user;
/**
* A user with permission to use advanced search.
*
* @var \Drupal\user\UserInterface
*/
public $testUser;
protected function setUp() {
parent::setUp();
node_access_rebuild();
// Create a test user and log in.
$this->test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search'));
$this->drupalLogin($this->test_user);
$this->testUser = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search'));
$this->drupalLogin($this->testUser);
}
/**
......
......@@ -20,14 +20,19 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
*/
public static $modules = array();
public $test_user;
/**
* A user with permission to access and search content.
*
* @var \Drupal\user\UserInterface
*/
public $testUser;
protected function setUp() {
parent::setUp();
// Create a test user and log in.
$this->test_user = $this->drupalCreateUser(array('access content', 'search content'));
$this->drupalLogin($this->test_user);
$this->testUser = $this->drupalCreateUser(array('access content', 'search content'));
$this->drupalLogin($this->testUser);
}
/**
......
......@@ -15,29 +15,45 @@
* @group search
*/
class SearchNumberMatchingTest extends SearchTestBase {
protected $test_user;
protected $numbers;
/**
* A user with permission to administer nodes.
*
* @var \Drupal\user\UserInterface
*/
protected $testUser;
/**
* An array of strings containing numbers to use for testing.
*
* Define a group of numbers that should all match each other --
* numbers with internal punctuation should match each other, as well
* as numbers with and without leading zeros and leading/trailing
* . and -.
*
* @var string[]
*/
protected $numbers = array(
'123456789',
'12/34/56789',
'12.3456789',
'12-34-56789',
'123,456,789',
'-123456789',
'0123456789',
);
/**
* An array of nodes created for testing purposes.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $nodes;
protected function setUp() {
parent::setUp();
$this->test_user = $this->drupalCreateUser(array('search content', 'access content', 'administer nodes', 'access site reports'));
$this->drupalLogin($this->test_user);
// Define a group of numbers that should all match each other --
// numbers with internal punctuation should match each other, as well
// as numbers with and without leading zeros and leading/trailing
// . and -.
$this->numbers = array(
'123456789',
'12/34/56789',
'12.3456789',
'12-34-56789',
'123,456,789',
'-123456789',
'0123456789',
);
$this->testUser = $this->drupalCreateUser(array('search content', 'access content', 'administer nodes', 'access site reports'));
$this->drupalLogin($this->testUser);
foreach ($this->numbers as $num) {
$info = array(
......
......@@ -15,35 +15,51 @@
* @group search
*/
class SearchNumbersTest extends SearchTestBase {
protected $test_user;
protected $numbers;
/**
* A user with permission to administer nodes.
*