Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

class TMGMTUiReviewTest

Verifies the UI of the review form.

@group tmgmt

Hierarchy

Expanded class hierarchy of TMGMTUiReviewTest

File

tests/src/Functional/TMGMTUiReviewTest.php, line 15

Namespace

Drupal\Tests\tmgmt\Functional
View source
class TMGMTUiReviewTest extends TMGMTTestBase {
  use TmgmtEntityTestTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'tmgmt_content',
    'image',
    'node',
  ];

  /**
   * {@inheritdoc}
   */
  function setUp() : void {
    parent::setUp();
    $this
      ->addLanguage('de');
    $filtered_html_format = FilterFormat::create(array(
      'format' => 'filtered_html',
      'name' => 'Filtered HTML',
    ));
    $filtered_html_format
      ->save();
    $this
      ->drupalCreateContentType(array(
      'type' => 'test_bundle',
    ));
    $this
      ->loginAsAdmin(array(
      'create translation jobs',
      'submit translation jobs',
      'create test_bundle content',
      $filtered_html_format
        ->getPermissionName(),
    ));
    \Drupal::service('file_system')
      ->copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg');
    $this->image = File::create(array(
      'uri' => 'public://example.jpg',
    ));
    $this->image
      ->save();
  }

  /**
   * Tests text format permissions on translation fields.
   */
  public function testTextFormatPermissions() {

    // Create a job.
    $job1 = $this
      ->createJob();
    $job1
      ->save();
    $job1
      ->setState(Job::STATE_ACTIVE);
    \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',
          '#format' => 'full_html',
        ),
      ),
    ));
    $item1 = $job1
      ->addItem('test_source', 'test', 1);
    $item1
      ->setState(JobItem::STATE_REVIEW);
    $item1
      ->save();
    $this
      ->drupalGet('admin/tmgmt/items/' . $item1
      ->id());

    // Assert that translator has no permission to review/update "body" field.
    $source_field_message = $this
      ->xpath('//*[@id="edit-bodydeep-nesting-source"]')[0];
    $translation_field_message = $this
      ->xpath('//*[@id="edit-bodydeep-nesting-translation"]')[0];
    $this
      ->assertEquals('This field has been disabled because you do not have sufficient permissions to edit it. It is not possible to review or accept this job item.', $source_field_message
      ->getText());
    $this
      ->assertEquals('This field has been disabled because you do not have sufficient permissions to edit it. It is not possible to review or accept this job item.', $translation_field_message
      ->getText());
    $this
      ->assertSession()
      ->responseNotContains('Save as completed" class="button button--primary js-form-submit form-submit"');

    // Remove full html format from the body field.
    $item1
      ->updateData('body|deep_nesting', [
      '#format' => '',
    ]);
    $item1
      ->save();

    // Translator should see enabled translation field again.
    $this
      ->drupalGet('admin/tmgmt/items/' . $item1
      ->id());
    $this
      ->assertSession()
      ->responseContains('Save as completed" class="button button--primary js-form-submit form-submit"');
    $this
      ->assertSession()
      ->fieldExists('body|deep_nesting[translation]');
    $translation_field = $this
      ->xpath('//*[@id="edit-bodydeep-nesting-translation"]')[0];
    $this
      ->assertEquals('', $translation_field
      ->getText());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
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.
TMGMTUiReviewTest::$modules protected static property Modules to enable. Overrides TMGMTTestBase::$modules
TMGMTUiReviewTest::setUp function Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase::setUp
TMGMTUiReviewTest::testTextFormatPermissions public function Tests text format permissions on translation fields.