/**
  * Overrides DrupalUnitTestBase::setUp().
  */
 function setUp()
 {
     parent::setUp();
     // @todo: Try to get rid of these.
     $this->installSchema('system', array('url_alias', 'router'));
     $this->installEntitySchema('user');
     $this->installEntitySchema('tmgmt_job');
     $this->installEntitySchema('tmgmt_job_item');
     $this->installEntitySchema('tmgmt_message');
     $this->default_translator = entity_create('tmgmt_translator', array('name' => 'test_translator', 'plugin' => 'test_translator', 'remote_languages_mappings' => []));
     $this->default_translator->save();
     $this->addLanguage('de');
 }
 /**
  * Tests the UI of the plugin.
  */
 protected function testMicrosoftUi()
 {
     $this->loginAsAdmin();
     $edit = ['settings[api_key]' => 'wrong key'];
     $this->drupalPostForm('admin/config/regional/tmgmt_translator/manage/' . $this->translator->id(), $edit, t('Save'));
     $this->assertText(t('The "Google API key" is not correct.'));
     $edit = ['settings[api_key]' => 'correct key'];
     $this->drupalPostForm('admin/config/regional/tmgmt_translator/manage/' . $this->translator->id(), $edit, t('Save'));
     $this->assertText(t('@label configuration has been updated.', ['@label' => $this->translator->label()]));
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 function checkAvailable(TranslatorInterface $translator)
 {
     if ($translator->getSetting('action') == 'not_available') {
         return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', ['@translator' => $translator->label(), ':configured' => $translator->url()]));
     }
     return parent::checkAvailable($translator);
 }
 /**
  * {@inheritdoc}
  */
 public function getSupportedRemoteLanguages(TranslatorInterface $translator)
 {
     $languages = array();
     // Prevent access if the translator isn't configured yet.
     if (!$translator->getSetting('client_id')) {
         // @todo should be implemented by an Exception.
         return $languages;
     }
     try {
         $request = $this->doRequest($translator, 'GetLanguagesForTranslate');
         if ($request) {
             $dom = new \DOMDocument();
             $dom->loadXML($request->getBody()->getContents());
             foreach ($dom->getElementsByTagName('string') as $item) {
                 $languages[$item->nodeValue] = $item->nodeValue;
             }
         }
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'Cannot get languages from the translator');
         return $languages;
     }
     return $languages;
 }
 /**
  * Overrides TMGMTDefaultTranslatorPluginController::getSupportedRemoteLanguages().
  */
 public function getSupportedRemoteLanguages(TranslatorInterface $translator)
 {
     $languages = array();
     // Prevent access if the translator isn't configured yet.
     if (!$translator->getSetting('api_key')) {
         return $languages;
     }
     try {
         $request = $this->doRequest($translator, 'languages');
         if (isset($request['data'])) {
             foreach ($request['data']['languages'] as $language) {
                 $languages[$language['language']] = $language['language'];
             }
         }
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return $languages;
     }
     return $languages;
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function delete(array $form, FormStateInterface $form_state)
 {
     $form_state->setRedirectUrl($this->entity->urlInfo('delete-form'));
 }