function ContentTranslationPermissionsTest::testPermissions

Same name in other branches
  1. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationPermissionsTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationPermissionsTest::testPermissions()
  2. 11.x core/modules/content_translation/tests/src/Kernel/ContentTranslationPermissionsTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationPermissionsTest::testPermissions()

Tests that enabling translation via the API triggers schema updates.

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationPermissionsTest.php, line 41

Class

ContentTranslationPermissionsTest
Tests the content translation dynamic permissions.

Namespace

Drupal\Tests\content_translation\Kernel

Code

public function testPermissions() {
    $this->container
        ->get('content_translation.manager')
        ->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
    $this->container
        ->get('content_translation.manager')
        ->setEnabled('entity_test_mul_with_bundle', 'test', TRUE);
    $permissions = $this->container
        ->get('user.permissions')
        ->getPermissions();
    $this->assertEquals([
        'entity_test',
    ], $permissions['translate entity_test_mul']['dependencies']['module']);
    $this->assertEquals([
        'entity_test.entity_test_mul_bundle.test',
    ], $permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);
    // Ensure bundle permission granularity works for bundles not based on
    // configuration.
    $this->container
        ->get('state')
        ->set('entity_test_mul.permission_granularity', 'bundle');
    $this->container
        ->get('entity_type.manager')
        ->clearCachedDefinitions();
    $permissions = $this->container
        ->get('user.permissions')
        ->getPermissions();
    $this->assertEquals([
        'entity_test',
    ], $permissions['translate entity_test_mul entity_test_mul']['dependencies']['module']);
    $this->assertEquals([
        'entity_test.entity_test_mul_bundle.test',
    ], $permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.