You are here

class LocalTranslatorTest in Translation Management Tool 8

Basic tests for the local translator.

@group tmgmt

Hierarchy

Expanded class hierarchy of LocalTranslatorTest

File

translators/tmgmt_local/tests/src/Functional/LocalTranslatorTest.php, line 16

Namespace

Drupal\Tests\tmgmt_local\Functional
View source
class LocalTranslatorTest extends LocalTranslatorTestBase {

  /**
   * Test assignee skills.
   */
  public function testAssigneeSkillsForTasks() {
    $this
      ->addLanguage('fr');
    $assignee1 = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $this
      ->drupalLogin($assignee1);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'en',
    );
    $this
      ->drupalPostForm('user/' . $assignee1
      ->id() . '/edit', $edit, t('Save'));
    $this
      ->assertText('The \'from\' and \'to\' language fields can\'t have the same value.');
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee1
      ->id() . '/edit', $edit, t('Save'));
    $this
      ->assertText('The changes have been saved.');
    $edit = array(
      'tmgmt_translation_skills[1][language_from]' => 'en',
      'tmgmt_translation_skills[1][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee1
      ->id() . '/edit', $edit, t('Save'));
    $this
      ->assertText('The language combination has to be unique.');
    $assignee2 = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $this
      ->drupalLogin($assignee2);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee2
      ->id() . '/edit', $edit, t('Save'));
    $edit = array(
      'tmgmt_translation_skills[1][language_from]' => 'de',
      'tmgmt_translation_skills[1][language_to]' => 'en',
    );
    $this
      ->drupalPostForm('user/' . $assignee2
      ->id() . '/edit', $edit, t('Save'));
    $assignee3 = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $this
      ->drupalLogin($assignee3);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee3
      ->id() . '/edit', $edit, t('Save'));
    $edit = array(
      'tmgmt_translation_skills[1][language_from]' => 'de',
      'tmgmt_translation_skills[1][language_to]' => 'en',
    );
    $this
      ->drupalPostForm('user/' . $assignee3
      ->id() . '/edit', $edit, t('Save'));
    $edit = array(
      'tmgmt_translation_skills[2][language_from]' => 'en',
      'tmgmt_translation_skills[2][language_to]' => 'fr',
    );
    $this
      ->drupalPostForm('user/' . $assignee3
      ->id() . '/edit', $edit, t('Save'));
    $job1 = $this
      ->createJob('en', 'de');
    $job2 = $this
      ->createJob('de', 'en');
    $job3 = $this
      ->createJob('en', 'fr');
    $local_task1 = LocalTask::create(array(
      'uid' => $job1
        ->getOwnerId(),
      'tjid' => $job1
        ->id(),
      'title' => 'Task 1',
    ));
    $local_task1
      ->save();
    $local_task2 = LocalTask::create(array(
      'uid' => $job2
        ->getOwnerId(),
      'tjid' => $job2
        ->id(),
      'title' => 'Task 2',
    ));
    $local_task2
      ->save();
    $local_task3 = LocalTask::create(array(
      'uid' => $job3
        ->getOwnerId(),
      'tjid' => $job3
        ->id(),
      'title' => 'Task 3',
    ));
    $local_task3
      ->save();

    // Test languages involved in tasks.
    $this
      ->assertEqual(tmgmt_local_tasks_languages(array(
      $local_task1
        ->id(),
      $local_task2
        ->id(),
      $local_task3
        ->id(),
    )), array(
      'en' => array(
        'de',
        'fr',
      ),
      'de' => array(
        'en',
      ),
    ));

    // Test available translators for task en - de.
    $this
      ->assertEqual(tmgmt_local_get_assignees_for_tasks(array(
      $local_task1
        ->id(),
    )), array(
      $assignee1
        ->id() => $assignee1
        ->getDisplayName(),
      $assignee2
        ->id() => $assignee2
        ->getDisplayName(),
      $assignee3
        ->id() => $assignee3
        ->getDisplayName(),
    ));

    // Test available translators for tasks en - de, de - en.
    $this
      ->assertEqual(tmgmt_local_get_assignees_for_tasks(array(
      $local_task1
        ->id(),
      $local_task2
        ->id(),
    )), array(
      $assignee2
        ->id() => $assignee2
        ->getDisplayName(),
      $assignee3
        ->id() => $assignee3
        ->getDisplayName(),
    ));

    // Test available translators for tasks en - de, de - en, en - fr.
    $this
      ->assertEqual(tmgmt_local_get_assignees_for_tasks(array(
      $local_task1
        ->id(),
      $local_task2
        ->id(),
      $local_task3
        ->id(),
    )), array(
      $assignee3
        ->id() => $assignee3
        ->getDisplayName(),
    ));
  }

  /**
   * Test the basic translation workflow.
   */
  public function testBasicWorkflow() {
    $translator = Translator::load('local');

    /** @var FilterFormat $basic_html_format */
    $basic_html_format = FilterFormat::create(array(
      'format' => 'basic_html',
      'name' => 'Basic HTML',
    ));
    $basic_html_format
      ->save();

    // Create a job and request a local translation.
    $this
      ->loginAsTranslator();
    $job = $this
      ->createJob();
    $job->translator = $translator
      ->id();
    $job
      ->addItem('test_source', 'test', '1');
    \Drupal::state()
      ->set('tmgmt.test_source_data', [
      'dummy' => [
        'deep_nesting' => [
          '#text' => file_get_contents(drupal_get_path('module', 'tmgmt') . '/tests/testing_html/sample.html'),
          '#label' => 'Label for job item with type test and id 2.',
          '#translate' => TRUE,
          '#format' => 'basic_html',
        ],
      ],
      'second' => [
        '#text' => 'second text',
        '#label' => 'Second label',
        '#translate' => TRUE,
      ],
      'third' => [
        '#text' => 'third text',
        '#label' => 'Third label',
        '#translate' => TRUE,
      ],
    ]);
    $job
      ->addItem('test_source', 'test', '2');
    $job
      ->save();

    // Make sure that the checkout page works as expected when there are no
    // roles.
    $this
      ->drupalGet($job
      ->toUrl());
    $this
      ->assertText(t('@translator can not translate from @source to @target.', array(
      '@translator' => 'Drupal user',
      '@source' => 'English',
      '@target' => 'German',
    )));
    $element = $this
      ->xpath('//*[@id="edit-translator"]/option')[0];
    $this
      ->assertEqual($element
      ->getText(), 'Drupal user (unsupported)');
    $this->assignee = $this
      ->drupalCreateUser(array_merge($this->localTranslatorPermissions, [
      $basic_html_format
        ->getPermissionName(),
    ]));

    // The same when there is a single role.
    $this
      ->drupalGet($job
      ->toUrl());
    $this
      ->assertText(t('@translator can not translate from @source to @target.', array(
      '@translator' => 'Drupal user',
      '@source' => 'English',
      '@target' => 'German',
    )));

    // Create another local translator with the required abilities.
    $other_assignee_same = $this
      ->drupalCreateUser($this->localTranslatorPermissions);

    // And test again with two roles but still no abilities.
    $this
      ->drupalGet($job
      ->toUrl());
    $this
      ->assertText(t('@translator can not translate from @source to @target.', array(
      '@translator' => 'Drupal user',
      '@source' => 'English',
      '@target' => 'German',
    )));
    $this
      ->drupalLogin($other_assignee_same);

    // Configure language abilities.
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $other_assignee_same
      ->id() . '/edit', $edit, t('Save'));

    // Check that the user is not listed in the translator selection form.
    $this
      ->loginAsAdmin();
    $this
      ->drupalGet($job
      ->toUrl());
    $element = $this
      ->xpath('//*[@id="edit-translator"]/option')[0];
    $this
      ->assertEqual($element
      ->getText(), 'Drupal user');
    $this
      ->assertText(t('Assign job to'));
    $this
      ->assertText($other_assignee_same
      ->getDisplayName());
    $this
      ->assertNoText($this->assignee
      ->getDisplayName());
    $this
      ->drupalLogin($this->assignee);

    // Configure language abilities.
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $this->assignee
      ->id() . '/edit', $edit, t('Save'));

    // Check that the translator is now listed.
    $this
      ->loginAsAdmin();
    $this
      ->drupalGet($job
      ->toUrl());
    $this
      ->assertText($this->assignee
      ->getDisplayName());

    // Test assign task while submitting job.
    $job_comment = 'Dummy job comment';
    $edit = [
      'settings[translator]' => $this->assignee
        ->id(),
      'settings[job_comment]' => $job_comment,
    ];
    $this
      ->drupalPostForm(NULL, $edit, t('Submit to provider'));
    $this
      ->drupalLogin($this->assignee);
    $this
      ->drupalGet('translate/pending');
    $this
      ->assertText($job
      ->label());
    $this
      ->loginAsAdmin($this->localManagerPermissions);
    $this
      ->drupalGet('manage-translate/assigned');
    $this
      ->assertNoLink(t('Delete'));
    $this
      ->clickLink(t('Unassign'));
    $this
      ->drupalPostForm(NULL, [], t('Unassign'));

    // Test for job comment in the job checkout info pane.
    $this
      ->drupalGet($job
      ->toUrl());
    $this
      ->assertText($job_comment);
    $this
      ->drupalLogin($this->assignee);

    // Create a second local translator with different language abilities,
    // make sure that he does not see the task.
    $other_translator = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $this
      ->drupalLogin($other_translator);

    // Configure language abilities.
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'de',
      'tmgmt_translation_skills[0][language_to]' => 'en',
    );
    $this
      ->drupalPostForm('user/' . $other_translator
      ->id() . '/edit', $edit, t('Save'));
    $this
      ->drupalGet('translate');
    $this
      ->assertNoText($job
      ->label());
    $this
      ->drupalLogin($this->assignee);

    // Check the translate overview.
    $this
      ->drupalGet('translate');
    $this
      ->assertText($job
      ->label());

    // @todo: Fails, encoding problem?
    // $this->assertText(t('@from => @to', array('@from' => 'en', '@to' => 'de')));
    // Test LocalTaskForm.
    $this
      ->clickLink('View');
    $this
      ->assertText('Unassigned');
    $xpath = $this
      ->xpath('//*[@id="edit-status"]');
    $this
      ->assertEmpty($xpath);
    $this
      ->loginAsAdmin($this->localManagerPermissions);
    $this
      ->drupalGet('translate');
    $this
      ->clickLink('View');
    $xpath = $this
      ->xpath('//*[@id="edit-tuid"]');
    $this
      ->assertNotEmpty($xpath);
    $edit = array(
      'tuid' => $this->assignee
        ->id(),
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Save task'));
    $this
      ->assertText(t('Assigned to user @assignee.', [
      '@assignee' => $this->assignee
        ->getDisplayName(),
    ]));
    $this
      ->drupalGet('manage-translate/assigned');
    $this
      ->clickLink('View');
    $edit = array(
      'tuid' => 0,
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Save task'));
    $this
      ->drupalLogin($this->assignee);
    $this
      ->drupalGet('translate');

    // Assign to action not working yet.
    $edit = array(
      'tmgmt_local_task_bulk_form[0]' => TRUE,
      'action' => 'tmgmt_local_task_assign_to_me',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
    $this
      ->assertText(t('Assign to me was applied to 1 item.'));

    // Unassign again.
    $edit = array(
      'tmgmt_local_task_bulk_form[0]' => TRUE,
      'action' => 'tmgmt_local_task_unassign_multiple',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
    $this
      ->assertText(t('Unassign was applied to 1 item.'));

    // Now test the assign link.
    // @todo Action should not redirect to mine.
    $this
      ->drupalGet('translate');
    $this
      ->clickLink(t('Assign to me'));
    $this
      ->assertText(t('The task has been assigned to you.'));

    // Assert created local task and task items.
    $this
      ->drupalGet('translate/pending');
    $this
      ->clickLink(t('View'));
    $this
      ->assertNotEmpty(preg_match('|translate/(\\d+)|', $this
      ->getUrl(), $matches), 'Task found');

    /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
    $task = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task')
      ->load($matches[1]);
    $this
      ->assertTrue($task
      ->isPending());
    $items = $task
      ->getItems();

    /** @var \Drupal\tmgmt_local\Entity\LocalTaskItem $first_task_item */
    $first_task_item = reset($items);
    $this
      ->assertTrue($first_task_item
      ->isPending());

    // Log in with the translator with the same abilities, make sure that he
    // does not see the assigned task.
    $this
      ->drupalLogin($other_assignee_same);
    $this
      ->drupalGet('translate');
    $this
      ->assertNoText($job
      ->label());
    $this
      ->drupalGet('translate/items/' . $first_task_item
      ->id());
    $this
      ->assertResponse(403);
    $this
      ->drupalLogin($this->admin_user);

    // Unassign the task.
    $this
      ->drupalGet('translate/' . $task
      ->id());
    $edit = [
      'tuid' => '',
    ];
    $this
      ->drupalPostForm(NULL, $edit, t('Save task'));
    $this
      ->clickLink(t('View'));

    // Assign again the task to himself.
    $edit = [
      'tuid' => $this->assignee
        ->id(),
    ];
    $this
      ->drupalPostForm(NULL, $edit, t('Save task'));
    $this
      ->drupalLogin($this->assignee);

    // Translate the task.
    $this
      ->drupalGet('translate/' . $task
      ->id());
    $this
      ->assertText('test_source:test:1');
    $this
      ->assertText('test_source:test:2');

    // Translate the first item.
    $this
      ->drupalGet($first_task_item
      ->toUrl());

    // Assert the breadcrumb.
    $this
      ->assertLink(t('Home'));
    $this
      ->assertLink(t('Local Tasks'));
    $this
      ->assertText($job
      ->label());

    // Assert the header.
    $this
      ->assertLink($first_task_item
      ->getJobItem()
      ->getSourceLabel());
    $this
      ->assertText($first_task_item
      ->getJobItem()
      ->getSourceType());
    $this
      ->assertText($first_task_item
      ->getJobItem()
      ->getJob()
      ->getSourceLanguage()
      ->getName());
    $this
      ->assertText($first_task_item
      ->getJobItem()
      ->getJob()
      ->getTargetLanguage()
      ->getName());
    $this
      ->assertText(\Drupal::service('date.formatter')
      ->format($first_task_item
      ->getChangedTime()));
    $this
      ->assertText($first_task_item
      ->getStatus());
    $this
      ->assertLink($first_task_item
      ->getTask()
      ->label());
    $this
      ->assertText(t('Dummy'));

    // Check if Save as completed button is displayed.
    $elements = $this
      ->xpath('//*[@id="edit-save-as-completed"]');
    $this
      ->assertTrue(!empty($elements), "'Save as completed' button appears.");

    // Job comment is present in the translate tool as well.
    $this
      ->assertText($job_comment);
    $this
      ->assertText('test_source:test:1');

    // Try to complete a translation when translations are missing.
    $edit = array(
      'dummy|deep_nesting[translation]' => '',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Save as completed'));
    $this
      ->assertText(t('Missing translation.'));
    $edit = array(
      'dummy|deep_nesting[translation]' => $translation1 = 'German translation of source 1',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Save as completed'));
    $this
      ->assertRaw('tmgmt/icons/gray-check.svg" title="Translated"');
    $this
      ->assertText('The translation for ' . $first_task_item
      ->label() . ' has been saved as completed.');

    // Check that the source has not being modified.
    $this
      ->clickLink(t('View'));

    /** @var \Drupal\tmgmt\JobItemInterface $job_item */
    $job_items = $job
      ->getItems([
      'tjiid' => 1,
    ]);
    $job_item = reset($job_items);
    $source = $job_item
      ->getData([
      'dummy',
      'deep_nesting',
      '#text',
    ]);
    $this
      ->assertText($source);

    // Review and accept the first item.
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_job_item')
      ->resetCache();
    drupal_static_reset('tmgmt_local_task_statistics_load');

    /** @var \Drupal\tmgmt\JobItemInterface $item1 */
    $item1 = JobItem::load(1);

    // The first item should be available for review.
    $this
      ->assertTrue($item1
      ->isNeedsReview(), 'Job item 1 needs review.');
    $item1
      ->acceptTranslation();

    // The first item should be accepted now, the second still in progress.
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task_item')
      ->resetCache();
    $this
      ->drupalGet('translate/1');

    // Checking if the 'Save as completed' button is not displayed.
    $this
      ->drupalGet('translate/items/1');
    $elements = $this
      ->xpath('//*[@id="edit-save-as-completed"]');
    $this
      ->assertTrue(empty($elements), "'Save as completed' button does not appear.");

    // Checking if the item status is not displayed.
    $this
      ->assertNoRaw('title="Finish"');
    $this
      ->assertNoRaw('title="Reject"');

    // We can go back to the Task from the item.
    $this
      ->drupalGet('translate/items/1');
    $this
      ->clickLink($task
      ->label());

    // Let's check the task status.

    /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
    $task = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task')
      ->loadUnchanged($task
      ->id());
    $this
      ->assertTrue($task
      ->isPending());

    /** @var \Drupal\tmgmt_local\Entity\LocalTaskItem $second_task_item */
    list($first_task_item, $second_task_item) = array_values($task
      ->getItems());
    $this
      ->assertTrue($first_task_item
      ->isClosed());

    // Assert that translator can provide translations for a "Dummy" field. An
    // empty text field should be displayed as translator does not have a
    // permission to use "full_html" text format.
    $second_task_item
      ->updateData('dummy|deep_nesting', [
      '#format' => 'full_html',
    ]);
    $second_task_item
      ->save();
    $this
      ->clickLink(t('Translate'));
    $this
      ->assertFieldByName('dummy|deep_nesting[translation]');
    $this
      ->assertRaw('Save as completed" class="button button--primary js-form-submit form-submit"');
    $translation_field = $this
      ->xpath('//*[@id="edit-dummydeep-nesting-translation"]')[0];
    $this
      ->assertEqual($translation_field
      ->getText(), '');

    // Translate the second item but do not mark as translated it yet.
    $second_task_item
      ->updateData('dummy|deep_nesting', [
      '#format' => 'basic_html',
    ]);
    $second_task_item
      ->save();
    $this
      ->drupalGet('translate/items/' . $second_task_item
      ->id());
    $title = $this
      ->xpath('//*[@id="edit-dummydeep-nesting-translation-format-guidelines"]/div/h4')[0];
    $this
      ->assertEqual($title
      ->getText(), t('Basic HTML'));

    // Assert the order of the displayed elements.
    $translate_elements = $this
      ->xpath('//*[@id="edit-translation"]/table');
    $ids = [];
    foreach ($translate_elements as $translate_element) {
      $ids[] = (string) $translate_element
        ->getAttribute('id');
    }
    $this
      ->assertEqual($ids[0], 'tmgmt-local-element-dummy-deep-nesting');
    $this
      ->assertEqual($ids[1], 'tmgmt-local-element-second');
    $this
      ->assertEqual($ids[2], 'tmgmt-local-element-third');
    $edit = array(
      'dummy|deep_nesting[translation][value]' => $translation2 = 'German translation of source 2',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Save'));
    $this
      ->assertText('The translation for ' . $second_task_item
      ->label() . ' has been saved.');
    drupal_static_reset('tmgmt_local_task_statistics_load');

    /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
    $task = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task')
      ->loadUnchanged($task
      ->id());
    $this
      ->assertTrue($task
      ->isPending());

    // Mark the data item as translated but don't save the task item as
    // completed.
    $this
      ->clickLink(t('Translate'));
    $page = $this
      ->getSession()
      ->getPage();
    $page
      ->pressButton('finish-dummy|deep_nesting');
    $this
      ->assertRaw('name="reject-dummy|deep_nesting"', "'✗' button appears.");
    $this
      ->drupalGet('translate/' . $task
      ->id());
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task_item')
      ->resetCache();
    drupal_static_reset('tmgmt_local_task_statistics_load');

    /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
    $task = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task')
      ->loadUnchanged($task
      ->id());
    $this
      ->assertTrue($task
      ->isPending());
    list($first_task_item, $second_task_item) = array_values($task
      ->getItems());
    $this
      ->assertTrue($first_task_item
      ->isClosed());
    $this
      ->assertTrue($second_task_item
      ->isPending());

    // Check the job data.
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_job_item')
      ->resetCache();

    /** @var \Drupal\tmgmt\JobInterface $job */
    $job = Job::load($job
      ->id());

    /** @var \Drupal\tmgmt\JobItemInterface $item2 */
    list($item1, $item2) = array_values($job
      ->getItems());
    $this
      ->assertTrue($item1
      ->isAccepted(), 'Job item 1 is accepted.');

    // The first item should be active.
    $this
      ->assertTrue($item2
      ->isActive(), 'Job item 2 is still active.');

    // Check the overview page, the task should still show in progress.
    $this
      ->drupalGet('translate');
    $this
      ->assertText(t('Pending'));

    // Mark the second item as completed now.
    $this
      ->clickLink(t('View'));
    $this
      ->clickLink(t('Translate'));
    $remaining_translations = [
      'second[translation]' => 'Third translation',
      'third[translation]' => 'Third translation',
    ];
    $this
      ->drupalPostForm(NULL, $remaining_translations, t('Save as completed'));
    $this
      ->assertText('The translation for ' . $second_task_item
      ->label() . ' has been saved as completed.');
    $this
      ->clickLink('View');

    // Review and accept the second item.
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_job_item')
      ->resetCache();
    drupal_static_reset('tmgmt_local_task_statistics_load');
    $item1 = JobItem::load(2);
    $item1
      ->acceptTranslation();

    // Refresh the page.
    $this
      ->drupalGet('translate');

    // We should have been redirect back to the overview, the task should be
    // completed now.
    $this
      ->assertNoText($task
      ->getJob()
      ->label());
    $this
      ->clickLink(t('Closed'));
    $this
      ->assertText($task
      ->getJob()
      ->label());
    $this
      ->assertText(t('Completed'));
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task_item')
      ->resetCache();
    $task = LocalTask::load($task
      ->id());
    $this
      ->assertTrue($task
      ->isClosed());
    list($first_task_item, $second_task_item) = array_values($task
      ->getItems());
    $this
      ->assertTrue($first_task_item
      ->isClosed());
    $this
      ->assertTrue($second_task_item
      ->isClosed());
    \Drupal::entityTypeManager()
      ->getStorage('tmgmt_job_item')
      ->resetCache();
    $job = Job::load($job
      ->id());
    list($item1, $item2) = array_values($job
      ->getItems());

    // Job was accepted and finished automatically due to the default approve
    // setting.
    $this
      ->assertTrue($job
      ->isFinished());
    $this
      ->assertEqual($item1
      ->getData(array(
      'dummy',
      'deep_nesting',
      '#translation',
      '#text',
    )), $translation1);
    $this
      ->assertEqual($item2
      ->getData(array(
      'dummy',
      'deep_nesting',
      '#translation',
      '#text',
    )), $translation2);

    // Delete the job, make sure that the corresponding task and task items were
    // deleted.
    $job
      ->delete();
    $this
      ->assertEmpty(LocalTask::load($task
      ->id()));
    $this
      ->assertEmpty($task
      ->getItems());
  }

  /**
   * Test the allow all setting.
   */
  public function testAllowAll() {

    /** @var Translator $translator */
    $translator = Translator::load('local');

    // Create a job and request a local translation.
    $this
      ->loginAsTranslator();
    $job = $this
      ->createJob();
    $job->translator = $translator
      ->id();
    $job
      ->addItem('test_source', 'test', '1');
    $job
      ->addItem('test_source', 'test', '2');
    $this
      ->assertFalse($job
      ->requestTranslation(), 'Translation request was denied.');

    // Now enable the setting.
    $this
      ->config('tmgmt_local.settings')
      ->set('allow_all', TRUE)
      ->save();

    /** @var Job $job */
    $job = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_job')
      ->loadUnchanged($job
      ->id());
    $job->translator = $translator
      ->id();
    $this
      ->assertIdentical(NULL, $job
      ->requestTranslation(), 'Translation request was successfull');
    $this
      ->assertTrue($job
      ->isActive());
  }
  public function testAbilitiesAPI() {
    $this
      ->addLanguage('fr');
    $this
      ->addLanguage('ru');
    $this
      ->addLanguage('it');
    $all_assignees = array();
    $assignee1 = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $all_assignees[$assignee1
      ->id()] = $assignee1
      ->getDisplayName();
    $this
      ->drupalLogin($assignee1);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee1
      ->id() . '/edit', $edit, t('Save'));
    $assignee2 = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $all_assignees[$assignee2
      ->id()] = $assignee2
      ->getDisplayName();
    $this
      ->drupalLogin($assignee2);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'ru',
    );
    $this
      ->drupalPostForm('user/' . $assignee2
      ->id() . '/edit', $edit, t('Save'));
    $edit = array(
      'tmgmt_translation_skills[1][language_from]' => 'en',
      'tmgmt_translation_skills[1][language_to]' => 'fr',
    );
    $this
      ->drupalPostForm('user/' . $assignee2
      ->id() . '/edit', $edit, t('Save'));
    $edit = array(
      'tmgmt_translation_skills[2][language_from]' => 'fr',
      'tmgmt_translation_skills[2][language_to]' => 'it',
    );
    $this
      ->drupalPostForm('user/' . $assignee2
      ->id() . '/edit', $edit, t('Save'));
    $assignee3 = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $all_assignees[$assignee3
      ->id()] = $assignee3
      ->getDisplayName();
    $this
      ->drupalLogin($assignee3);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'fr',
      'tmgmt_translation_skills[0][language_to]' => 'ru',
    );
    $this
      ->drupalPostForm('user/' . $assignee3
      ->id() . '/edit', $edit, t('Save'));
    $edit = array(
      'tmgmt_translation_skills[1][language_from]' => 'it',
      'tmgmt_translation_skills[1][language_to]' => 'en',
    );
    $this
      ->drupalPostForm('user/' . $assignee3
      ->id() . '/edit', $edit, t('Save'));

    // Test target languages.
    $target_languages = tmgmt_local_supported_target_languages('fr');
    $this
      ->assertTrue(isset($target_languages['it']));
    $this
      ->assertTrue(isset($target_languages['ru']));
    $target_languages = tmgmt_local_supported_target_languages('en');
    $this
      ->assertTrue(isset($target_languages['fr']));
    $this
      ->assertTrue(isset($target_languages['ru']));

    // Test language pairs.
    $this
      ->assertEqual(tmgmt_local_supported_language_pairs(), array(
      'en__de' => array(
        'source_language' => 'en',
        'target_language' => 'de',
      ),
      'en__ru' => array(
        'source_language' => 'en',
        'target_language' => 'ru',
      ),
      'en__fr' => array(
        'source_language' => 'en',
        'target_language' => 'fr',
      ),
      'fr__it' => array(
        'source_language' => 'fr',
        'target_language' => 'it',
      ),
      'fr__ru' => array(
        'source_language' => 'fr',
        'target_language' => 'ru',
      ),
      'it__en' => array(
        'source_language' => 'it',
        'target_language' => 'en',
      ),
    ));
    $this
      ->assertEqual(tmgmt_local_supported_language_pairs('fr', array(
      $assignee2
        ->id(),
    )), array(
      'fr__it' => array(
        'source_language' => 'fr',
        'target_language' => 'it',
      ),
    ));

    // Test if we got all translators.
    $assignees = tmgmt_local_assignees();
    foreach ($all_assignees as $uid => $name) {
      if (!isset($assignees[$uid])) {
        $this
          ->fail('Expected translator not present');
      }
      if (!in_array($name, $all_assignees)) {
        $this
          ->fail('Expected translator name not present');
      }
    }

    // Only translator2 has such abilities.
    $assignees = tmgmt_local_assignees('en', array(
      'ru',
      'fr',
    ));
    $this
      ->assertTrue(isset($assignees[$assignee2
      ->id()]));
  }

  /**
   * Test permissions for the tmgmt_local VBO actions.
   */
  public function testVBOPermissions() {
    $translator = Translator::load('local');
    $job = $this
      ->createJob();
    $job->translator = $translator
      ->id();
    $job->settings->job_comment = $job_comment = 'Dummy job comment';
    $job
      ->addItem('test_source', 'test', '1');
    $job
      ->addItem('test_source', 'test', '2');

    // Create another local translator with the required abilities.
    $assignee = $this
      ->loginAsTranslator($this->localTranslatorPermissions);

    // Configure language abilities.
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee
      ->id() . '/edit', $edit, t('Save'));
    $job
      ->requestTranslation();
    $this
      ->drupalGet('manage-translate');
    $this
      ->assertResponse(403);
    $this
      ->drupalGet('translate');
    $edit = array(
      'tmgmt_local_task_bulk_form[0]' => TRUE,
      'action' => 'tmgmt_local_task_assign_to_me',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
    $this
      ->assertText(t('Assign to me was applied to 1 item.'));
    $edit = array(
      'tmgmt_local_task_bulk_form[0]' => TRUE,
      'action' => 'tmgmt_local_task_unassign_multiple',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
    $this
      ->assertText(t('Unassign was applied to 1 item.'));

    // Login as admin and check VBO submit actions are present.
    $this
      ->loginAsAdmin($this->localManagerPermissions);
    $this
      ->drupalGet('manage-translate');
    $edit = array(
      'tmgmt_local_task_bulk_form[0]' => TRUE,
      'action' => 'tmgmt_local_task_assign_multiple',
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
    $edit = array(
      'tuid' => $assignee
        ->id(),
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Assign tasks'));
    $this
      ->assertText(t('Assigned 1 to user @assignee.', [
      '@assignee' => $assignee
        ->getAccountName(),
    ]));
  }

  /**
   * Tests of the task progress.
   */
  public function testLocalProgress() {

    // Load the local translator.
    $translator = Translator::load('local');

    // Create assignee with the skills.
    $assignee1 = $this
      ->drupalCreateUser($this->localManagerPermissions);
    $this
      ->drupalLogin($assignee1);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $assignee1
      ->id() . '/edit', $edit, t('Save'));

    // Login as translator.
    $this
      ->loginAsTranslator();

    // Create the basic html format.
    $basic_html_format = FilterFormat::create(array(
      'format' => 'basic_html',
      'name' => 'Basic HTML',
    ));
    $basic_html_format
      ->save();

    // Create a Job.
    $job = $this
      ->createJob();
    $job->translator = $translator
      ->id();
    $item1 = $job
      ->addItem('test_source', 'test', '1');
    \Drupal::state()
      ->set('tmgmt.test_source_data', array(
      'title' => array(
        'deep_nesting' => array(
          '#text' => 'Example text',
          '#label' => 'Label for job item with type test and id 2.',
          '#translate' => TRUE,
        ),
      ),
      'text' => array(
        'deep_nesting' => array(
          '#text' => 'Example text',
          '#label' => 'Label for job item with type test and id 2.',
          '#translate' => TRUE,
        ),
      ),
    ));
    $job
      ->addItem('test_source', 'test', '2');
    $job
      ->save();
    $this
      ->drupalGet($job
      ->toUrl());
    $this
      ->drupalPostForm(NULL, NULL, t('Submit to provider'));

    // Login as assignee.
    $this
      ->drupalLogin($assignee1);

    // Check the task unassigned icon.
    $this
      ->drupalGet('/manage-translate');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'unassigned', 'Unassigned');

    // Assign the task and check its icon.
    $edit = array(
      'action' => 'tmgmt_local_task_assign_to_me',
      'tmgmt_local_task_bulk_form[0]' => 1,
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'assigned', 'Needs action');

    // Unassign it back.
    $edit = array(
      'action' => 'tmgmt_local_task_unassign_multiple',
      'tmgmt_local_task_bulk_form[0]' => 1,
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));

    // Check its unassigned icon.
    $this
      ->drupalGet('/manage-translate');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'unassigned', 'Unassigned');
    $this
      ->drupalGet('/translate');

    // Check the unassigned status.
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'unassigned', 'Unassigned');
    $edit = array(
      'tmgmt_local_task_bulk_form[0]' => 1,
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Apply to selected items'));

    // Check the needs action status.
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'my-tasks', 'Needs action');

    // Check if the task is displayed on pending overview.
    $this
      ->drupalGet('/translate/pending');
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'pending', 'Needs action');
    $this
      ->drupalGet('/manage-translate/pending');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'pending', 'Needs action');

    // Check the icons of the task items.
    $this
      ->drupalGet('/translate/1');
    $this
      ->assertTaskItemStatusIcon('test_source:test:1', 'Untranslated');
    $this
      ->assertTaskItemStatusIcon('test_source:test:2', 'Untranslated');
    $this
      ->assertTaskItemProgress('test_source:test:1', 1, 0, 0);
    $this
      ->assertTaskItemProgress('test_source:test:2', 2, 0, 0);

    // Check the progress bar and status of the task.
    $this
      ->drupalGet('/translate');
    $this
      ->assertTaskProgress(1, 'my-tasks', 3, 0, 0);
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'my-tasks', 'Needs action');
    $this
      ->drupalGet('/manage-translate');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'assigned', 'Needs action');

    // Set two items as translated.
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalGet('translate/items/1');
    $page
      ->pressButton('finish-dummy|deep_nesting');
    $this
      ->drupalGet('translate/items/2');
    $page
      ->pressButton('finish-title|deep_nesting');

    // Check the task items icons and progress.
    $this
      ->drupalGet('/translate/1');
    $this
      ->assertTaskItemStatusIcon('test_source:test:1', 'Untranslated');
    $this
      ->assertTaskItemStatusIcon('test_source:test:2', 'Untranslated');
    $this
      ->assertTaskItemProgress('test_source:test:1', 0, 1, 0);
    $this
      ->assertTaskItemProgress('test_source:test:2', 1, 1, 0);

    // Check the progress bar and status of the task.
    $this
      ->drupalGet('/translate');
    $this
      ->assertTaskProgress(1, 'my-tasks', 1, 2, 0);
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'my-tasks', 'Needs action');
    $this
      ->drupalGet('/manage-translate');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'assigned', 'Needs action');

    // Save the first item as completed and check item icons and progress.
    $edit = [
      'dummy|deep_nesting[translation]' => 'German translation',
    ];
    $this
      ->drupalPostForm('/translate/items/1', $edit, t('Save as completed'));
    $this
      ->assertTaskItemStatusIcon('test_source:test:1', 'Translated');
    $this
      ->assertTaskItemStatusIcon('test_source:test:2', 'Untranslated');
    $this
      ->assertTaskItemProgress('test_source:test:1', 0, 0, 1);
    $this
      ->assertTaskItemProgress('test_source:test:2', 1, 1, 0);

    // Check the progress bar and status of the task.
    $this
      ->drupalGet('/translate');
    $this
      ->assertTaskProgress(1, 'my-tasks', 1, 1, 1);
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'my-tasks', 'Needs action');
    $this
      ->drupalGet('/manage-translate');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'assigned', 'Needs action');

    // Save the second item as completed.
    $edit = [
      'title|deep_nesting[translation]' => 'German translation of title',
      'text|deep_nesting[translation]' => 'German translation of text',
    ];
    $this
      ->drupalPostForm('/translate/items/2', $edit, t('Save as completed'));

    // Check the icon a progress bar of the task.
    $this
      ->assertTaskProgress(1, 'my-tasks', 0, 0, 3);
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'my-tasks', 'In review');

    // Check the task items icons.
    $this
      ->drupalGet('/translate/1');
    $this
      ->assertTaskItemStatusIcon('test_source:test:1', 'Translated');
    $this
      ->assertTaskItemStatusIcon('test_source:test:2', 'Translated');
    $this
      ->assertTaskItemProgress('test_source:test:1', 0, 0, 1);
    $this
      ->assertTaskItemProgress('test_source:test:2', 0, 0, 2);

    // Check if the task is displayed on the completed overview.
    $this
      ->drupalGet('/translate/completed');
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'completed', 'In review');
    $this
      ->drupalGet('/manage-translate/completed');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'completed', 'In review');

    // Accept translation of the job items.

    /** @var \Drupal\tmgmt\Entity\Job $job1 */
    $job1 = Job::load($job
      ->id());

    /** @var \Drupal\tmgmt\Entity\JobItem $item */
    foreach ($job1
      ->getItems() as $item) {
      $item
        ->acceptTranslation();
    }

    // Check if the task is displayed on the closed overview.
    $this
      ->drupalGet('/translate/closed');
    $this
      ->assertTaskStatusIcon(1, 'task-overview', 'closed', 'Closed');
    $this
      ->drupalGet('/manage-translate/closed');
    $this
      ->assertTaskStatusIcon(1, 'manage-translate-task', 'closed', 'Closed');

    // Assert the legend.
    $this
      ->drupalGet('/translate/items/' . $item1
      ->id());
    $this
      ->assertRaw('class="tmgmt-color-legend');
  }

  /**
   * Test permissions for the tmgmt_local VBO actions.
   */
  public function testUserPermissionsAccess() {
    $permissions = [
      'administer tmgmt',
      'create translation jobs',
      'accept translation jobs',
      'administer translation tasks',
    ];
    foreach ($permissions as $permission) {
      $user = $this
        ->drupalCreateUser([
        $permission,
      ]);
      $this
        ->drupalLogin($user);
      $this
        ->drupalGet('admin/tmgmt');
      $this
        ->assertText('Translation');
    }
    $user = $this
      ->drupalCreateUser([
      'provide translation services',
    ]);
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet('admin/tmgmt');
    $this
      ->assertText('Local Tasks');
  }

  /**
   * Test the settings of TMGMT local.
   */
  public function testSettings() {
    \Drupal::getContainer()
      ->get('theme_installer')
      ->install([
      'seven',
    ]);
    $this
      ->drupalPlaceBlock('system_menu_block:account');
    $this
      ->loginAsAdmin($this->localManagerPermissions);
    $edit = [
      'admin_theme' => 'seven',
      'use_admin_theme' => TRUE,
    ];
    $this
      ->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
    $settings = \Drupal::config('tmgmt_local.settings');
    $this
      ->assertTrue($settings
      ->get('use_admin_theme'));
    $this
      ->drupalGet('admin/tmgmt');
    $this
      ->assertText('Translate');
    $this
      ->drupalGet('<front>');
    $this
      ->assertNoText('Translate');
    $this
      ->drupalGet('admin/tmgmt/settings');
    $edit = [
      'use_admin_theme' => FALSE,
    ];
    $this
      ->drupalPostForm(NULL, $edit, t('Save configuration'));
    $settings = \Drupal::config('tmgmt_local.settings');
    $this
      ->assertFalse($settings
      ->get('use_admin_theme'));
    $this
      ->drupalGet('admin/tmgmt');
    $this
      ->assertNoText('Translate');
    $this
      ->drupalGet('<front>');
    $this
      ->assertText('Translate');
  }

  /**
   * Test the task and task items are closed and completed when aborting a Job.
   */
  public function testAbort() {

    // Prepare the scenario.
    $translator = Translator::load('local');
    $this
      ->loginAsTranslator($this->localTranslatorPermissions);
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->drupalPostForm('user/' . $this->translator_user
      ->id() . '/edit', $edit, t('Save'));
    $job = $this
      ->createJob();
    $job->translator = $translator
      ->id();
    $first_job_item = $job
      ->addItem('test_source', 'test', '1');
    \Drupal::state()
      ->set('tmgmt.test_source_data', [
      'dummy' => [
        'deep_nesting' => [
          '#text' => file_get_contents(drupal_get_path('module', 'tmgmt') . '/tests/testing_html/sample.html'),
          '#label' => 'Label for job item with type test and id 2.',
          '#translate' => TRUE,
          '#format' => 'basic_html',
        ],
      ],
    ]);
    $second_job_item = $job
      ->addItem('test_source', 'test', '2');
    $job
      ->save();
    $edit = [
      'settings[translator]' => $this->translator_user
        ->id(),
    ];
    $this
      ->drupalPostForm($job
      ->toUrl(), $edit, t('Submit to provider'));

    // Check Job Item abort, close the task item.
    $this
      ->drupalGet('admin/tmgmt/items/' . $first_job_item
      ->id() . '/abort');
    $this
      ->drupalPostForm(NULL, [], t('Confirm'));
    $this
      ->drupalGet('translate');
    $this
      ->assertNoRaw('views-field-progress">Closed');
    $this
      ->clickLink(t('View'));
    $this
      ->assertRaw('views-field-progress">Closed');
    $this
      ->assertNotEmpty(preg_match('|translate/(\\d+)|', $this
      ->getUrl(), $matches), 'Task found');

    /** @var \Drupal\tmgmt_local\Entity\LocalTask $task */
    $task = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task')
      ->load($matches[1]);
    $this
      ->assertTrue($task
      ->isPending());

    // Checking if the 'Save as completed' button is not displayed.
    $this
      ->drupalGet('translate/items/1');
    $elements = $this
      ->xpath('//*[@id="edit-save-as-completed"]');
    $this
      ->assertTrue(empty($elements), "'Save as completed' button does not appear.");

    // Checking if the 'Save' button is not displayed.
    $elements = $this
      ->xpath('//*[@id="edit-save"]');
    $this
      ->assertTrue(empty($elements), "'Save' button does not appear.");

    // Checking if the 'Preview' button is not displayed.
    $elements = $this
      ->xpath('//*[@id="edit-preview"]');
    $this
      ->assertTrue(empty($elements), "'Preview' button does not appear.");

    // Checking if the '✓' button is not displayed.
    $elements = $this
      ->xpath('//*[@id="edit-dummydeep-nesting-actions-finish-dummydeep-nesting"]');
    $this
      ->assertTrue(empty($elements), "'✓' button does not appear.");

    // Checking translation is readonly.
    $this
      ->assertRaw('data-drupal-selector="edit-dummydeep-nesting-translation" readonly="readonly"');

    // Check closing all task items also closes the task.
    $this
      ->drupalGet('admin/tmgmt/items/' . $second_job_item
      ->id() . '/abort');
    $this
      ->drupalPostForm(NULL, [], t('Confirm'));
    $this
      ->drupalGet('translate/closed');
    $this
      ->assertText($task
      ->label());
    $task = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_local_task')
      ->loadUnchanged($matches[1]);
    $this
      ->assertTrue($task
      ->isClosed());
    $this
      ->assertRaw('views-field-progress">Closed');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertCacheTag protected function Asserts whether an expected cache tag was present in the last response.
AssertLegacyTrait::assertElementNotPresent protected function Asserts that the element with the given CSS selector is not present.
AssertLegacyTrait::assertElementPresent protected function Asserts that the element with the given CSS selector is present.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertLegacyTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertLegacyTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertLegacyTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertLegacyTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertLegacyTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertLegacyTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertLegacyTrait::assertHeader protected function Checks that current response header equals value.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertLink protected function Passes if a link with the specified label is found.
AssertLegacyTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertLegacyTrait::assertNoCacheTag protected function Asserts whether an expected cache tag was absent in the last response.
AssertLegacyTrait::assertNoEscaped protected function Passes if the raw text is not found escaped on the loaded page.
AssertLegacyTrait::assertNoField protected function Asserts that a field does NOT exist with the given name or ID.
AssertLegacyTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertLegacyTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertLegacyTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertLegacyTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertLegacyTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertLegacyTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertLegacyTrait::assertNoOption protected function Asserts that a select option does NOT exist in the current page.
AssertLegacyTrait::assertNoPattern protected function Triggers a pass if the Perl regex pattern is not found in the raw content.
AssertLegacyTrait::assertNoRaw protected function Passes if the raw text IS not found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text. 1
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertLegacyTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertLegacyTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertLegacyTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertLegacyTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertLegacyTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertResponse protected function Asserts the page responds with the specified response code. 1
AssertLegacyTrait::assertText protected function Passes if the page (with HTML stripped) contains the text. 1
AssertLegacyTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertLegacyTrait::assertTitle protected function Pass if the page title is the given string.
AssertLegacyTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertLegacyTrait::assertUrl protected function Passes if the internal browser's URL matches the given path.
AssertLegacyTrait::buildXPathQuery protected function Builds an XPath query.
AssertLegacyTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertLegacyTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertLegacyTrait::getRawContent protected function Gets the current raw content.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
BlockCreationTrait::placeBlock protected function Creates a block instance based on default settings. Aliased as: drupalPlaceBlock
BrowserHtmlDebugTrait::$htmlOutputBaseUrl protected property The Base URI to use for links to the output files.
BrowserHtmlDebugTrait::$htmlOutputClassName protected property Class name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounter protected property Counter for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounterStorage protected property Counter storage for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputDirectory protected property Directory name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputEnabled protected property HTML output output enabled.
BrowserHtmlDebugTrait::$htmlOutputFile protected property The file name to write the list of URLs to.
BrowserHtmlDebugTrait::$htmlOutputTestId protected property HTML output test ID.
BrowserHtmlDebugTrait::formatHtmlOutputHeaders protected function Formats HTTP headers as string for HTML output logging.
BrowserHtmlDebugTrait::getHtmlOutputHeaders protected function Returns headers in HTML output format. 1
BrowserHtmlDebugTrait::htmlOutput protected function Logs a HTML output message in a text file.
BrowserHtmlDebugTrait::initBrowserOutputFile protected function Creates the directory to store browser output.
BrowserTestBase::$baseUrl protected property The base URL.
BrowserTestBase::$configImporter protected property The config importer that can be used in a test.
BrowserTestBase::$customTranslations protected property An array of custom translations suitable for drupal_rewrite_settings().
BrowserTestBase::$databasePrefix protected property The database prefix of this test run.
BrowserTestBase::$mink protected property Mink session manager.
BrowserTestBase::$minkDefaultDriverArgs protected property
BrowserTestBase::$minkDefaultDriverClass protected property 1
BrowserTestBase::$originalContainer protected property The original container.
BrowserTestBase::$originalShutdownCallbacks protected property The original array of shutdown function callbacks.
BrowserTestBase::$preserveGlobalState protected property
BrowserTestBase::$profile protected property The profile to install as a basis for testing. 39
BrowserTestBase::$root protected property The app root.
BrowserTestBase::$runTestInSeparateProcess protected property Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests.
BrowserTestBase::$timeLimit protected property Time limit in seconds for the test.
BrowserTestBase::$translationFilesDirectory protected property The translation file directory for the test environment.
BrowserTestBase::cleanupEnvironment protected function Clean up the Simpletest environment.
BrowserTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
BrowserTestBase::cssSelectToXpath protected function Translates a CSS expression to its XPath equivalent.
BrowserTestBase::drupalGetHeader protected function Gets the value of an HTTP response header.
BrowserTestBase::drupalGetHeaders Deprecated protected function Returns all response headers.
BrowserTestBase::filePreDeleteCallback public static function Ensures test files are deletable.
BrowserTestBase::getDefaultDriverInstance protected function Gets an instance of the default Mink driver.
BrowserTestBase::getDrupalSettings protected function Gets the JavaScript drupalSettings variable for the currently-loaded page. 1
BrowserTestBase::getHttpClient protected function Obtain the HTTP client for the system under test.
BrowserTestBase::getMinkDriverArgs protected function Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. 1
BrowserTestBase::getOptions protected function Helper function to get the options of select field.
BrowserTestBase::getResponseLogHandler protected function Provides a Guzzle middleware handler to log every response received. Overrides BrowserHtmlDebugTrait::getResponseLogHandler
BrowserTestBase::getSession public function Returns Mink session.
BrowserTestBase::getSessionCookies protected function Get session cookies from current session.
BrowserTestBase::getTestMethodCaller protected function Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait::getTestMethodCaller
BrowserTestBase::initFrontPage protected function Visits the front page when initializing Mink. 3
BrowserTestBase::initMink protected function Initializes Mink sessions. 1
BrowserTestBase::installDrupal public function Installs Drupal into the Simpletest site. 1
BrowserTestBase::registerSessions protected function Registers additional Mink sessions.
BrowserTestBase::tearDown protected function 3
BrowserTestBase::translatePostValues protected function Transforms a nested array into a flat array suitable for drupalPostForm().
BrowserTestBase::xpath protected function Performs an xpath search on the contents of the internal browser.
BrowserTestBase::__construct public function 1
BrowserTestBase::__sleep public function Prevents serializing any properties.
CommentTestTrait::addDefaultCommentField public function Adds the default comment field to an entity.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. Aliased as: drupalCreateContentType 1
FunctionalTestSetupTrait::$apcuEnsureUniquePrefix protected property The flag to set 'apcu_ensure_unique_prefix' setting. 1
FunctionalTestSetupTrait::$classLoader protected property The class loader to use for installation and initialization of setup.
FunctionalTestSetupTrait::$configDirectories Deprecated protected property The config directories used in this test.
FunctionalTestSetupTrait::$rootUser protected property The "#1" admin user.
FunctionalTestSetupTrait::doInstall protected function Execute the non-interactive installer. 1
FunctionalTestSetupTrait::getDatabaseTypes protected function Returns all supported database driver installer objects.
FunctionalTestSetupTrait::initConfig protected function Initialize various configurations post-installation. 2
FunctionalTestSetupTrait::initKernel protected function Initializes the kernel after installation.
FunctionalTestSetupTrait::initSettings protected function Initialize settings created during install.
FunctionalTestSetupTrait::initUserSession protected function Initializes user 1 for the site to be installed.
FunctionalTestSetupTrait::installDefaultThemeFromClassProperty protected function Installs the default theme defined by `static::$defaultTheme` when needed.
FunctionalTestSetupTrait::installModulesFromClassProperty protected function Install modules defined by `static::$modules`. 1
FunctionalTestSetupTrait::installParameters protected function Returns the parameters that will be used when Simpletest installs Drupal. 9
FunctionalTestSetupTrait::prepareEnvironment protected function Prepares the current environment for running the test. 23
FunctionalTestSetupTrait::prepareRequestForGenerator protected function Creates a mock request and sets it on the generator.
FunctionalTestSetupTrait::prepareSettings protected function Prepares site settings and services before installation. 2
FunctionalTestSetupTrait::rebuildAll protected function Resets and rebuilds the environment after setup.
FunctionalTestSetupTrait::rebuildContainer protected function Rebuilds \Drupal::getContainer().
FunctionalTestSetupTrait::resetAll protected function Resets all data structures after having enabled new modules.
FunctionalTestSetupTrait::setContainerParameter protected function Changes parameters in the services.yml file.
FunctionalTestSetupTrait::setupBaseUrl protected function Sets up the base URL based upon the environment variable.
FunctionalTestSetupTrait::writeSettings protected function Rewrites the settings.php file of the test site.
LocalTranslatorTest::testAbilitiesAPI public function
LocalTranslatorTest::testAbort public function Test the task and task items are closed and completed when aborting a Job.
LocalTranslatorTest::testAllowAll public function Test the allow all setting.
LocalTranslatorTest::testAssigneeSkillsForTasks public function Test assignee skills.
LocalTranslatorTest::testBasicWorkflow public function Test the basic translation workflow.
LocalTranslatorTest::testLocalProgress public function Tests of the task progress.
LocalTranslatorTest::testSettings public function Test the settings of TMGMT local.
LocalTranslatorTest::testUserPermissionsAccess public function Test permissions for the tmgmt_local VBO actions.
LocalTranslatorTest::testVBOPermissions public function Test permissions for the tmgmt_local VBO actions.
LocalTranslatorTestBase::$assignee protected property Translator user.
LocalTranslatorTestBase::$localManagerPermissions protected property
LocalTranslatorTestBase::$localTranslatorPermissions protected property
LocalTranslatorTestBase::$modules public static property Modules to enable. Overrides TMGMTTestBase::$modules 2
LocalTranslatorTestBase::assertTaskItemProgress protected function Asserts the task item progress bar.
LocalTranslatorTestBase::assertTaskItemStatusIcon protected function Asserts task item status icon.
LocalTranslatorTestBase::assertTaskProgress protected function Asserts the task progress bar.
LocalTranslatorTestBase::assertTaskStatusIcon protected function Asserts task status icon.
LocalTranslatorTestBase::setUp public function Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase::setUp
NodeCreationTrait::createNode protected function Creates a node based on default settings. Aliased as: drupalCreateNode
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
RefreshVariablesTrait::refreshVariables protected function Refreshes in-memory configuration and state information. 3
SessionTestTrait::$sessionName protected property The name of the session cookie.
SessionTestTrait::generateSessionName protected function Generates a session cookie name.
SessionTestTrait::getSessionName protected function Returns the session name in use on the child site.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
TestSetupTrait::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
TestSetupTrait::$container protected property The dependency injection container used in the test.
TestSetupTrait::$kernel protected property The DrupalKernel instance used in the test.
TestSetupTrait::$originalSite protected property The site directory of the original parent site.
TestSetupTrait::$privateFilesDirectory protected property The private file directory for the test environment.
TestSetupTrait::$publicFilesDirectory protected property The public file directory for the test environment.
TestSetupTrait::$siteDirectory protected property The site directory of this test run.
TestSetupTrait::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 2
TestSetupTrait::$tempFilesDirectory protected property The temporary file directory for the test environment.
TestSetupTrait::$testId protected property The test run ID.
TestSetupTrait::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
TestSetupTrait::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
TestSetupTrait::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestSetupTrait::prepareDatabasePrefix protected function Generates a database prefix for running tests. 2
TmgmtEntityTestTrait::$field_names public property
TmgmtEntityTestTrait::attachFields function Creates fields of type text and text_with_summary of different cardinality.
TmgmtEntityTestTrait::createNodeType function Creates node type with several text fields with different cardinality.
TmgmtEntityTestTrait::createTaxonomyTerm function Creates a taxonomy term of a given vocabulary.
TmgmtEntityTestTrait::createTaxonomyVocab function Creates taxonomy vocabulary with custom fields.
TmgmtEntityTestTrait::createTranslatableNode protected function Creates a node of a given bundle.
TMGMTTestBase::$defaultTheme protected property The theme to install as the default for testing. Overrides BrowserTestBase::$defaultTheme
TMGMTTestBase::$default_translator protected property A default translator using the test translator.
TmgmtTestTrait::$admin_permissions protected property List of permissions used by loginAsAdmin().
TmgmtTestTrait::$admin_user protected property Drupal user object created by loginAsAdmin().
TmgmtTestTrait::$languageWeight protected property The language weight for new languages.
TmgmtTestTrait::$translator_permissions protected property List of permissions used by loginAsTranslator().
TmgmtTestTrait::$translator_user protected property Drupal user object created by loginAsTranslator().
TmgmtTestTrait::addLanguage function Sets the proper environment.
TmgmtTestTrait::assertJobItemLangCodes function Asserts job item language codes.
TmgmtTestTrait::assertTextByXpath protected function Asserts text in the page with an xpath expression.
TmgmtTestTrait::clickLinkWithImageTitle function Clicks on an image link with the provided title attribute.
TmgmtTestTrait::createJob function Creates, saves and returns a translation job.
TmgmtTestTrait::createTranslator function Creates, saves and returns a translator.
TmgmtTestTrait::loginAsAdmin function Will create a user with admin permissions and log it in.
TmgmtTestTrait::loginAsTranslator function Will create a user with translator permissions and log it in.
UiHelperTrait::$loggedInUser protected property The current user logged in using the Mink controlled browser.
UiHelperTrait::$maximumMetaRefreshCount protected property The number of meta refresh redirects to follow, or NULL if unlimited.
UiHelperTrait::$metaRefreshCount protected property The number of meta refresh redirects followed during ::drupalGet().
UiHelperTrait::assertSession public function Returns WebAssert object. 1
UiHelperTrait::buildUrl protected function Builds an a absolute URL from a system path or a URL object.
UiHelperTrait::checkForMetaRefresh protected function Checks for meta refresh tag and if found call drupalGet() recursively.
UiHelperTrait::click protected function Clicks the element with the given CSS selector.
UiHelperTrait::clickLink protected function Follows a link by complete name.
UiHelperTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
UiHelperTrait::drupalGet protected function Retrieves a Drupal path or an absolute path. 3
UiHelperTrait::drupalLogin protected function Logs in a user using the Mink controlled browser.
UiHelperTrait::drupalLogout protected function Logs a user out of the Mink controlled browser and confirms.
UiHelperTrait::drupalPostForm protected function Executes a form submission.
UiHelperTrait::drupalUserIsLoggedIn protected function Returns whether a given user account is logged in.
UiHelperTrait::getAbsoluteUrl protected function Takes a path and returns an absolute path.
UiHelperTrait::getTextContent protected function Retrieves the plain-text content from the current page.
UiHelperTrait::getUrl protected function Get the current URL from the browser.
UiHelperTrait::prepareRequest protected function Prepare for a request to testing site. 1
UiHelperTrait::submitForm protected function Fills and submits a form.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions. Aliased as: drupalCreateRole
UserCreationTrait::createUser protected function Create a user with a given set of permissions. Aliased as: drupalCreateUser
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.
XdebugRequestTrait::extractCookiesFromRequest protected function Adds xdebug cookies, from request setup.