Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Entity/LocalgovGeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* revision_data_table = "localgov_geo_field_revision",
* show_revision_ui = TRUE,
* translatable = TRUE,
* admin_permission = "administer geo types",
* admin_permission = "access geo overview",
* entity_keys = {
* "id" = "id",
* "revision" = "revision_id",
Expand Down
1 change: 1 addition & 0 deletions src/LocalgovGeoListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function render() {

$total = $this->getStorage()
->getQuery()
->accessCheck(TRUE)
->count()
->execute();

Expand Down
4 changes: 2 additions & 2 deletions tests/src/Functional/GeoBundleCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GeoBundleCreationTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'system',
'text',
'field_ui',
Expand Down Expand Up @@ -58,7 +58,7 @@ class GeoBundleCreationTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();

// Have two users ready to be used in tests.
Expand Down
120 changes: 120 additions & 0 deletions tests/src/Functional/GeoOverviewAccessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace Drupal\Tests\localgov_geo\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Geo ovewview page access tests.
*
* Ensures that non-admin users with the right permissions can access the Geo
* overview page.
*
* @group localgov_geo
*/
class GeoOverviewAccessTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'localgov_geo',
];

/**
* Permissions for the admin user that will be logged-in for test.
*
* @var array
*/
protected static $adminUserPermissions = [
'access geo overview',
'delete geo',
'create geo',
'edit geo',
'administer geo types',
];

/**
* Permissions given to an Editor user.
*
* @var array
*/
protected static $nonAdminUserPermissions = [
'access geo overview',
'create geo',
'edit geo',
'delete geo',
];

/**
* Permissions for non-editor who can create geo.
*
* @var array
*/
protected static $creatorUserPermissions = [
'create geo',
'edit geo',
];

/**
* An admin test user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $adminUser;

/**
* A non-admin test user account.
*
* @var \drupal\user\userinterface
*/
protected $nonAdminUser;

/**
* A creator test user account.
*
* @var \drupal\user\userinterface
*/
protected $creatorUser;

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

// Have two users ready to be used in tests.
$this->adminUser = $this->drupalCreateUser(static::$adminUserPermissions);
$this->nonAdminUser = $this->drupalCreateUser(static::$nonAdminUserPermissions);
$this->creatorUser = $this->drupalCreateUser(static::$creatorUserPermissions);

// Start off logged in as admin.
$this->drupalLogin($this->adminUser);
}

/**
* Access test for the Geo overview page.
*
* The Editor user should be able to access the overview page.
*/
public function testOverviewPageAccess() {

$this->drupalGet('/admin/content/geo');
$this->assertSession()->statusCodeEquals(200);

$this->drupalLogin($this->nonAdminUser);
$this->drupalGet('/admin/content/geo');
$this->assertSession()->statusCodeEquals(200);

$this->drupalLogin($this->creatorUser);
$this->drupalGet('/admin/content/geo');
$this->assertSession()->statusCodeEquals(403);
}

}