View source
<?php
namespace Drupal\tmgmt_smartling\Tests;
use Drupal;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Queue\DatabaseQueue;
use Drupal\node\Entity\Node;
class LoggingTest extends SmartlingTestBase {
public function setUp() {
parent::setUp();
$uploadQueue = new DatabaseQueue('tmgmt_extension_suit_upload', Database::getConnection());
$database_schema = Drupal::database()
->schema();
try {
if (!$database_schema
->tableExists('queue')) {
$schema_definition = $uploadQueue
->schemaDefinition();
$database_schema
->createTable('queue', $schema_definition);
}
} catch (SchemaObjectExistsException $e) {
}
$this
->drupalPostForm('/admin/tmgmt/translators/manage/smartling', [
'settings[project_id]' => $this->smartlingPluginProviderSettings['settings[project_id]'],
'settings[user_id]' => $this->smartlingPluginProviderSettings['settings[user_id]'],
'settings[token_secret]' => $this->smartlingPluginProviderSettings['settings[token_secret]'],
'settings[contextUsername]' => $this->smartlingPluginProviderSettings['settings[contextUsername]'],
'settings[context_silent_user_switching]' => $this->smartlingPluginProviderSettings['settings[context_silent_user_switching]'],
'settings[retrieval_type]' => $this->smartlingPluginProviderSettings['settings[retrieval_type]'],
'settings[auto_authorize_locales]' => $this->smartlingPluginProviderSettings['settings[auto_authorize_locales]'],
'settings[callback_url_use]' => $this->smartlingPluginProviderSettings['settings[callback_url_use]'],
'settings[callback_url_host]' => $this->smartlingPluginProviderSettings['settings[callback_url_host]'],
'settings[scheme]' => $this->smartlingPluginProviderSettings['settings[scheme]'],
'settings[custom_regexp_placeholder]' => $this->smartlingPluginProviderSettings['settings[custom_regexp_placeholder]'],
'settings[export_format]' => $this->smartlingPluginProviderSettings['settings[export_format]'],
], t('Save'));
}
public function testRequestTranslationEventLogging() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this
->drupalPostForm('/admin/tmgmt/sources', [
'items[1]' => 1,
], t('Request translation'));
$this
->drupalPostForm(NULL, [
'target_language' => 'de',
], t('Submit to provider'));
$this
->drupalGet('/admin/reports/dblog');
$this
->assertRaw('File upload triggered (request translation). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload queued (request translation in a batch). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload triggered (view action). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload queued (track entity changes). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File uploaded. Job id: 2, file name: JobID2_en_fr.xml.');
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testRequestTranslationInABatchEventLogging() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this
->drupalPostForm('/admin/tmgmt/sources', [
'items[1]' => 1,
], t('Request translation in a batch'));
$this
->drupalPostForm(NULL, [
'target_language[de]' => 'de',
'translator' => 'smartling',
], t('Request translation'));
$this
->drupalGet('/admin/reports/dblog');
$this
->assertNoRaw('File upload triggered (request translation). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertRaw('File upload queued (request translation in a batch). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload triggered (view action). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload queued (track entity changes). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testViewActionEventLogging() {
if (!empty($this->smartlingPluginProviderSettings)) {
$translator = $this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$this
->requestTranslationForNode($this->testNodeId, 'de', $translator);
$this
->drupalPostForm('/admin/reports/dblog/confirm', [], t('Confirm'));
$this
->drupalPostForm('/admin/tmgmt/jobs', [
'tmgmt_job_bulk_form[0]' => '',
'action' => 'tmgmt_extension_suit_upload_job_action_id',
], t('Apply to selected items'));
$this
->drupalPostForm(NULL, [], t('Send for Translation'));
$this
->drupalGet('/admin/reports/dblog');
$this
->assertNoRaw('File upload triggered (request translation). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload queued (request translation in a batch). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertRaw('File upload triggered (view action). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload queued (track entity changes). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
public function testTrackEntityChangesEventLogging() {
if (!empty($this->smartlingPluginProviderSettings)) {
$this->userForTranslations = $this
->loginAsAdmin([
'edit any translatable_node content',
'access site reports',
]);
$translator = $this
->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
$this
->requestTranslationForNode($this->testNodeId, 'de', $translator);
$this
->drupalPostForm('/admin/reports/dblog/confirm', [], t('Confirm'));
$node = Node::load($this->testNodeId);
$node
->setTitle('New title');
$node
->save();
$this
->drupalGet('/admin/reports/dblog');
$this
->assertNoRaw('File upload triggered (request translation). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload queued (request translation in a batch). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File upload triggered (view action). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertRaw('File upload queued (track entity changes). Job id: 1, file name: JobID1_en_de.xml.');
$this
->assertNoRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
}
else {
$this
->fail("Smartling settings file for simpletests not found.");
}
}
}