Commit b0d0c490 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher
Browse files

Added config schema and cleaned up test

parent d597d2db
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
tmgmt.translator.settings.microsoft:
  type: mapping
  mapping:
    auto_accept:
      type: boolean
      label: Automatically accept
    url:
      type: string
      label: Remote URL, used for tests.
    client_id:
      type: string
      label: Client ID
    client_secret:
      type: string
      label: Client Secret
+15 −24
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ use Drupal\Core\Url;

/**
 * Basic tests for the Microsoft translator.
 *
 * @group tmgmt
 */
class MicrosoftTest extends TMGMTTestBase {

@@ -20,51 +22,40 @@ class MicrosoftTest extends TMGMTTestBase {
   */
  public static $modules = array('tmgmt_microsoft', 'tmgmt_microsoft_test');

  static public function getInfo() {
    return array(
      'name' => 'Microsoft Translator tests',
      'description' => 'Tests the Microsoft translator plugin integration.',
      'group' => 'Translation Management',
    );
  }

  /**
   * Tests basic API methods of the plugin.
   */
  protected function testMicrosoft() {
    $this->addLanguage('de');
    $translator = $this->createTranslator();
    $translator->plugin = 'microsoft';
    $translator->settings = array(
    $translator = $this->createTranslator([
      'plugin' => 'microsoft',
      'settings' => [
        'url' => URL::fromUri('base://tmgmt_microsoft_mock/v2/Http.svc', array('absolute' => TRUE))->toString(),
    );
    $translator->save();
      ],
    ]);

    $job = $this->createJob();
    $job->translator = $translator->name;
    $job->translator = $translator->id();
    $item = $job->addItem('test_source', 'test', '1');
    $item->save();

    $this->assertFalse($job->isTranslatable(), 'Check if the translator is not available at this point because we did not define the API parameters.');

    // Save a wrong api key.
    $translator->settings['api'] = 'wrong api key';
    $translator->settings['client_id'] = 'wrong client_id';
    $translator->settings['client_secret'] = 'wrong client_secret';
    // Save a wrong client ID key.
    $translator->setSetting('client_id', 'wrong client_id');
    $translator->setSetting('client_secret', 'wrong client_secret');
    $translator->save();

    $translator = $job->getTranslator();
    $languages = $translator->getSupportedTargetLanguages('en');
    $this->assertTrue(empty($languages), t('We can not get the languages using wrong api parameters.'));

    // Save a correct api key.
    $translator->settings['api'] = 'correct api key';
    $translator->settings['client_id'] = 'correct client_id';
    $translator->settings['client_secret'] = 'correct client_secret';
    // Save a correct client ID.
    $translator->setSetting('client_id', 'correct client_id');
    $translator->setSetting('client_secret', 'correct client_secret');
    $translator->save();

    // Make sure the translator returns the correct supported target languages.
    \Drupal::cache('tmgmt')->deleteAll();
    $translator->clearLanguageCache();
    $languages = $translator->getSupportedTargetLanguages('en');
    $this->assertTrue(isset($languages['de']));

tmgmt_microsoft.module

deleted100644 → 0
+0 −26
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Module file of the translation management test module.
 */

/**
 * Implements hook_tmgmt_translator_plugin_info().
 */
function tmgmt_microsoft_tmgmt_translator_plugin_info() {
  return array(
    'microsoft' => array(
      'label' => t('Microsoft translator'),
      'description' => t('Microsoft Translator service.'),
      'plugin controller class' => 'TMGMTMicrosoftTranslatorPluginController',
      'ui controller class' => 'TMGMTMicrosoftTranslatorUIController',
      'default settings' => array(
        'api' => '',
        'client_id' => '',
        'client_secret' => '',
      ),
    ),
  );
}
+0 −7
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Module file of the translation management test module.
 */