You are here

public function TranslationOperationsFieldPermissionsTest::testTranslationOperationsDeletePermissions in Translation Views 8

Test translation operation delete permissions.

Throws

\Behat\Mink\Exception\ElementTextException

\Behat\Mink\Exception\ExpectationException

File

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

Class

TranslationOperationsFieldPermissionsTest
Class TranslationOperationsFieldPermissionsTest.

Namespace

Drupal\Tests\translation_views\Functional

Code

public function testTranslationOperationsDeletePermissions() {
  $this
    ->translateNode();
  $userDelete = $this
    ->createUser([
    'delete content translations',
  ]);
  $this
    ->drupalLogin($userDelete);

  // Check without translation permission.
  $this
    ->drupalGet('/test_operations_links', [
    'query' => [
      'translation_target_language' => 'fr',
    ],
  ]);
  $this
    ->assertSession()
    ->elementTextNotContains('css', ".view-content > div:nth-child(1) .views-field-translation-operations", 'Delete');

  // Check with translation permission.
  $this
    ->addPermissionsForAuthUser([
    'translate article node',
  ]);
  $this
    ->assertTrue($userDelete
    ->hasPermission('translate article node'));
  $this
    ->drupalGet('/test_operations_links', [
    'query' => [
      'translation_target_language' => 'fr',
    ],
  ]);
  $this
    ->assertSession()
    ->elementTextContains('css', ".view-content > div:nth-child(1) .views-field-translation-operations ul .delete a", 'Delete');
  $this
    ->click('.view-content > div:nth-child(1) .views-field-translation-operations ul .delete a');
  $this
    ->assertUrl('/fr/node/1/translations/delete/fr');

  // Check with edit permission.
  $this
    ->addPermissionsForAuthUser([
    'delete any article content',
  ]);
  $this
    ->assertTrue($userDelete
    ->hasPermission('delete any article content'));
  $this
    ->drupalGet('/test_operations_links', [
    'query' => [
      'translation_target_language' => 'fr',
    ],
  ]);
  $this
    ->assertSession()
    ->elementTextContains('css', ".view-content > div:nth-child(1) .views-field-translation-operations ul .delete a", 'Delete');
  $this
    ->click('.view-content > div:nth-child(1) .views-field-translation-operations ul .delete a');
  $this
    ->assertUrl('/fr/node/1/delete');
}