class FileTranslatorTest in Translation Management Tool 8
Tests for the file translator.
@group tmgmt
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses FunctionalTestSetupTrait, TestSetupTrait, AssertLegacyTrait, BlockCreationTrait, ConfigTestTrait, ContentTypeCreationTrait, NodeCreationTrait, PhpunitCompatibilityTrait, RandomGeneratorTrait, TestRequirementsTrait, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\tmgmt\Functional\TMGMTTestBase uses TmgmtTestTrait
- class \Drupal\Tests\tmgmt_file\Functional\FileTranslatorTest
- class \Drupal\Tests\tmgmt\Functional\TMGMTTestBase uses TmgmtTestTrait
Expanded class hierarchy of FileTranslatorTest
File
- translators/
tmgmt_file/ tests/ src/ Functional/ FileTranslatorTest.php, line 18
Namespace
Drupal\Tests\tmgmt_file\FunctionalView source
class FileTranslatorTest extends TMGMTTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'tmgmt_file',
'tmgmt',
);
/**
* {@inheritdoc}
*/
function setUp() : void {
parent::setUp();
$this
->loginAsAdmin();
$this
->addLanguage('de');
}
/**
* Test the content processing for XLIFF export and import.
*/
public function testXLIFFTextProcessing() {
$translator = $this
->createTranslator([
'plugin' => 'file',
'settings' => [
'export_format' => 'xlf',
'xliff_processing' => TRUE,
'format_configuration' => [
'target' => '',
],
],
]);
// Get the source text.
$source_text = trim(file_get_contents(drupal_get_path('module', 'tmgmt') . '/tests/testing_html/sample.html'));
// Create the reader instance, it will be used through the tests.
$reader = new \XMLReader();
$xliff_elements = array(
'bpt',
'ept',
'ph',
'x',
'#text',
'#cdata-section',
'content',
);
// ==== First test the whole cycle ==== //
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->addItem('test_html_source', 'test', '1');
// Simulate an existing public://tmmgt_file directory that is not writable.
mkdir('public://tmgmt_file', 0555);
// Requesting translation will mask the html.
$job
->requestTranslation();
$content = $this
->getTransUnitsContent($job);
// Test that the exported trans unit contains only xliff elements.
$reader
->XML('<content>' . $content[0]['source'] . '</content>');
while ($reader
->read()) {
if (!in_array($reader->name, $xliff_elements)) {
$this
->fail(t('The source contains unexpected element %element', array(
'%element' => $reader->name,
)));
}
}
$reader
->XML('<content>' . $content[0]['target'] . '</content>');
while ($reader
->read()) {
if (!in_array($reader->name, $xliff_elements)) {
$this
->fail(t('The target contains unexpected element %element', array(
'%element' => $reader->name,
)));
}
}
// Import the file, make sure all the html has been revealed and no xliff
// elements are present in the job translation.
$messages = $job
->getMessages();
$message = reset($messages);
$translated_file = 'public://tmgmt_file/translated.xlf';
$this
->createTranslationFile($message->variables->{'@link'}, 'one paragraph', 'one translated paragraph', $translated_file);
$edit = array(
'files[file]' => $translated_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
// Reset caches and reload job.
\Drupal::entityTypeManager()
->getStorage('tmgmt_job')
->resetCache();
\Drupal::entityTypeManager()
->getStorage('tmgmt_job_item')
->resetCache();
$job = Job::load($job
->id());
// Do the comparison of the translation text and the source. It must be the
// same as there was no change done to the translation.
$item_data = $job
->getData(array(
1,
'dummy',
'deep_nesting',
));
$this
->assertEqual(trim($item_data[1]['#translation']['#text']), str_replace('one paragraph', 'one translated paragraph', $source_text));
$job_items = $job
->getItems();
$job_item = array_shift($job_items);
// Job item must be in review.
$this
->assertTrue($job_item
->isNeedsReview());
$this
->assertIntegrityCheck($job, FALSE);
// ==== Test integrity check ==== //
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->addItem('test_html_source', 'test', '1');
$job
->requestTranslation();
$messages = $job
->getMessages();
$message = reset($messages);
// Get the xml content and remove the element representing <br />. This will
// result in different element counts in the source and target and should
// trigger an error and not import the translation.
$translated_file = 'public://tmgmt_file/translated.xlf';
$this
->createTranslationFile($message->variables->{'@link'}, '<x id="tjiid2-4" ctype="lb"/>', '', $translated_file);
$edit = array(
'files[file]' => $translated_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
\Drupal::entityTypeManager()
->getStorage('tmgmt_job')
->resetCache();
\Drupal::entityTypeManager()
->getStorage('tmgmt_job_item')
->resetCache();
$job = Job::load($job
->id());
$this
->assertIntegrityCheck($job);
// Set the XLIFF processing to FALSE and test it results in the source
// text not being XLIFF processed.
$translator
->setSetting('xliff_processing', FALSE);
$translator
->save();
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->addItem('test_html_source', 'test', '1');
$job
->requestTranslation();
$targets = $this
->getTransUnitsContent($job);
$this
->assertEqual(trim(html_entity_decode($targets['0']['source'])), $source_text);
}
/**
* Test the CDATA option for XLIFF export and import.
*/
function testXLIFFCDATA() {
$translator = $this
->createTranslator([
'plugin' => 'file',
'settings' => [
'export_format' => 'xlf',
'xliff_cdata' => TRUE,
],
]);
// Get the source text.
$source_text = trim(file_get_contents(drupal_get_path('module', 'tmgmt') . '/tests/testing_html/sample.html'));
// Create a new job.
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->addItem('test_html_source', 'test', '1');
$job
->requestTranslation();
$messages = $job
->getMessages();
$message = reset($messages);
// Get XLIFF content.
$variables = $message->variables;
$download_url = $variables->{'@link'};
$this
->assertFalse((bool) strpos('< a', $download_url));
$xliff = file_get_contents($download_url);
$dom = new \DOMDocument();
$dom
->loadXML($xliff);
$this
->assertTrue($dom
->schemaValidate(drupal_get_path('module', 'tmgmt_file') . '/xliff-core-1.2-strict.xsd'));
// "Translate" items.
$xml = simplexml_import_dom($dom);
$translated_text = array();
foreach ($xml->file->body
->children() as $group) {
foreach ($group
->children() as $transunit) {
if ($transunit
->getName() == 'trans-unit') {
// The target should be empty.
$this
->assertEqual($transunit->target, '');
// Update translations using CDATA.
$node = dom_import_simplexml($transunit->target);
$owner = $node->ownerDocument;
$node
->appendChild($owner
->createCDATASection($xml->file['target-language'] . '_' . (string) $transunit->source));
// Store the text to allow assertions later on.
$translated_text[(string) $group['id']][(string) $transunit['id']] = (string) $transunit->target;
}
}
}
$translated_file = 'public://tmgmt_file/translated file.xlf';
$xml
->asXML($translated_file);
// Import the file and check translation for the "dummy" item.
$edit = array(
'files[file]' => $translated_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
// Reset caches and reload job.
\Drupal::entityTypeManager()
->getStorage('tmgmt_job')
->resetCache();
\Drupal::entityTypeManager()
->getStorage('tmgmt_job_item')
->resetCache();
$job = Job::load($job
->id());
$item_data = $job
->getData(array(
1,
'dummy',
'deep_nesting',
));
$this
->assertEqual(trim($item_data[1]['#translation']['#text']), str_replace($source_text, $xml->file['target-language'] . '_' . $source_text, $source_text));
}
/**
* Gets trans-unit content from the XLIFF file that has been exported for the
* given job as last.
*/
protected function getTransUnitsContent(JobInterface $job) {
$messages = $job
->getMessages();
$message = reset($messages);
$download_url = $message->variables->{'@link'};
$this
->assertFalse((bool) strpos('< a', $download_url));
$xml_string = file_get_contents($download_url);
$xml = simplexml_load_string($xml_string);
// Register the xliff namespace, required for xpath.
$xml
->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
$reader = new \XMLReader();
$data = array();
$i = 0;
foreach ($xml
->xpath('//xliff:trans-unit') as $unit) {
$reader
->XML($unit->source
->asXML());
$reader
->read();
$data[$i]['source'] = $reader
->readInnerXML();
$reader
->XML($unit->target
->asXML());
$reader
->read();
$data[$i]['target'] = $reader
->readInnerXML();
$i++;
}
return $data;
}
/**
* Tests export and import for the HTML format.
*/
function testHTML() {
$translator = Translator::load('file');
$translator
->setSetting('export_format', 'html')
->save();
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->addItem('test_source', 'test', '1');
$job
->addItem('test_source', 'test', '2');
$job
->requestTranslation();
$messages = $job
->getMessages();
$message = reset($messages);
$download_url = $message->variables->{'@link'};
$this
->assertFalse((bool) strpos('< a', $download_url));
// "Translate" items.
$xml = simplexml_load_file($download_url);
$translated_text = array();
foreach ($xml->body
->children() as $group) {
for ($i = 0; $i < $group
->count(); $i++) {
// This does not actually override the whole object, just the content.
$group->div[$i] = (string) $xml->head->meta[3]['content'] . '_' . (string) $group->div[$i];
// Store the text to allow assertions later on.
$translated_text[(string) $group['id']][(string) $group->div[$i]['id']] = (string) $group->div[$i];
}
}
$translated_file = 'public://tmgmt_file/translated.html';
$xml
->asXML($translated_file);
$this
->importFile($translated_file, $translated_text, $job);
}
/**
* Tests import and export for the XLIFF format.
*/
function testXLIFF() {
$translator = Translator::load('file');
$translator
->setSetting('export_format', 'xlf')
->setSetting('format_configuration', [
'target' => 'source',
])
->save();
// Set multiple data items for the source.
\Drupal::state()
->set('tmgmt.test_source_data', array(
'dummy' => array(
'deep_nesting' => array(
'#text' => file_get_contents(drupal_get_path('module', 'tmgmt') . '/tests/testing_html/sample.html') . ' @id.',
'#label' => 'Label of deep nested item @id',
),
'#label' => 'Dummy item',
),
'another_item' => array(
'#text' => 'Text of another item @id.',
'#label' => 'Label of another item @id.',
'#max_length' => '100',
),
));
$job = $this
->createJob();
$job->translator = $translator
->id();
$first_item = $job
->addItem('test_source', 'test', '1');
// Keep the first item data for later use.
$first_item_data = \Drupal::service('tmgmt.data')
->flatten($first_item
->getData());
$job
->addItem('test_source', 'test', '2');
$job
->requestTranslation();
$messages = $job
->getMessages();
$message = reset($messages);
$variables = $message->variables;
$download_url = $variables->{'@link'};
$this
->assertFalse((bool) strpos('< a', $download_url));
$xliff = file_get_contents($download_url);
$dom = new \DOMDocument();
$dom
->loadXML($xliff);
$this
->assertTrue($dom
->schemaValidate(drupal_get_path('module', 'tmgmt_file') . '/xliff-core-1.2-strict.xsd'));
// Build a list of expected note labels.
$expected_notes = [
'1][dummy][deep_nesting' => 'Dummy item > Label of deep nested item @id',
'1][another_item' => 'Label of another item @id.',
'2][dummy][deep_nesting' => 'Dummy item > Label of deep nested item @id',
'2][another_item' => 'Label of another item @id.',
];
// "Translate" items.
$xml = simplexml_import_dom($dom);
$translated_text = array();
foreach ($xml->file->body
->children() as $group) {
foreach ($group
->children() as $transunit) {
if ($transunit
->getName() == 'trans-unit') {
// The target should contain the source data.
$this
->assertEqual($transunit->target, $transunit->source);
// Assert that notes contain parent and non-parent labels.
$this
->assertEqual($expected_notes[(string) $transunit['id']], (string) $transunit->note);
$transunit->target = $xml->file['target-language'] . '_' . (string) $transunit->source;
// Store the text to allow assertions later on.
$translated_text[(string) $group['id']][(string) $transunit['id']] = (string) $transunit->target;
// Check that the character limit is in the target.
$attributes = $transunit
->attributes();
if ($transunit
->attributes()['id'] == '1][another_item') {
$this
->assertEquals('100', $attributes['maxwidth']);
$this
->assertEquals('char', $attributes['size-unit']);
}
if ($transunit
->attributes()['id'] == '1][dummy][deep_nesting') {
$this
->assertFalse(isset($attributes['maxwidth']));
$this
->assertFalse(isset($attributes['size-unit']));
}
}
}
}
// Change the job id to a non-existing one and try to import it.
$wrong_xml = clone $xml;
$wrong_xml->file->header->{'phase-group'}->phase['job-id'] = 500;
$wrong_file = 'public://tmgmt_file/wrong_file.xlf';
$wrong_xml
->asXML($wrong_file);
$edit = array(
'files[file]' => $wrong_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
$this
->assertText(t('Failed to validate file, import aborted.'));
// Change the job id to a wrong one and try to import it.
$wrong_xml = clone $xml;
$second_job = $this
->createJob();
$second_job->translator = $translator
->id();
// We need to add the elements count value into settings, otherwise the
// validation will fail on integrity check.
$xliff_validation = array(
1 => 0,
2 => 0,
);
$second_job->settings->xliff_validation = $xliff_validation;
$second_job
->save();
$wrong_xml->file->header->{'phase-group'}->phase['job-id'] = $second_job
->id();
$wrong_file = 'public://tmgmt_file/wrong_file.xlf';
$wrong_xml
->asXML($wrong_file);
$edit = array(
'files[file]' => $wrong_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
$this
->assertRaw(t('The imported file job id @file_id does not match the job id @job_id.', array(
'@file_id' => $second_job
->id(),
'@job_id' => $job
->id(),
)));
$translated_file = 'public://tmgmt_file/translated file.xlf';
$xml
->asXML($translated_file);
// Import the file and accept translation for the "dummy" item.
$edit = array(
'files[file]' => $translated_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
$this
->assertText(t('The translation of @job_item to German is finished and can now be reviewed.', [
'@job_item' => $first_item
->label(),
]));
$this
->clickLink(t('Review'));
$this
->getSession()
->getPage()
->pressButton('reviewed-dummy|deep_nesting');
// Update the translation for "another" item and import.
$xml->file->body->group[0]->{'trans-unit'}[1]->target = $xml->file->body->group[0]->{'trans-unit'}[1]->target . ' updated';
$xml
->asXML($translated_file);
$edit = array(
'files[file]' => $translated_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
// At this point we must have the "dummy" item accepted and intact. The
// "another" item must have updated translation.
$this
->assertText('Review');
$this
->drupalGet($first_item
->toUrl());
$this
->assertFieldByName('dummy|deep_nesting[translation]', 'de_' . $first_item_data['dummy][deep_nesting']['#text']);
$this
->assertFieldByName('another_item[translation]', 'de_' . $first_item_data['another_item']['#text'] . ' updated');
// Now finish the import/save as completed process doing another extra
// import. The extra import will test that a duplicate import of the same
// file does not break the process.
$this
->importFile($translated_file, $translated_text, $job);
$this
->assertNoText(t('Import translated file'));
// Create a job, assign to the file translator and delete before attaching
// a file.
$other_job = $this
->createJob();
$other_job->translator = $translator
->id();
$other_job
->save();
$other_job
->delete();
// Make sure the file of the other job still exists.
$response = \Drupal::httpClient()
->get($download_url);
$this
->assertEqual(200, $response
->getStatusCode());
// Delete the job and then make sure that the file has been deleted.
$job
->delete();
try {
$response = \Drupal::httpClient()
->get($download_url);
$this
->fail('Expected exception not thrown.');
} catch (RequestException $e) {
$this
->assertEqual(404, $e
->getResponse()
->getStatusCode());
}
}
/**
* Tests storing files in the private file system.
*/
function testPrivate() {
// Create a translator using the private file system.
// @todo: Test the configuration UI.
$translator = $this
->createTranslator([
'plugin' => 'file',
'settings' => [
'export_format' => 'xlf',
'xliff_processing' => TRUE,
'scheme' => 'private',
],
]);
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->addItem('test_source', 'test', '1');
$job
->addItem('test_source', 'test', '2');
$job
->requestTranslation();
$messages = $job
->getMessages();
$message = reset($messages);
$this
->drupalGet('admin/tmgmt/jobs');
$this
->clickLink(t('Manage'));
// Assert that the label field is only shown once in page.
$this
->assertEqual(count($this
->xpath('//div[@id="tmgmt-ui-label"]')), 1);
$download_url = $message->variables->{'@link'};
$this
->assertFalse((bool) strpos('< a', $download_url));
$this
->drupalGet($download_url);
// Verify that the URL is served using the private file system and the
// access checks work.
$this
->assertNotEmpty(preg_match('|system/files|', $download_url));
$this
->assertResponse(200);
$this
->drupalLogout();
// Verify that access is now protected.
$this
->drupalGet($download_url);
$this
->assertResponse(403);
}
protected function importFile($translated_file, $translated_text, JobInterface $job) {
// To test the upload form functionality, navigate to the edit form.
$edit = array(
'files[file]' => $translated_file,
);
$this
->drupalPostForm($job
->toUrl(), $edit, t('Import'));
// Make sure the translations have been imported correctly.
$this
->assertNoRaw('title="In progress"');
// @todo: Enable this assertion once new releases for views and entity
// module are out.
//$this->assertText(t('Needs review'));
// Review both items.
list($item1, $item2) = array_values($job
->getItems());
$this
->drupalGet($item1
->toUrl());
foreach ($translated_text[1] as $key => $value) {
$this
->assertText(Html::escape($value));
}
foreach ($translated_text[2] as $key => $value) {
$this
->assertNoText(Html::escape($value));
}
$this
->drupalPostForm(NULL, array(), t('Save as completed'));
// Review both items.
$this
->drupalGet($item2
->toUrl());
foreach ($translated_text[1] as $key => $value) {
$this
->assertNoText(Html::escape($value));
}
foreach ($translated_text[2] as $key => $value) {
$this
->assertText(Html::escape($value));
}
$this
->drupalPostForm(NULL, array(), t('Save as completed'));
// @todo: Enable this assertion once new releases for views and entity
// module are out.
//$this->assertText(t('Accepted'));
$this
->assertText(t('Finished'));
$this
->assertNoRaw('title="Needs review"');
}
/**
* Creates a translated XLIFF file based on the replacement definition.
*
* @param string $source_file
* Source file name.
* @param $search
* String to search in the source.
* @param $replace
* String to replace it with in the target.
* @param $translated_file
* Name of the file to write.
*/
protected function createTranslationFile($source_file, $search, $replace, $translated_file) {
$xml_string = file_get_contents($source_file);
preg_match('/<source xml:lang="en">(.+)<\\/source>/s', $xml_string, $matches);
$target = str_replace($search, $replace, $matches[1]);
if ($replace) {
$this
->assertTrue(strpos($target, $replace) !== FALSE, 'String replaced in translation');
}
$translated_xml_string = str_replace('<target xml:lang="de"/>', '<target xml:lang="de">' . $target . '</target>', $xml_string);
file_put_contents($translated_file, $translated_xml_string);
}
/**
* Asserts import integrity for a job.
*
* @param \Drupal\tmgmt\JobInterface $job
* The job to check.
* @param bool $expected
* (optional) If an integrity failed message is expected or not, defaults
* to FALSE.
*/
protected function assertIntegrityCheck(JobInterface $job, $expected = TRUE) {
$integrity_check_failed = FALSE;
/** @var \Drupal\tmgmt\MessageInterface $message */
foreach ($job
->getMessages() as $message) {
if ($message
->getMessage() == new TranslatableMarkup('Failed to validate semantic integrity of %key element. Please check also the HTML code of the element in the review process.', array(
'%key' => 'dummy][deep_nesting',
))) {
$integrity_check_failed = TRUE;
break;
}
}
// Check if the message was found or not, based on the expected argument.
if ($expected) {
$this
->assertTrue($integrity_check_failed, 'The validation of semantic integrity must fail.');
}
else {
$this
->assertFalse($integrity_check_failed, 'The validation of semantic integrity must not fail.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertHelperTrait:: |
protected static | function | Casts MarkupInterface objects into strings. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | Asserts whether an expected cache tag was present in the last response. | |
AssertLegacyTrait:: |
protected | function | Asserts that the element with the given CSS selector is not present. | |
AssertLegacyTrait:: |
protected | function | Asserts that the element with the given CSS selector is present. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertLegacyTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertLegacyTrait:: |
protected | function | Checks that current response header equals value. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertLegacyTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertLegacyTrait:: |
protected | function | Asserts whether an expected cache tag was absent in the last response. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text is not found escaped on the loaded page. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does NOT exist with the given name or ID. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertLegacyTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertLegacyTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertLegacyTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertLegacyTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option does NOT exist in the current page. | |
AssertLegacyTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is not found in the raw content. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS not found on the loaded page, fail otherwise. | 1 |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | 1 |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead. | |
AssertLegacyTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option with the visible text exists. | |
AssertLegacyTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertLegacyTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertLegacyTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | 1 |
AssertLegacyTrait:: |
protected | function | Asserts the page responds with the specified response code. | 1 |
AssertLegacyTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | 1 |
AssertLegacyTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertLegacyTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertLegacyTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertLegacyTrait:: |
protected | function | Passes if the internal browser's URL matches the given path. | |
AssertLegacyTrait:: |
protected | function | Builds an XPath query. | |
AssertLegacyTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertLegacyTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertLegacyTrait:: |
protected | function | Gets the current raw content. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | ||
BlockCreationTrait:: |
protected | function | Creates a block instance based on default settings. Aliased as: drupalPlaceBlock | |
BrowserHtmlDebugTrait:: |
protected | property | The Base URI to use for links to the output files. | |
BrowserHtmlDebugTrait:: |
protected | property | Class name for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | Counter for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | Counter storage for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | Directory name for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | property | HTML output output enabled. | |
BrowserHtmlDebugTrait:: |
protected | property | The file name to write the list of URLs to. | |
BrowserHtmlDebugTrait:: |
protected | property | HTML output test ID. | |
BrowserHtmlDebugTrait:: |
protected | function | Formats HTTP headers as string for HTML output logging. | |
BrowserHtmlDebugTrait:: |
protected | function | Returns headers in HTML output format. | 1 |
BrowserHtmlDebugTrait:: |
protected | function | Logs a HTML output message in a text file. | |
BrowserHtmlDebugTrait:: |
protected | function | Creates the directory to store browser output. | |
BrowserTestBase:: |
protected | property | The base URL. | |
BrowserTestBase:: |
protected | property | The config importer that can be used in a test. | |
BrowserTestBase:: |
protected | property | An array of custom translations suitable for drupal_rewrite_settings(). | |
BrowserTestBase:: |
protected | property | The database prefix of this test run. | |
BrowserTestBase:: |
protected | property | Mink session manager. | |
BrowserTestBase:: |
protected | property | ||
BrowserTestBase:: |
protected | property | 1 | |
BrowserTestBase:: |
protected | property | The original container. | |
BrowserTestBase:: |
protected | property | The original array of shutdown function callbacks. | |
BrowserTestBase:: |
protected | property | ||
BrowserTestBase:: |
protected | property | The profile to install as a basis for testing. | 39 |
BrowserTestBase:: |
protected | property | The app root. | |
BrowserTestBase:: |
protected | property | Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests. | |
BrowserTestBase:: |
protected | property | Time limit in seconds for the test. | |
BrowserTestBase:: |
protected | property | The translation file directory for the test environment. | |
BrowserTestBase:: |
protected | function | Clean up the Simpletest environment. | |
BrowserTestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
BrowserTestBase:: |
protected | function | Translates a CSS expression to its XPath equivalent. | |
BrowserTestBase:: |
protected | function | Gets the value of an HTTP response header. | |
BrowserTestBase:: |
protected | function | Returns all response headers. | |
BrowserTestBase:: |
public static | function | Ensures test files are deletable. | |
BrowserTestBase:: |
protected | function | Gets an instance of the default Mink driver. | |
BrowserTestBase:: |
protected | function | Gets the JavaScript drupalSettings variable for the currently-loaded page. | 1 |
BrowserTestBase:: |
protected | function | Obtain the HTTP client for the system under test. | |
BrowserTestBase:: |
protected | function | Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. | 1 |
BrowserTestBase:: |
protected | function | Helper function to get the options of select field. | |
BrowserTestBase:: |
protected | function |
Provides a Guzzle middleware handler to log every response received. Overrides BrowserHtmlDebugTrait:: |
|
BrowserTestBase:: |
public | function | Returns Mink session. | |
BrowserTestBase:: |
protected | function | Get session cookies from current session. | |
BrowserTestBase:: |
protected | function |
Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait:: |
|
BrowserTestBase:: |
protected | function | Visits the front page when initializing Mink. | 3 |
BrowserTestBase:: |
protected | function | Initializes Mink sessions. | 1 |
BrowserTestBase:: |
public | function | Installs Drupal into the Simpletest site. | 1 |
BrowserTestBase:: |
protected | function | Registers additional Mink sessions. | |
BrowserTestBase:: |
protected | function | 3 | |
BrowserTestBase:: |
protected | function | Transforms a nested array into a flat array suitable for drupalPostForm(). | |
BrowserTestBase:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
BrowserTestBase:: |
public | function | 1 | |
BrowserTestBase:: |
public | function | Prevents serializing any properties. | |
ConfigTestTrait:: |
protected | function | Returns a ConfigImporter object to import test configuration. | |
ConfigTestTrait:: |
protected | function | Copies configuration objects from source storage to target storage. | |
ContentTypeCreationTrait:: |
protected | function | Creates a custom content type based on default settings. Aliased as: drupalCreateContentType | 1 |
FileTranslatorTest:: |
public static | property |
Modules to enable. Overrides TMGMTTestBase:: |
|
FileTranslatorTest:: |
protected | function | Asserts import integrity for a job. | |
FileTranslatorTest:: |
protected | function | Creates a translated XLIFF file based on the replacement definition. | |
FileTranslatorTest:: |
protected | function | Gets trans-unit content from the XLIFF file that has been exported for the given job as last. | |
FileTranslatorTest:: |
protected | function | ||
FileTranslatorTest:: |
function |
Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase:: |
||
FileTranslatorTest:: |
function | Tests export and import for the HTML format. | ||
FileTranslatorTest:: |
function | Tests storing files in the private file system. | ||
FileTranslatorTest:: |
function | Tests import and export for the XLIFF format. | ||
FileTranslatorTest:: |
function | Test the CDATA option for XLIFF export and import. | ||
FileTranslatorTest:: |
public | function | Test the content processing for XLIFF export and import. | |
FunctionalTestSetupTrait:: |
protected | property | The flag to set 'apcu_ensure_unique_prefix' setting. | 1 |
FunctionalTestSetupTrait:: |
protected | property | The class loader to use for installation and initialization of setup. | |
FunctionalTestSetupTrait:: |
protected | property | The config directories used in this test. | |
FunctionalTestSetupTrait:: |
protected | property | The "#1" admin user. | |
FunctionalTestSetupTrait:: |
protected | function | Execute the non-interactive installer. | 1 |
FunctionalTestSetupTrait:: |
protected | function | Returns all supported database driver installer objects. | |
FunctionalTestSetupTrait:: |
protected | function | Initialize various configurations post-installation. | 2 |
FunctionalTestSetupTrait:: |
protected | function | Initializes the kernel after installation. | |
FunctionalTestSetupTrait:: |
protected | function | Initialize settings created during install. | |
FunctionalTestSetupTrait:: |
protected | function | Initializes user 1 for the site to be installed. | |
FunctionalTestSetupTrait:: |
protected | function | Installs the default theme defined by `static::$defaultTheme` when needed. | |
FunctionalTestSetupTrait:: |
protected | function | Install modules defined by `static::$modules`. | 1 |
FunctionalTestSetupTrait:: |
protected | function | Returns the parameters that will be used when Simpletest installs Drupal. | 9 |
FunctionalTestSetupTrait:: |
protected | function | Prepares the current environment for running the test. | 23 |
FunctionalTestSetupTrait:: |
protected | function | Creates a mock request and sets it on the generator. | |
FunctionalTestSetupTrait:: |
protected | function | Prepares site settings and services before installation. | 2 |
FunctionalTestSetupTrait:: |
protected | function | Resets and rebuilds the environment after setup. | |
FunctionalTestSetupTrait:: |
protected | function | Rebuilds \Drupal::getContainer(). | |
FunctionalTestSetupTrait:: |
protected | function | Resets all data structures after having enabled new modules. | |
FunctionalTestSetupTrait:: |
protected | function | Changes parameters in the services.yml file. | |
FunctionalTestSetupTrait:: |
protected | function | Sets up the base URL based upon the environment variable. | |
FunctionalTestSetupTrait:: |
protected | function | Rewrites the settings.php file of the test site. | |
NodeCreationTrait:: |
protected | function | Creates a node based on default settings. Aliased as: drupalCreateNode | |
NodeCreationTrait:: |
public | function | Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | 1 |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
RefreshVariablesTrait:: |
protected | function | Refreshes in-memory configuration and state information. | 3 |
SessionTestTrait:: |
protected | property | The name of the session cookie. | |
SessionTestTrait:: |
protected | function | Generates a session cookie name. | |
SessionTestTrait:: |
protected | function | Returns the session name in use on the child site. | |
StorageCopyTrait:: |
protected static | function | Copy the configuration from one storage to another and remove stale items. | |
TestRequirementsTrait:: |
private | function | Checks missing module requirements. | |
TestRequirementsTrait:: |
protected | function | Check module requirements for the Drupal use case. | 1 |
TestRequirementsTrait:: |
protected static | function | Returns the Drupal root directory. | |
TestSetupTrait:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
TestSetupTrait:: |
protected | property | The dependency injection container used in the test. | |
TestSetupTrait:: |
protected | property | The DrupalKernel instance used in the test. | |
TestSetupTrait:: |
protected | property | The site directory of the original parent site. | |
TestSetupTrait:: |
protected | property | The private file directory for the test environment. | |
TestSetupTrait:: |
protected | property | The public file directory for the test environment. | |
TestSetupTrait:: |
protected | property | The site directory of this test run. | |
TestSetupTrait:: |
protected | property | Set to TRUE to strict check all configuration saved. | 2 |
TestSetupTrait:: |
protected | property | The temporary file directory for the test environment. | |
TestSetupTrait:: |
protected | property | The test run ID. | |
TestSetupTrait:: |
protected | function | Changes the database connection to the prefixed one. | |
TestSetupTrait:: |
protected | function | Gets the config schema exclusions for this test. | |
TestSetupTrait:: |
public static | function | Returns the database connection to the site running Simpletest. | |
TestSetupTrait:: |
protected | function | Generates a database prefix for running tests. | 2 |
TMGMTTestBase:: |
protected | property |
The theme to install as the default for testing. Overrides BrowserTestBase:: |
|
TMGMTTestBase:: |
protected | property | A default translator using the test translator. | |
TmgmtTestTrait:: |
protected | property | List of permissions used by loginAsAdmin(). | |
TmgmtTestTrait:: |
protected | property | Drupal user object created by loginAsAdmin(). | |
TmgmtTestTrait:: |
protected | property | The language weight for new languages. | |
TmgmtTestTrait:: |
protected | property | List of permissions used by loginAsTranslator(). | |
TmgmtTestTrait:: |
protected | property | Drupal user object created by loginAsTranslator(). | |
TmgmtTestTrait:: |
function | Sets the proper environment. | ||
TmgmtTestTrait:: |
function | Asserts job item language codes. | ||
TmgmtTestTrait:: |
protected | function | Asserts text in the page with an xpath expression. | |
TmgmtTestTrait:: |
function | Clicks on an image link with the provided title attribute. | ||
TmgmtTestTrait:: |
function | Creates, saves and returns a translation job. | ||
TmgmtTestTrait:: |
function | Creates, saves and returns a translator. | ||
TmgmtTestTrait:: |
function | Will create a user with admin permissions and log it in. | ||
TmgmtTestTrait:: |
function | Will create a user with translator permissions and log it in. | ||
UiHelperTrait:: |
protected | property | The current user logged in using the Mink controlled browser. | |
UiHelperTrait:: |
protected | property | The number of meta refresh redirects to follow, or NULL if unlimited. | |
UiHelperTrait:: |
protected | property | The number of meta refresh redirects followed during ::drupalGet(). | |
UiHelperTrait:: |
public | function | Returns WebAssert object. | 1 |
UiHelperTrait:: |
protected | function | Builds an a absolute URL from a system path or a URL object. | |
UiHelperTrait:: |
protected | function | Checks for meta refresh tag and if found call drupalGet() recursively. | |
UiHelperTrait:: |
protected | function | Clicks the element with the given CSS selector. | |
UiHelperTrait:: |
protected | function | Follows a link by complete name. | |
UiHelperTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
UiHelperTrait:: |
protected | function | Retrieves a Drupal path or an absolute path. | 3 |
UiHelperTrait:: |
protected | function | Logs in a user using the Mink controlled browser. | |
UiHelperTrait:: |
protected | function | Logs a user out of the Mink controlled browser and confirms. | |
UiHelperTrait:: |
protected | function | Executes a form submission. | |
UiHelperTrait:: |
protected | function | Returns whether a given user account is logged in. | |
UiHelperTrait:: |
protected | function | Takes a path and returns an absolute path. | |
UiHelperTrait:: |
protected | function | Retrieves the plain-text content from the current page. | |
UiHelperTrait:: |
protected | function | Get the current URL from the browser. | |
UiHelperTrait:: |
protected | function | Prepare for a request to testing site. | 1 |
UiHelperTrait:: |
protected | function | Fills and submits a form. | |
UserCreationTrait:: |
protected | function | Checks whether a given list of permission names is valid. | |
UserCreationTrait:: |
protected | function | Creates an administrative role. | |
UserCreationTrait:: |
protected | function | Creates a role with specified permissions. Aliased as: drupalCreateRole | |
UserCreationTrait:: |
protected | function | Create a user with a given set of permissions. Aliased as: drupalCreateUser | |
UserCreationTrait:: |
protected | function | Grant permissions to a user role. | |
UserCreationTrait:: |
protected | function | Switch the current logged in user. | |
UserCreationTrait:: |
protected | function | Creates a random user account and sets it as current user. | |
XdebugRequestTrait:: |
protected | function | Adds xdebug cookies, from request setup. |