translators-8.x-1.x-dev/modules/translators_content/tests/src/Functional/TranslatorsContentPermissionNodeTest.php
modules/translators_content/tests/src/Functional/TranslatorsContentPermissionNodeTest.php
<?php
namespace Drupal\Tests\translators_content\Functional;
/**
* Class TranslatorsContentPermissionNodeTest.
*
* @package Drupal\Tests\translators_content\Functional
*
* @group translators_content
*/
class TranslatorsContentPermissionNodeTest extends TranslatorsContentPermissionTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['translators_content', 'node'];
/**
* {@inheritdoc}
*/
protected $entityTypeId = 'node';
/**
* {@inheritdoc}
*/
protected $bundle = 'article';
/**
* {@inheritdoc}
*/
protected $entityPermissionSupport = TRUE;
/**
* {@inheritdoc}
*/
public function testTranslatonPermissionsVisability() {
parent::testTranslatonPermissionsVisability();
$this->runTestEntityPermissionsVisability();
}
/**
* Test bypass node access permissions.
*/
public function testBypassNodeAccess() {
$bundle = $this->bundle;
$user = $this->createUser(['bypass node access']);
$this->expectedStatus = $this->getDefaultExpectedStatus(200);
$this->runTests($user);
}
/**
* Test create entity any language permissions.
*/
public function testCreateEntityAnyLanguage() {
$bundle = $this->bundle;
$user = $this->createUser([
"create $bundle content",
]);
$defaultStatus = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'create entity in any language' => 200,
'create entity in translation skills' => 200,
];
$this->expectedStatus = array_merge($defaultStatus, $expectedStatus);
$this->runTests($user);
}
/**
* Test edit entity any language permissions.
*/
public function testEditAnyEntityAnyLanguage() {
$bundle = $this->bundle;
$user = $this->createUser([
"edit any $bundle content",
]);
$defaultStatus = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'edit any entity in any language' => 200,
'edit any entity in translation skills' => 200,
'edit own entity' => 200,
];
$this->expectedStatus = array_merge($defaultStatus, $expectedStatus);
$this->runTests($user);
}
/**
* Test edit own entity permissions.
*/
public function testEditOwnEntity() {
$bundle = $this->bundle;
$user = $this->createUser([
"edit own $bundle content",
]);
$defaultStatus = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'edit own entity' => 200,
];
$this->expectedStatus = array_merge($defaultStatus, $expectedStatus);
$this->runTests($user);
}
/**
* Test delete entity any language permissions.
*/
public function testDeleteAnyEntityAnyLanguage() {
$bundle = $this->bundle;
$user = $this->createUser([
"delete any $bundle content",
]);
$defaultStatus = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'delete any entity in any language' => 200,
'delete any entity in translation skills' => 200,
'delete own entity' => 200,
];
$this->expectedStatus = array_merge($defaultStatus, $expectedStatus);
$this->runTests($user);
}
/**
* Test delete own entity permissions.
*/
public function testDeleteOwnEntity() {
$bundle = $this->bundle;
$user = $this->createUser([
"delete own $bundle content",
]);
$defaultStatus = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'delete own entity' => 200,
];
$this->expectedStatus = array_merge($defaultStatus, $expectedStatus);
$this->runTests($user);
}
/**
* Test create entity in translation skills permissions.
*/
public function testCreateEntityInTranslationSkills() {
$bundle = $this->bundle;
$user = $this->createUser([
"translators_content create $bundle node",
]);
$default_status = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'create entity in translation skills' => 200,
];
$this->expectedStatus = array_merge($default_status, $expectedStatus);
$this->runTests($user);
}
/**
* Test edit entity in translation skills permissions.
*/
public function testEditEntityInTranslationSkills() {
$bundle = $this->bundle;
$user = $this->createUser([
"translators_content edit any $bundle node",
]);
$default_status = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'edit any entity in translation skills' => 200,
];
$this->expectedStatus = array_merge($default_status, $expectedStatus);
$this->runTests($user);
}
/**
* Test delete entity in translation skills permissions.
*/
public function testDeleteEntityInTranslationSkills() {
$bundle = $this->bundle;
$user = $this->createUser([
"translators_content delete any $bundle node",
]);
$default_status = $this->getDefaultExpectedStatus(403);
$expectedStatus = [
'delete any entity in translation skills' => 200,
];
$this->expectedStatus = array_merge($default_status, $expectedStatus);
$this->runTests($user);
}
/**
* Create test node.
*
* @param null|string $langcode
* Optional. Default language ID.
* @param null|int $uid
* Optional. Author ID.
*/
public function createTestEntity($langcode = NULL, int $uid = NULL) {
return $this->createTestNode($langcode, $uid);
}
/**
* {@inheritdoc}
*/
public function addEntityTranslation($entity, $target, $source = NULL) {
return $this->addNodeTranslation($entity, $target, $source);
}
/**
* {@inheritdoc}
*/
public function getCreateEntityUrl($langcode = NULL) {
$bundle = $this->bundle;
if (empty($langcode) || $langcode == $this->getSiteDefaultLangcode()) {
return "/node/add/$bundle";
}
return "/$langcode/node/add/$bundle";
}
}
