function testEntitySourceListSearch() {
// We need a node with title composed of several words to test
// "any words" search.
$title_part_1 = $this
->randomMachineName(4);
$title_part_2 = $this
->randomMachineName(4);
$title_part_3 = $this
->randomMachineName(4);
$this->nodes['article']['en'][0]->title = "{$title_part_1} {$title_part_2} {$title_part_3}";
$this->nodes['article']['en'][0]
->save();
$this
->drupalGet('admin/tmgmt/sources/content/node');
$edit = array();
// There should be no result when the word sequence does not match.
$edit['search[title]'] = "{$title_part_1} {$title_part_3}";
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->pageTextNotContains("{$title_part_1} {$title_part_2} {$title_part_3}");
// Submit partial node title and see if we have a result.
$edit['search[title]'] = "{$title_part_1} {$title_part_2}";
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->pageTextContains("{$title_part_1} {$title_part_2} {$title_part_3}");
// Check if there is only one result in the list.
$search_result_rows = $this
->xpath('//table[@id="edit-items"]/tbody/tr');
$this
->assertCount(1, $search_result_rows, 'The search result must return only one row.');
// To test if other entity types work go for simple comment search.
$this
->addDefaultCommentField('node', 'article');
$content_translation_manager = \Drupal::service('content_translation.manager');
$content_translation_manager
->setEnabled('comment', 'comment', TRUE);
$values = array(
'entity_type' => 'node',
'entity_id' => $this->nodes['article']['en'][0]
->id(),
'field_name' => 'comment',
'comment_type' => 'comment',
'comment_body' => $this
->randomMachineName(),
'subject' => $this
->randomMachineName(),
);
$comment = Comment::create($values);
$comment
->save();
// Do search for the comment.
$this
->drupalGet('admin/tmgmt/sources/content/comment');
$edit = array();
$edit['search[subject]'] = $comment
->getSubject();
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->pageTextContains($comment
->getSubject());
// Tests that search bundle filter works.
$this
->drupalGet('/admin/tmgmt/sources/content/node');
$this
->submitForm([
'search[title]' => $this->nodes['article']['en'][0]
->label(),
], 'Search');
$this
->assertSession()
->pageTextContains('Content overview');
$this
->assertSession()
->pageTextContains($this->nodes['article']['en'][0]
->label());
$this
->submitForm([
'search[title]' => 'wrong_value',
], 'Search');
$this
->assertSession()
->pageTextContains('Content overview');
$this
->assertSession()
->pageTextNotContains($this->nodes['article']['en'][0]
->label());
$options = [
'query' => [
'any_key' => 'any_value',
],
];
$this
->drupalGet('/admin/tmgmt/sources/content/node', $options);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this->nodes['article']['en'][0]
->label());
// Test combined title and language filter.
$this
->drupalGet('/admin/tmgmt/sources/content/node');
$edit = [
'search[target_language]' => 'de',
'search[title]' => $this->nodes['article']['en'][0]
->label(),
];
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->linkExists($this->nodes['article']['en'][0]
->label());
}