You are here

public function ControllerTest::setUp in MongoDB 8.2

Configure settings and create users with specific permissions.

Overrides BrowserTestBase::setUp

See also

\Drupal\Tests\mongodb_watchdog\Functional\ControllerTest::writeSettings()

File

modules/mongodb_watchdog/tests/src/Functional/ControllerTest.php, line 139

Class

ControllerTest
Test the MongoDB report controllers.

Namespace

Drupal\Tests\mongodb_watchdog\Functional

Code

public function setUp() : void {

  // $_ENV if it comes from phpunit.xml <env>
  // $_SERVER if it comes from the phpunit command line environment.
  $this->uri = $_ENV['MONGODB_URI'] ?? $_SERVER['MONGODB_URI'] ?? static::DEFAULT_URI;

  // This line customizes the parent site; ::writeSettings the child site.
  $this->settings = new Settings([
    MongoDb::MODULE => $this
      ->getSettingsArray(),
  ]);
  parent::setUp();

  // Create users.
  $this->adminUser = $this
    ->drupalCreateUser([], 'test_admin', TRUE);
  $this->bigUser = $this
    ->drupalCreateUser([
    'administer site configuration',
    'access administration pages',
    'access site reports',
    'administer users',
  ], 'test_honcho');
  $this->anyUser = $this
    ->drupalCreateUser([
    'access content',
  ], 'test_lambda');
  $this->requestTime = $this->container
    ->get('datetime.time')
    ->getCurrentTime();
  try {
    $this->collection = $this->container
      ->get(MongoDb::SERVICE_DB_FACTORY)
      ->get(Logger::DB_LOGGER)
      ->selectCollection(Logger::TEMPLATE_COLLECTION);
  } catch (\Exception $e) {
    $this->collection = NULL;
  }
  $this
    ->assertNotNull($this->collection, (string) $this
    ->t('Access MongoDB watchdog collection'));
}