Commit da63e126 authored by webchick's avatar webchick

Issue #1919928 by larowlan: Resolve usage of 'view content' permission in modules other than Node.

parent 2f027d5c
...@@ -20,7 +20,7 @@ class CustomBlockAccessController implements EntityAccessControllerInterface { ...@@ -20,7 +20,7 @@ class CustomBlockAccessController implements EntityAccessControllerInterface {
* Implements EntityAccessControllerInterface::viewAccess(). * Implements EntityAccessControllerInterface::viewAccess().
*/ */
public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) {
return user_access('view content', $account); return TRUE;
} }
/** /**
......
<?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');
}
}
...@@ -73,10 +73,27 @@ function custom_block_test_custom_block_update(CustomBlock $custom_block) { ...@@ -73,10 +73,27 @@ function custom_block_test_custom_block_update(CustomBlock $custom_block) {
function custom_block_test_custom_block_insert(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. // Set the custom_block title to the custom_block ID and save.
if ($custom_block->info->value == 'new') { 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(); $custom_block->save();
} }
if ($custom_block->info->value == 'fail_creation') { if ($custom_block->info->value == 'fail_creation') {
throw new Exception('Test exception for rollback.'); 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment