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
- Decouple test on two tests:
- for user with
'view test entity field', 'access content'
permissions - for user with
'administer users'
permission
- for user with
- Do not touch the commented code (just duplicate it to both tests), because we already have issue about it (#2464635: Follow-up: Enable additional tests for base entity field access checking in Views)
- Fix unexpected user/1 access for
$userWithAccess
inFieldFieldAccessTestBase
, to prevent similar defects in the future. Override$userWithAccess
inside UserViewsFieldAccessTest tests, and fixing$userWithAccess
ofFieldFieldAccessTestBase
in #540008: Remove the special behavior of uid #1..
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).