diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php index a2d7eef..156de4c 100644 --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -19,7 +19,8 @@ * "default" = "Drupal\taxonomy\VocabularyForm", * "reset" = "Drupal\taxonomy\Form\VocabularyResetForm", * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" - * } + * }, + * "access" = "Drupal\taxonomy\VocabularyAccessControlHandler" * }, * admin_permission = "administer taxonomy", * config_prefix = "vocabulary", diff --git a/core/modules/taxonomy/src/VocabularyAccessControlHandler.php b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php new file mode 100644 index 0000000..309b26e --- /dev/null +++ b/core/modules/taxonomy/src/VocabularyAccessControlHandler.php @@ -0,0 +1,29 @@ +prophesize(CacheContextsManager::class); + $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); + $cache_contexts_manager->reveal(); + $container = new Container(); + $container->set('cache_contexts_manager', $cache_contexts_manager); + \Drupal::setContainer($container); + } + + /** + * Asserts correct vocabulary access for a vocabulary. + */ + public function assertVocabularyAccess($viewer, $target, $view, $edit) { + foreach (array('view' => $view, 'edit' => $edit) as $operation => $result) { + $result_text = !isset($result) ? 'null' : ($result ? 'true' : 'false'); + $message = "Access returns '$result_text' with operation '$operation' for '$viewer' accessing '$target'"; + $this->assertSame($result, TRUE, $message); + } + } + + /** + * Tests anonymous access to vocabulary config entities. + * + * @dataProvider vocabularyProvider + */ + public function testVocabularyAccess($viewer, $target, $view, $edit) { + $this->assertVocabularyAccess($viewer, $target, $view, $edit); + } + + /** + * Provides test data for testVocabularyAccess(). + */ + public function vocabularyProvider() { + + $anonymous = new UserSession(array( + 'uid' => 1, + 'roles' => array(), + )); + + $vocabulary_access = array( + // Anonymous users are allowed to view vocabulary config entities by + // default. + array( + 'viewer' => 'anonymous', + 'target' => 'tags', + 'view' => TRUE, + 'edit' => FALSE, + ), + ); + return $vocabulary_access; + } + +}