MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

TestAccounts

MMO\admin\helpers · 1 symbole · générée le 27 Oct 2026

class

TestAccounts

TestAccounts.php:26

The test accounts of a checklist's recipe (recipe.accounts): as whom a check is done, and the account of this machine's database that fills the condition -- « an account limited to a group », « a consultant ».

class MMO\admin\helpers\TestAccounts
Espace de noms
MMO\admin\helpers
"accounts": { "limited": {"username": "test.groupe.nord", "label": "Account limited to a group (North)", "match": "/\\bcompte limité\\b|limited to a group/iu", "roles": ["dev-user"], "groups": ["North"], "description": "sees the establishments of the North group only"} } - a profile's key is what an item's `action.as` names ([`Checklist::NormalizeAction`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/Checklist.md#checklist-normalizeaction)), and what a ```` ```check ```` line's `as=<key>` column gives; - `match` is a regular expression: a check whose text it matches is done as this account ([`Find`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/TestAccounts.md#testaccounts-find): the earliest); - `username` is always a test account: it starts with `test.` ([`USERNAME`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/TestAccounts.md#testaccounts-username)) -- never an operator's nor a real one; `"self": true` instead is the account logged in (`connecté en god`): recognized, nothing to switch to; - `roles` and `groups` (labels) are what `php admin.php developer test-accounts` gives the account it makes ([`DeveloperShellController::route_test_accounts`](https://mmoframework.fr/fr/documentation/mmo.admin/php/controllers/DeveloperShellController.md#developershellcontroller-route-test-accounts)): in this machine's own database only ([`DatabaseRefusal`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/TestAccounts.md#testaccounts-databaserefusal)), never changing an account it did not make.
TestAccounts::Find(TestAccounts::Profiles(['limited' => ['username' => 'test.nord', 'match' => '/compte limité/u']]), 'en compte limité, ...'); // 'limited'

Index

KEYa profile's key
MENTIONA text that says as whom a check is done -- but no profile may know it: connecté en compte limité, avec un compte sans admin, en administrateur, as an account limited to a group, `logged in…
USERNAMEwhat a test account's username is: test. and a name
DatabaseRefusal($mode, $uri, $database, $config) staticWhy test accounts may not be made in a database: only on a development instance, in a database of this machine, the one configs/config.json declares -- never a copy of a client's (local.json po…
Find($profiles, $text) static
IsLocalUri($uri) static
Mentions($text) static
Profiles($accounts, $errors) static
SiteRelative($url, $bases) staticAn address a page opens, made relative to the site: an absolute one of another site, a scheme (javascript:), a protocol-relative one, a backslash or a .. are refused -- never a redirection else…

Constantes3

KEY

a profile's key

const KEY = '/^[A-Za-z][\\w.-]{0,63}$/'

MENTION

A text that says as whom a check is done -- but no profile may know it: connecté en compte limité, avec un compte sans admin, en administrateur, as an account limited to a group, logged in as a consultant.

const MENTION = '/\\b(?:comptes?|accounts?)\\s+(?:limité|restreint|sans\\b|non\\b|non-|consultant|admin|d[\'’]un(?:e)?\\s+autre|hors\\b|qui\\b|«|"|user\\b|éditeur|valideur|assistante|de test|limited|without|with no|outside|read-only|of another)|\\ben (?:tant que|administrateur\\b)|\\bun administrateur\\b|\\bpar un admin\\b|\\bconnecté (?:en|avec|comme)\\b|\\bas (?:an? )?(?:admin|administrator|consultant|user|editor)\\b|\\blogged in (?:as|with)\\b/iu'

USERNAME

what a test account's username is: test. and a name

const USERNAME = '/^test\\.[\\w.@+-]{1,100}$/u'

Méthodes6

DatabaseRefusal($mode, $uri, $database, $config)

staticTestAccounts.php:106

Why test accounts may not be made in a database: only on a development instance, in a database of this machine, the one configs/config.json declares -- never a copy of a client's (local.json pointing elsewhere).

static function DatabaseRefusal(string $mode, ?string $uri, ?string $database, string $config): ?string
$modestringthe instance's (MMO_MODE)
$urinull | stringthe database server's address (mongodb://127.0.0.1/), never shown: it may hold a password
$databasenull | stringthe database's name
$configstringconfigs/config.json, as it is written
retournenull | stringthe refusal, null when it may
TestAccounts::DatabaseRefusal('dev', 'mongodb://127.0.0.1/', 'acme', '{"repository": {"database": "demo"}}'); // 'the database [acme] is not configs/config.json's ...'

Find($profiles, $text)

staticTestAccounts.php:81
static function Find(array $profiles, string $text): ?string
$profilesarray
$textstringa check's text
retournenull | stringthe key of the profile whose match is found first in $text (the first declared on a tie); null for none
TestAccounts::Find($profiles, 'en compte non administrateur, 403 ; en administrateur, la liste'); // 'nonAdmin', not 'admin'

IsLocalUri($uri)

staticTestAccounts.php:127
static function IsLocalUri(string $uri): bool
$uristring
retourneboolwhether every host of a database's address is this machine
TestAccounts::IsLocalUri('mongodb://user:secret@127.0.0.1:27017/'); // true

Profiles($accounts, $errors)

staticTestAccounts.php:49
static function Profiles(mixed $accounts, ?array &$errors = null): array
$accountsmixeda recipe's accounts
$errors = nullnull | arraywhat was refused, and why
retournearrayarray{username: string, label: string, match: ?string, roles: list<string>, groups: list<string>, description: string, self: bool}> the valid profiles, by key: a username that is not a test account's, or a match that is no regular expression, leaves the profile out; a self one (the account logged in) has no username
TestAccounts::Profiles(['admin' => ['username' => 'god']], $errors); // [], $errors: ['admin: [god] is not a test account (test.…).']

SiteRelative($url, $bases)

staticTestAccounts.php:146

An address a page opens, made relative to the site: an absolute one of another site, a scheme (javascript:), a protocol-relative one, a backslash or a .. are refused -- never a redirection elsewhere.

static function SiteRelative(string $url, array $bases): ?string
$urlstringas an item gives it: relative to the site, or absolute
$basesarraythe site's own absolute addresses (the recipe's site, the application's url)
retournenull | stringthe address relative to the site (gestion/accidents?id=1), null when it is not one of the site's
TestAccounts::SiteRelative('http://localhost/acme/gestion?x=1', ['http://localhost/acme/']); // 'gestion?x=1'TestAccounts::SiteRelative('https://evil.example/acme/', ['http://localhost/acme/']); // null