Wound up figuring this out I suppose, although I have no idea if this is the proper way.
Under the custom module I wanted to test, I created a 'tests' directory with a test module and within that new module placed 3 configuration files from my project config ("Show Profile" field storage, "Show Profile" field instance, user form display configuration).
In a functional test, I required that module:
<?php
namespace Drupal\Tests\mymodule\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;
/**
* Class ProfileAccessTest
* @package Drupal\Tests\mymodule\Functional
*/
class ProfileAccessTest extends BrowserTestBase {
/**
* A set of test users.
*/
protected $user1, $user2, $user3, $user4;
/**
* {@inheritdoc}
*/
protected static $modules = ['node', 'user', 'mymodule', 'system', 'mymodule_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$anon_role = Role::load(Role::ANONYMOUS_ID);
$this->grantPermissions($anon_role, ['access user profiles']);
$this->user1 = $this->drupalCreateUser(['access content', 'access user profiles'], 'regular_user');
$this->user2 = $this->drupalCreateUser(['administer users'], 'john', TRUE);
$this->user3 = $this->drupalCreateUser([], 'zzz', FALSE);
$this->user4 = $this->drupalCreateUser([], 'yyy', FALSE);
}
public function testProfileAccess() {
// The average user should not be able to do anything to their own account.
$this->drupalLogin($this->user1);
$this->drupalGet('/user/' . $this->user1->id());
$this->assertResponse(403);
$this->drupalGet('/user/' . $this->user1->id() . '/edit');
$this->assertResponse(403);
$this->drupalGet('/user/' . $this->user1->id() . '/cancel');
$this->assertResponse(403);
$this->drupalLogin($this->user2);
$this->drupalGet('user/' . $this->user3->id() . '/edit');
$edit['edit-field-show-profile-value'] = 1;
$this->drupalPostForm("user/" . $this->user3->id() . "/edit", $edit, t('Save'));
$this->drupalGet('user/' . $this->user4->id() . '/edit');
$edit['edit-field-show-profile-value'] = 0;
$this->drupalPostForm("user/" . $this->user4->id() . "/edit", $edit, t('Save'));
// Any user should be able to view an account with SHOW PROFILE true.
$this->drupalLogin($this->user1);
$this->drupalGet('/user/' . $this->user3->id());
$this->assertResponse(200);
// But not if SHOW PROFILE is false.
$this->drupalGet('/user/' . $this->user4->id());
$this->assertResponse(403);
}
}
The tests all pass, which is good.