From da63e12607cc87e0d9c581998cc93945ed15add3 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Wed, 27 Feb 2013 20:19:51 -0500 Subject: [PATCH] Issue #1919928 by larowlan: Resolve usage of 'view content' permission in modules other than Node. --- .../CustomBlockAccessController.php | 2 +- .../Tests/CustomBlockPageViewTest.php | 57 +++++++++++++++++++ .../custom_block_test.module | 19 ++++++- 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockPageViewTest.php diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php index e9c1e3106803..01421f2042ad 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php @@ -20,7 +20,7 @@ class CustomBlockAccessController implements EntityAccessControllerInterface { * Implements EntityAccessControllerInterface::viewAccess(). */ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { - return user_access('view content', $account); + return TRUE; } /** diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockPageViewTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockPageViewTest.php new file mode 100644 index 000000000000..0841fd9a8a0e --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockPageViewTest.php @@ -0,0 +1,57 @@ +<?php + +/** + * @file + * Contains \Drupal\custom_block\Tests\CustomBlockPageViewTest. + */ + +namespace Drupal\custom_block\Tests; + +/** + * Tests the block edit functionality. + */ +class CustomBlockPageViewTest extends CustomBlockTestBase { + + /** + * Permissions to grant admin user. + * + * @var array + */ + protected $permissions = array( + 'administer blocks', + 'access content' + ); + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('block', 'custom_block', 'custom_block_test'); + + /** + * Declares test information. + */ + public static function getInfo() { + return array( + 'name' => 'Custom Block page view', + 'description' => 'Create a block and test block access by attempting to view the block.', + 'group' => 'Custom Block', + ); + } + + /** + * Checks block edit functionality. + */ + public function testPageEdit() { + $this->drupalLogin($this->adminUser); + $block = $this->createCustomBlock(); + + // Attempt to view the block. + $this->drupalGet('custom-block/' . $block->id()); + + // Assert response was '200' and not '403 Access denied'. + $this->assertResponse('200', 'User was able the view the block'); + } + +} diff --git a/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module b/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module index 76bccdc4db80..a2961fc641fb 100644 --- a/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module +++ b/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module @@ -73,10 +73,27 @@ function custom_block_test_custom_block_update(CustomBlock $custom_block) { function custom_block_test_custom_block_insert(CustomBlock $custom_block) { // Set the custom_block title to the custom_block ID and save. if ($custom_block->info->value == 'new') { - $custom_block->info->value = 'CustomBlock '. $custom_block->id->value; + $custom_block->info->value = 'CustomBlock ' . $custom_block->id->value; $custom_block->save(); } if ($custom_block->info->value == 'fail_creation') { throw new Exception('Test exception for rollback.'); } } + +/** + * Implements hook_menu(). + */ +function custom_block_test_menu() { + $items = array(); + // Add a block-view callback. + $items['custom-block/%custom_block'] = array( + 'title callback' => 'entity_page_label', + 'title arguments' => array(1), + 'page callback' => 'entity_view', + 'page arguments' => array(1, 'default'), + 'access callback' => 'entity_page_access', + 'access arguments' => array(1, 'view'), + ); + return $items; +} -- GitLab