You are here

LoggingTest.php in TMGMT Translator Smartling 8.2

File

src/Tests/LoggingTest.php
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;

/**
 * Logging tests.
 *
 * @group tmgmt_smartling
 */
class LoggingTest extends SmartlingTestBase {

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    // Create queue table (it doesn't exist for simpletests somehow).
    $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'));
  }

  /**
   * Test request translation logging.
   */
  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');

      // File triggered/queued.
      $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.');

      // File uploaded.
      $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.");
    }
  }

  /**
   * Test request translation in a batch logging.
   */
  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');

      // File triggered/queued.
      $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.');

      // File uploaded.
      $this
        ->assertNoRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

  /**
   * Test request translation in a batch logging.
   */
  public function testViewActionEventLogging() {
    if (!empty($this->smartlingPluginProviderSettings)) {

      // Create a job. It is needed for test.
      $translator = $this
        ->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
      $this
        ->requestTranslationForNode($this->testNodeId, 'de', $translator);

      // Clean log messages after job submission.
      $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');

      // File triggered/queued.
      $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.');

      // File uploaded.
      $this
        ->assertRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

  /**
   * Test request translation track entity changes logging.
   */
  public function testTrackEntityChangesEventLogging() {
    if (!empty($this->smartlingPluginProviderSettings)) {
      $this->userForTranslations = $this
        ->loginAsAdmin([
        'edit any translatable_node content',
        'access site reports',
      ]);

      // Create a job. It is needed for test.
      $translator = $this
        ->setUpSmartlingProviderSettings($this->smartlingPluginProviderSettings);
      $this
        ->requestTranslationForNode($this->testNodeId, 'de', $translator);

      // Clean log messages after job submission.
      $this
        ->drupalPostForm('/admin/reports/dblog/confirm', [], t('Confirm'));
      $node = Node::load($this->testNodeId);
      $node
        ->setTitle('New title');
      $node
        ->save();
      $this
        ->drupalGet('/admin/reports/dblog');

      // File triggered/queued.
      $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.');

      // File uploaded.
      $this
        ->assertNoRaw('File uploaded. Job id: 1, file name: JobID1_en_de.xml.');
    }
    else {
      $this
        ->fail("Smartling settings file for simpletests not found.");
    }
  }

}

Classes

Namesort descending Description
LoggingTest Logging tests.