DSP Project first push, date: 29/01/2026
This commit is contained in:
38
tests/Helpers/JupyterHelpersTest.php
Normal file
38
tests/Helpers/JupyterHelpersTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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'));
|
||||
}
|
||||
}
|
||||
22
tests/bootstrap.php
Normal file
22
tests/bootstrap.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// tests/bootstrap.php
|
||||
// Minimal bootstrap for PHPUnit runs.
|
||||
|
||||
define('DSP_TEST_ROOT', dirname(__DIR__));
|
||||
|
||||
// Ensure Composer autoloader is available when dependencies are installed.
|
||||
$composerAutoload = DSP_TEST_ROOT . '/vendor/autoload.php';
|
||||
if (file_exists($composerAutoload)) {
|
||||
require_once $composerAutoload;
|
||||
}
|
||||
|
||||
// Fall back to a simple autoloader for project classes when running without Composer.
|
||||
spl_autoload_register(static function (string $class): void {
|
||||
$classPath = DSP_TEST_ROOT . '/classes/' . $class . '.php';
|
||||
if (is_file($classPath)) {
|
||||
require_once $classPath;
|
||||
}
|
||||
});
|
||||
|
||||
// Load helper functions that rely on global scope.
|
||||
require_once DSP_TEST_ROOT . '/includes/jupyter_helpers.php';
|
||||
Reference in New Issue
Block a user