You are here

public function TranslationOperationsFieldPermissionsTest::testTranslationOperationsCreatePermissions in Translation Views 8

Test translation operation create permissions.

Throws

\Behat\Mink\Exception\ElementTextException

\Behat\Mink\Exception\ExpectationException

File

tests/src/Functional/TranslationOperationsFieldPermissionsTest.php, line 136

Class

TranslationOperationsFieldPermissionsTest
Class TranslationOperationsFieldPermissionsTest.

Namespace

Drupal\Tests\translation_views\Functional

Code

public function testTranslationOperationsCreatePermissions() {
  $default_language = \Drupal::languageManager()
    ->getDefaultLanguage();
  $target_language = static::$langcodes[mt_rand(0, 4)];
  $this
    ->assertNotNull($target_language);
  $this
    ->assertNotNull($default_language);
  $userCreate = $this
    ->createUser([
    'create content translations',
  ]);
  $this
    ->drupalLogin($userCreate);
  $this
    ->drupalGet('/translate/content', [
    'query' => [
      'langcode' => $default_language
        ->getId(),
      'translation_target_language' => $target_language,
      'translation_outdated' => 'All',
      'translation_status' => 'All',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementNotExists('css', 'table > tbody > tr:nth-child(1) .views-field-translation-operations ul li a');
  $this
    ->addPermissionsForAuthUser([
    'translate any entity',
  ]);
  $this
    ->assertTrue($userCreate
    ->hasPermission('translate any entity'));
  $this
    ->drupalGet('/translate/content', [
    'query' => [
      'langcode' => $default_language
        ->getId(),
      'translation_target_language' => $target_language,
      'translation_outdated' => 'All',
      'translation_status' => 'All',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementTextContains('css', "table > tbody > tr:nth-child(1) .views-field-translation-operations ul li a", 'Add');
}