use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
-use Drupal\taxonomy\Entity\Vocabulary;
-use Drupal\user\Entity\User;
use Drupal\permissions_by_term\Service\AccessCheck;
-use Drupal\taxonomy\Entity\Term;
use Drupal\permissions_by_term\Service\AccessStorage;
+use Drupal\taxonomy\Entity\Term;
+use Drupal\taxonomy\Entity\Vocabulary;
+use Drupal\user\Entity\User;
/**
* Class PBTKernelTestBase
/**
* @var int
*/
- protected $nidNoTerms;
+ protected $nidNoRestriction;
/**
* {@inheritdoc}
*/
- public static $modules = ['taxonomy', 'node', 'user', 'text', 'field', 'system', 'permissions_by_term'];
+ public static $modules = ['taxonomy', 'node', 'user', 'text', 'field', 'system', 'permissions_by_term', 'language'];
/**
* @var AccessStorage
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(['permissions_by_term']);
+ $this->installConfig(['language']);
$this->installSchema('node', 'node_access');
$this->installSchema('permissions_by_term', 'permissions_by_term_user');
$this->installSchema('permissions_by_term', 'permissions_by_term_role');
$this->accessStorage = $this->container->get('permissions_by_term.access_storage');
$this->accessCheck = $this->container->get('permissions_by_term.access_check');
\Drupal::configFactory()->getEditable('taxonomy.settings')->set('maintain_index_table', TRUE)->save();
- $this->createTestVocabulary();
+ $this->createTestVocabularies();
$this->createPageNodeType();
$this->createCurrentUser();
}
- protected function createTestVocabulary() {
+ protected function createTestVocabularies() {
Vocabulary::create([
'name' => 'test',
'vid' => 'test',
])->save();
+
+ Vocabulary::create([
+ 'name' => 'test2',
+ 'vid' => 'test2',
+ ])->save();
}
protected function createPageNodeType() {
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
])->save();
+ FieldStorageConfig::create([
+ 'entity_type' => 'node',
+ 'field_name' => 'field_tags2',
+ 'type' => 'entity_reference',
+ 'settings' => [
+ 'target_type' => 'taxonomy_term',
+ ],
+ 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
+ ])->save();
+
FieldConfig::create([
'field_name' => 'field_tags',
'entity_type' => 'node',
'bundle' => 'page',
])->save();
+
+ FieldConfig::create([
+ 'field_name' => 'field_tags2',
+ 'entity_type' => 'node',
+ 'bundle' => 'page',
+ ])->save();
}
protected function createCurrentUser() {
$term->save();
$tids[] = $term->id();
+ $term = Term::create([
+ 'name' => 'term3',
+ 'vid' => 'test2',
+ ]);
+ $term->save();
+ $tids[] = $term->id();
+
$this->accessStorage->addTermPermissionsByUserIds([99], $term->id());
$node = Node::create([
[
'target_id' => $tids[1]
],
+ ],
+ 'field_tags2' => [
+ [
+ 'target_id' => $tids[2]
+ ]
]
]);
$node->save();
$this->setNidAllGrantedTerms($node->id());
}
- protected function createRelationNoTerms() {
+ protected function createRelationWithoutRestriction() {
$term = Term::create([
'name' => 'term1',
'vid' => 'test',
$term->save();
$tids[] = $term->id();
- $this->accessStorage->addTermPermissionsByUserIds([\Drupal::service('current_user')->id()], $term->id());
-
$term = Term::create([
'name' => 'term2',
'vid' => 'test',
$term->save();
$tids[] = $term->id();
- $this->accessStorage->addTermPermissionsByUserIds([\Drupal::service('current_user')->id()], $term->id());
-
$node = Node::create([
'type' => 'page',
'title' => 'test_title',
]
]);
$node->save();
- $this->setNidNoTerms($node->id());
+ $this->setNidNoRestriction($node->id());
}
/**
* @return int
*/
- protected function getNidNoTerms() {
- return $this->nidNoTerms;
+ protected function getNidNoRestriction() {
+ return $this->nidNoRestriction;
}
/**
- * @param int $nidNoTerms
+ * @param int $nidNoRestiction
*/
- protected function setNidNoTerms($nidNoTerms) {
- $this->nidNoTerms = $nidNoTerms;
+ protected function setNidNoRestriction($nidNoRestiction) {
+ $this->nidNoRestriction = $nidNoRestiction;
}
-}
\ No newline at end of file
+}