<?php
namespace Drupal\Tests\tmgmt_demo\Functional;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\tmgmt\Functional\TMGMTTestBase;
class TMGMTDemoTest extends TMGMTTestBase {
protected static $modules = array(
'tmgmt_demo',
'ckeditor5',
);
public function setUp() : void {
parent::setUp();
$basic_html_format = FilterFormat::load('basic_html');
$restricted_html_format = FilterFormat::create(array(
'format' => 'restricted_html',
'name' => 'Restricted HTML',
));
$restricted_html_format
->save();
$full_html_format = FilterFormat::create(array(
'format' => 'full_html',
'name' => 'Full HTML',
));
$full_html_format
->save();
$this
->loginAsAdmin([
'access content overview',
'administer tmgmt',
'translate any entity',
'edit any translatable_node content',
$basic_html_format
->getPermissionName(),
$restricted_html_format
->getPermissionName(),
$full_html_format
->getPermissionName(),
]);
}
public function testInstalled() {
$this
->drupalGet('node');
$this
->assertSession()
->pageTextContains('First node');
$this
->assertSession()
->pageTextContains('Second node');
$this
->assertSession()
->pageTextContains('TMGMT Demo');
$this
->clickLink('First node');
$this
->clickLink('Translate');
$edit = [
'languages[de]' => TRUE,
'languages[fr]' => TRUE,
];
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('2 jobs need to be checked out.');
$this
->drupalGet('admin/content');
$this
->clickLink('Second node');
$this
->clickLink('Translate');
$this
->submitForm($edit, 'Request translation');
$this
->assertSession()
->pageTextContains('2 jobs need to be checked out.');
$edit = [
'translator' => 'local',
];
$this
->submitForm($edit, 'Submit to provider and continue');
$this
->assertSession()
->pageTextContains('The translation job has been submitted.');
$this
->drupalGet('admin/tmgmt/sources');
$this
->submitForm([], 'Request translation');
$this
->assertSession()
->pageTextContainsOnce("You didn't select any source items.");
$this
->submitForm([], 'Search');
$this
->assertSession()
->pageTextNotContains("You didn't select any source items.");
$this
->submitForm([], 'Cancel');
$this
->assertSession()
->pageTextNotContains("You didn't select any source items.");
$this
->submitForm([], 'Add to cart');
$this
->assertSession()
->pageTextContainsOnce("You didn't select any source items.");
$this
->drupalGet('node/1/edit');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-body-0-format--2', 'basic_html')
->isSelected());
$this
->drupalGet('node/2/edit');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-body-0-format--2', 'restricted_html')
->isSelected());
$this
->drupalGet('node/3/edit');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-body-0-format--2', 'full_html')
->isSelected());
}
}