function ContentTmgmtEntitySourceListTest::testEntitySourceListSearch in Translation Management Tool 8
File
- sources/content/tests/src/Functional/ContentTmgmtEntitySourceListTest.php, line 353
Class
- ContentTmgmtEntitySourceListTest
- Tests the user interface for entity translation lists.
Namespace
Drupal\Tests\tmgmt_content\Functional
Code
function testEntitySourceListSearch() {
$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();
$edit = array();
$edit['search[title]'] = "{$title_part_1} {$title_part_3}";
$this
->drupalPostForm('admin/tmgmt/sources/content/node', $edit, t('Search'));
$this
->assertSession()
->pageTextContains("{$title_part_1} {$title_part_2} {$title_part_3}", 'Searching on partial node title must return the result.');
$search_result_rows = $this
->xpath('//table[@id="edit-items"]/tbody/tr');
$this
->assert(count($search_result_rows) == 1, 'The search result must return only one row.');
$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();
$edit = array();
$edit['search[subject]'] = $comment
->getSubject();
$this
->drupalPostForm('admin/tmgmt/sources/content/comment', $edit, t('Search'));
$this
->assertSession()
->pageTextContains($comment
->getSubject(), 'Searching for a comment subject.');
$this
->drupalPostForm('/admin/tmgmt/sources/content/node', [
'search[title]' => $this->nodes['article']['en'][0]
->label(),
], 'Search');
$this
->assertSession()
->pageTextContains(t('Content overview'));
$this
->assertSession()
->pageTextContains($this->nodes['article']['en'][0]
->label());
$this
->drupalPostForm('/admin/tmgmt/sources/content/node', [
'search[title]' => 'wrong_value',
], 'Search');
$this
->assertSession()
->pageTextContains(t('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());
$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());
}