class ContentTranslationPermissionsTest in Drupal 10
Same name and namespace in other branches
- 9 core/modules/content_translation/tests/src/Kernel/ContentTranslationPermissionsTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationPermissionsTest
Tests the content translation dynamic permissions.
@group content_translation
@coversDefaultClass \Drupal\content_translation\ContentTranslationPermissions
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\content_translation\Kernel\ContentTranslationPermissionsTest
Expanded class hierarchy of ContentTranslationPermissionsTest
File
- core/
modules/ content_translation/ tests/ src/ Kernel/ ContentTranslationPermissionsTest.php, line 15
Namespace
Drupal\Tests\content_translation\KernelView source
class ContentTranslationPermissionsTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'language',
'content_translation',
'user',
'entity_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test_mul');
$this
->installEntitySchema('entity_test_mul_with_bundle');
EntityTestMulBundle::create([
'id' => 'test',
'label' => 'Test label',
'description' => 'My test description',
])
->save();
}
/**
* Tests that enabling translation via the API triggers schema updates.
*/
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']);
}
}