<?php
namespace Drupal\Tests\tmgmt\Kernel;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\KernelTests\KernelTestBase;
use Drupal\tmgmt\Entity\Translator;
use Drupal\tmgmt\JobItemInterface;
abstract class TMGMTKernelTestBase extends KernelTestBase {
protected $default_translator;
protected static $modules = array(
'user',
'system',
'field',
'text',
'entity_test',
'language',
'locale',
'tmgmt',
'tmgmt_test',
'options',
);
function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('tmgmt_job');
$this
->installEntitySchema('tmgmt_job_item');
$this
->installEntitySchema('tmgmt_message');
$this->default_translator = Translator::create([
'name' => 'test_translator',
'plugin' => 'test_translator',
'remote_languages_mappings' => [],
]);
$this->default_translator
->save();
$this
->addLanguage('de');
}
function createTranslator() {
$translator = Translator::create([
'name' => strtolower($this
->randomMachineName()),
'label' => $this
->randomMachineName(),
'plugin' => 'test_translator',
'remote_languages_mappings' => [],
'settings' => [
'key' => $this
->randomMachineName(),
'another_key' => $this
->randomMachineName(),
],
]);
$this
->assertEquals(SAVED_NEW, $translator
->save());
return $translator;
}
protected function createJob($source = 'en', $target = 'de', $uid = 0, array $values = array()) {
$job = tmgmt_job_create($source, $target, $uid, $values);
$this
->assertEquals(SAVED_NEW, $job
->save());
$this
->assertTrue($job
->id() > 0);
return $job;
}
function addLanguage($langcode) {
$language = ConfigurableLanguage::createFromLangcode($langcode);
$language
->save();
}
function assertJobItemLangCodes(JobItemInterface $job_item, $expected_source_lang, array $actual_lang_codes) {
$this
->assertEquals($expected_source_lang, $job_item
->getSourceLangCode());
$existing = $job_item
->getExistingLangCodes();
sort($existing);
sort($actual_lang_codes);
$this
->assertEquals($actual_lang_codes, $existing);
}
}