39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class JupyterHelpersTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
putenv('JUPYTERHUB_USERNAME_TEMPLATE');
|
|
}
|
|
|
|
public function testResolveJupyterHubUsernameWithDefaultTemplate(): void
|
|
{
|
|
$username = dsp_resolve_jupyterhub_username(42, 'alice', 'alice@example.com');
|
|
$this->assertSame('user_42', $username);
|
|
}
|
|
|
|
public function testResolveJupyterHubUsernameUsesCustomTemplate(): void
|
|
{
|
|
putenv('JUPYTERHUB_USERNAME_TEMPLATE=hub-{username}-{person_id}');
|
|
$username = dsp_resolve_jupyterhub_username(7, 'bob', 'bob@example.com');
|
|
$this->assertSame('hub-bob-7', $username);
|
|
}
|
|
|
|
public function testResolveJupyterHubUsernameSanitisesOutput(): void
|
|
{
|
|
putenv('JUPYTERHUB_USERNAME_TEMPLATE={email}');
|
|
$username = dsp_resolve_jupyterhub_username(99, 'carol', 'carol+demo@example.com');
|
|
$this->assertSame('carol-demo-example.com', $username);
|
|
}
|
|
|
|
public function testResolveJupyterHubUsernameRejectsMissingPersonId(): void
|
|
{
|
|
$this->assertNull(dsp_resolve_jupyterhub_username(null, 'dave', 'dave@example.com'));
|
|
}
|
|
}
|