Correcting UserViewsFieldAccessTest

Created on 5 December 2017, almost 7 years ago
Updated 18 January 2023, over 1 year ago

Follow-up to #2917584-49: Some tests only go green because they happen to run as UID1 β†’

Problem/Motivation

UserViewsFieldAccessTest extends FieldFieldAccessTestBase, where we have $userWithAccess instance with unexpected user/1 mode.

As a result, the UserViewsFieldAccessTest::testUserFields() checks access for user with full access, which is obviously not the goal of this test.

However, it would be good to keep assertions for user with 'administer users' permission too.

If we move this assertions to separate test, than another fun challenge arises. What to do with a commented code?

    // $this->assertFieldAccess('user', 'mail', 'druplicon@drop.org');
    // $this->assertFieldAccess('user', 'created', \Drupal::service('date.formatter')->format(123456));
    // $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));

Proposed resolution

  1. Decouple test on two tests:
    • for user with 'view test entity field', 'access content' permissions
    • for user with 'administer users' permission
  2. Do not touch the commented code (just duplicate it to both tests), because we already have issue about it ( πŸ“Œ Follow-up: Enable additional tests for base entity field access checking in Views Needs work )
  3. Fix unexpected user/1 access for $userWithAccess in FieldFieldAccessTestBase, to prevent similar defects in the future.

Remaining tasks

To choose the most suitable solution:

  • fix the root of the problem - in the FieldFieldAccessTestBase class (see #2)
  • fix only the effects of the problem in the UserViewsFieldAccessTest (see #4, #5).

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
User moduleΒ  β†’

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024