示例#1
0
 /**
  * Tests tmgmt_job_match_item()
  *
  * @see tmgmt_job_match_item
  */
 function testTMGTJobMatchItem()
 {
     $this->addLanguage('fr');
     $this->addLanguage('es');
     // Add a job from en to fr and en to sp.
     $job_en_fr = $this->createJob('en', 'fr');
     $job_en_sp = $this->createJob('en', 'es');
     // Add a job which has existing source-target combinations.
     $this->assertEqual($job_en_fr->id(), tmgmt_job_match_item('en', 'fr')->id());
     $this->assertEqual($job_en_sp->id(), tmgmt_job_match_item('en', 'es')->id());
     // Add a job which has no existing source-target combination.
     $this->assertTrue(tmgmt_job_match_item('fr', 'es') instanceof Job);
 }
示例#2
0
 /**
  * Test the page callbacks to create jobs and check them out.
  *
  * This includes
  * - Varying checkout situations with form detail values.
  * - Unsupported checkout situations where translator is not available.
  * - Exposed filters for job overview
  * - Deleting a job
  *
  * @todo Separate the exposed filter admin overview test.
  */
 function testCheckoutForm()
 {
     // Add a first item to the job. This will auto-create the job.
     $job = tmgmt_job_match_item('en', '');
     $job->addItem('test_source', 'test', 1);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Test primary buttons.
     $this->assertRaw('Save job" class="button js-form-submit form-submit"');
     // Check checkout form.
     $this->assertText('test_source:test:1');
     // Add two more job items.
     $job->addItem('test_source', 'test', 2);
     $job->addItem('test_source', 'test', 3);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('test_source:test:1');
     $this->assertText('test_source:test:2');
     $this->assertText('test_source:test:3');
     // @todo: Test ajax functionality.
     // Attempt to translate into greek.
     $edit = array('target_language' => 'el', 'settings[action]' => 'translate');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('@translator can not translate from @source to @target.', array('@translator' => 'Test provider', '@source' => 'English', '@target' => 'Greek')));
     // Job still needs to be in state new.
     /** @var \Drupal\tmgmt\JobInterface $job */
     $job = \Drupal::entityTypeManager()->getStorage('tmgmt_job')->loadUnchanged($job->id());
     $this->assertTrue($job->isUnprocessed());
     // The owner must be the one that submits the job.
     $this->assertTrue($job->isAuthor());
     $this->drupalLogin($this->translator_user);
     $this->drupalGet('admin/tmgmt/jobs/' . $job->id());
     $edit = array('target_language' => 'es', 'settings[action]' => 'translate');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     /** @var \Drupal\tmgmt\JobInterface $job */
     $job = \Drupal::entityTypeManager()->getStorage('tmgmt_job')->loadUnchanged($job->id());
     $this->assertTrue($job->isAuthor());
     // Job needs to be in state active.
     $job = \Drupal::entityTypeManager()->getStorage('tmgmt_job')->loadUnchanged($job->id());
     $this->assertTrue($job->isActive());
     foreach ($job->getItems() as $job_item) {
         /* @var $job_item \Drupal\tmgmt\JobItemInterface */
         $this->assertTrue($job_item->isNeedsReview());
     }
     $this->assertText(t('Test translation created'));
     $this->assertNoText(t('Test provider called'));
     // Test redirection.
     $this->assertText(t('Job overview'));
     // Another job.
     $previous_tjid = $job->id();
     $job = tmgmt_job_match_item('en', '');
     $job->addItem('test_source', 'test', 9);
     $this->assertNotEqual($job->id(), $previous_tjid);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:9');
     $edit = array('target_language' => 'es', 'settings[action]' => 'submit');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('Test submit'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isActive());
     // Another job.
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 10);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:10');
     $edit = array('settings[action]' => 'reject');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('This is not supported'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isRejected());
     // Check displayed job messages.
     $args = array('@view' => 'view-tmgmt-job-messages');
     $this->assertEqual(2, count($this->xpath('//div[contains(@class, @view)]//tbody/tr', $args)));
     // Check that the author for each is the current user.
     $message_authors = $this->xpath('////div[contains(@class, @view)]//td[contains(@class, @field)]/span', $args + array('@field' => 'views-field-name'));
     $this->assertEqual(2, count($message_authors));
     foreach ($message_authors as $message_author) {
         $this->assertEqual((string) $message_author, $this->translator_user->getUsername());
     }
     // Make sure that rejected jobs can be re-submitted.
     $this->assertTrue($job->isSubmittable());
     $edit = array('settings[action]' => 'translate');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('Test translation created'));
     // HTML tags count.
     \Drupal::state()->set('tmgmt.test_source_data', array('title' => array('deep_nesting' => array('#text' => '<p><em><strong>Six dummy HTML tags in the title.</strong></em></p>', '#label' => 'Title')), 'body' => array('deep_nesting' => array('#text' => '<p>Two dummy HTML tags in the body.</p>', '#label' => 'Body')), 'phantom' => array('deep_nesting' => array('#text' => 'phantom text', '#label' => 'phantom label', '#translate' => FALSE, '#format' => 'filtered_html'))));
     $item4 = $job->addItem('test_source', 'test', 4);
     // Manually active the item as the test expects that.
     $item4->active();
     $this->drupalGet('admin/tmgmt/items/' . $item4->id());
     // Test if the phantom wrapper is not displayed because of #translate FALSE.
     $this->assertNoRaw('tmgmt-ui-element-phantom-wrapper');
     // Test primary buttons.
     $this->assertRaw('Save" class="button button--primary js-form-submit form-submit"');
     $this->drupalPostForm(NULL, NULL, t('Save'));
     $this->clickLink('View');
     $this->assertRaw('Save as completed" class="button button--primary js-form-submit form-submit"');
     $this->drupalPostForm(NULL, NULL, t('Save'));
     $this->assertRaw('Save job" class="button button--primary js-form-submit form-submit"');
     $this->drupalPostForm(NULL, NULL, t('Save job'));
     $this->drupalGet('admin/tmgmt/jobs');
     // Total number of tags should be 8.
     $tags = trim((int) $this->xpath('//table[@class="views-table views-view-table cols-10"]/tbody/tr')[0]->td[7]);
     $this->assertEqual($tags, 8);
     // Another job.
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 11);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:11');
     $edit = array('settings[action]' => 'fail');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('Service not reachable'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isUnprocessed());
     // Verify that we are still on the form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     // Another job.
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 12);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:12');
     $edit = array('settings[action]' => 'not_translatable');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     // @todo Update to correct failure message.
     $this->assertText(t('Fail'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isUnprocessed());
     // Test default settings.
     $this->default_translator->setSetting('action', 'reject');
     $this->default_translator->save();
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 13);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:13');
     // The action should now default to reject.
     $this->drupalPostForm(NULL, array(), t('Submit to provider'));
     $this->assertText(t('This is not supported.'));
     $job4 = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job4->isRejected());
     // Test for job checkout form, if the target language is supported,
     // the test translator should say it is supported.
     $job = tmgmt_job_create('en', 'de', 0);
     $job->save();
     $edit = array('target_language' => 'de');
     $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
     $this->assertFieldByXPath('//select[@id="edit-translator"]/option[1]', 'Test provider');
     $this->drupalGet('admin/tmgmt/jobs');
     // Test if sources languages are correct.
     $sources = $this->xpath('//table[@class="views-table views-view-table cols-10"]/tbody/tr/td[@class="views-field views-field-source-language-1"][contains(., "English")]');
     $this->assertEqual(count($sources), 5);
     // Test if targets languages are correct.
     $targets = $this->xpath('//table[@class="views-table views-view-table cols-10"]/tbody/tr/td[@class="views-field views-field-target-language"][contains(., "Spanish") or contains(., "German")]');
     $this->assertEqual(count($targets), 5);
     // Check that the first action is 'manage'.
     $first_action = $this->xpath('//tbody/tr[2]/td[10]/div/div/ul/li[1]/a');
     $this->assertEqual($first_action[0][0], 'Manage');
     // Test for Unavailable/Unconfigured Translators.
     $this->default_translator->setSetting('action', 'not_translatable');
     $this->default_translator->save();
     $this->drupalGet('admin/tmgmt/jobs/' . $job->id());
     $this->drupalPostForm(NULL, array(), t('Submit to provider'));
     $this->assertText(t('Test provider can not translate from English to German.'));
     // Test for Unavailable/Unconfigured Translators.
     $this->default_translator->setSetting('action', 'not_available');
     $this->default_translator->save();
     $this->drupalGet('admin/tmgmt/jobs/' . $job->id());
     $this->assertText(t('Test provider is not available. Make sure it is properly configured.'));
     $this->drupalPostForm(NULL, array(), t('Submit to provider'));
     $this->assertText(t('@translator is not available. Make sure it is properly configured.', array('@translator' => 'Test provider')));
     // Login as administrator to delete a job.
     $this->loginAsAdmin();
     $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'All')));
     // Translated languages should now be listed as Needs review.
     $start_rows = $this->xpath('//tbody/tr');
     $this->assertEqual(count($start_rows), 5);
     $this->drupalGet($job4->urlInfo('delete-form'));
     $this->assertText('Are you sure you want to delete the translation job test_source:test:11 and 2 more?');
     $this->drupalPostForm(NULL, array(), t('Delete'));
     $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'All')));
     $end_rows = $this->xpath('//tbody/tr');
     $this->assertEqual(count($end_rows), 4);
 }
示例#3
0
 /**
  * Test multiple local language with one single remote language.
  */
 protected function testMultipleLocalToSingleRemoteMapping()
 {
     $this->addLanguage('pt-br');
     $this->addLanguage('pt-pt');
     // Add mapping to the file translator.
     $edit = array('remote_languages_mappings[pt-br]' => 'pt', 'remote_languages_mappings[pt-pt]' => 'pt');
     $this->drupalPostForm('admin/tmgmt/translators/manage/test_translator', $edit, t('Save'));
     $this->drupalGet('admin/tmgmt/translators/manage/test_translator');
     $this->assertFieldById('edit-remote-languages-mappings-pt-br', 'pt', 'Mapping saved correctly');
     // Test first local language.
     $job = tmgmt_job_match_item('en', 'pt-br');
     $job->addItem('test_source', 'test', 0);
     $edit = array('target_language' => 'pt-br');
     $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
     $this->assertFieldByXPath('//select[@id="edit-translator"]//option[@value="test_translator"]', t('Test provider'), 'Provider maps correctly');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText('Portuguese, Brazil');
     $this->assertEqual(count($job->getItems()), 1);
     $this->assertTrue($job->getItems()[1]->accepted());
     $this->drupalGet('admin/tmgmt/items/' . 1);
     $this->assertText('pt-br(pt): Text for job item with type ' . $job->getItems()[1]->getItemType() . ' and id ' . $job->getItems()[1]->getItemId() . '.');
     $this->assertEqual($job->getTargetLangcode(), 'pt-br');
     // Test the other local language.
     $job = tmgmt_job_match_item('en', 'pt-pt');
     $job->addItem('test_source', 'test', 0);
     $edit = array('target_language' => 'pt-pt');
     $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
     $this->assertFieldByXPath('//select[@id="edit-translator"]//option[@value="test_translator"]', t('Test provider'), 'Provider maps correctly');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText('Portuguese, Portugal');
     $this->assertEqual(count($job->getItems()), 1);
     $this->assertTrue($job->getItems()[2]->accepted());
     $this->drupalGet('admin/tmgmt/items/' . 2);
     $this->assertText('pt-pt(pt): Text for job item with type ' . $job->getItems()[2]->getItemType() . ' and id ' . $job->getItems()[2]->getItemId() . '.');
     $this->assertEqual($job->getTargetLangcode(), 'pt-pt');
 }