The test records of a checklist's recipe (recipe.testData): what each test account (recipe.accounts, TestAccounts) must find in its perimeter and must not find outside it, for every « Open as … » check to have something to look at -- an AT of a subcontractor of the North group for the account limited to it, and one of the South-East group it must not see.
class MMO\admin\helpers\TestData
Espace de noms
MMO\admin\helpers
"testData": {
"prefix": "TEST CLAUDE", // what every record's label starts with (the default)
"by": "admin", // the profile whose account writes them: its rights, the application's rules
"records": {
"employeeNorth": {"collection": "salaries", "label": "TEST CLAUDE Salarié Nord", "fields": {"nom": "TEST CLAUDE", "prenom": "Salarié Nord"}},
"contractNorth": {"collection": "contrats", "label": "TEST CLAUDE Contrat Nord", "fields": {"salarie": "@employeeNorth",
"entreprise": {"$find": "groupes", "where": {"label": "North"}, "path": "entreprises/0"}, "type": "CDI", "debut": {"$date": "2024-01-01"}}},
"atNorth": {"collection": "accidentTravails", "label": "TEST CLAUDE AT Nord", "status": "draft", "fields": {"contrat": "@contractNorth", "date": {"$date": "-10 days"}},
"calls": [{"method": "addCommentaire", "args": ["$by", "TEST CLAUDE comment"]}]},
"certificateNorth": {"collection": "files", "label": "TEST CLAUDE certificat Nord.pdf", "file": {}, "labels": ["\"#certificat\""], "fields": {"attachment": "@atNorth"}}
},
"expect": [
{"as": "limited", "match": "/sousTraitants/", "sees": ["astNorth"], "hides": ["astSouthEast"]},
{"as": "limited", "sees": ["atNorth"], "hides": ["atSouthEast"]}
]
}
- a record is made through the application's entities, as the account `by` names (\MMO\oauth\user() while it is
committed): the application's rules apply to it as to a request of that account (a contract without its employee
is refused...), never a raw insert. A file (`file`: `{name?, content?}`, a small PDF by default) is made as mmo.edms'
`FileManager::uploadFile()` does ([`TestDataStore::upload`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/TestDataStore.md#testdatastore-upload)), its labels its tokens;
- a field's value: `"@key"` the record of that key (made first), `"@key/path"` a value of it, `{"$find": collection,
"where": {...}, "path": "a/0"}` a record the database has (read, never written), `{"$date": "-10 days"}` a date;
`"$by"` (in `calls`) the account writing; `"@@x"` is the text `@x`;
- `calls`: the entity's `add…()` methods to call before it is saved (`addCommentaire`), their arguments as the fields';
- `status`: the status it is made with (`draft`: a declaration not complete is not submitted);
- `expect`: what a check opened as a test account must and must not show, by profile (`as`), by item (`items`: refs),
or by what its text says (`match`, a regular expression on its address, title and steps) -- the first rule that
fits; `sees` and `hides` name records (their label is shown) or say it in words (`@key` in them: the record's label).
`php admin.php developer test-data` makes them ([`DeveloperShellController::route_test_data`](https://mmoframework.fr/fr/documentation/mmo.admin/php/controllers/DeveloperShellController.md#developershellcontroller-route-test-data))
in this machine's own database only, keeps what it made (by database), makes nothing twice, never changes a record it
did not make, and archives what it made (`--archive`).
$recipe = TestData::Recipe($checklist->data['recipe']['testData'], TestAccounts::Profiles($checklist->data['recipe']['accounts']), $errors);[$report, $made] = (new TestData($recipe, new TestDataStore($repository)))->create($made, true); // a dry run
Make the records the database lacks: a record this command made ($made) that is still there is not made again; one whose label a record it did not make has (not archived) is left alone (the recor…
What each item opened as a test account must show, and must not: the first rule of expect that fits it -- its profile (as), its ref (items), its text (match: its address, its title, its ste…
list<array{key: string, collection: string, label: string, state: string, id: string, error?: string}>, 1: array} what was done with each, and what is left made (only the ones that could not be archived; all of them in a dry run)
Make the records the database lacks: a record this command made ($made) that is still there is not made again; one whose label a record it did not make has (not archived) is left alone (the records naming it with it) -- nothing is ever written in a record this command did not make. It stops at the first record the application refuses.
list<array{key: string, collection: string, label: string, state: string, id?: string, error?: string}>, 1: array} what was done with each record (exists, created, would create, skipped, error), and what it made now
What each item opened as a test account must show, and must not: the first rule of expect that fits it -- its profile (as), its ref (items), its text (match: its address, its title, its steps) --, the records' labels in place of their keys.
static function Expectations(array $recipe, array $items): array
string, by: ?string, records: array<string, array{collection: string, label: string, fields: array, status: ?string, file: ?array{name: string, content: ?string}, labels: list<string>, calls: list<array{method: string, args: list<mixed>}>, by: ?string}>, order: list<string>, expect: list<array{as: ?string, items: list<string>, match: ?string, sees: list<string>, hides: list<string>}>} the valid records -- by their writer's username --, in the order they are made (a record after the ones it names): a record whose label does not start with the prefix, of no collection, naming a record that is not, or written by no test account, is left out (and the ones naming it)
TestData::Recipe(['records' => ['x' => ['collection' => 'salaries', 'label' => 'Bob']]], [], $errors); // records: [], $errors: ['x: its label [Bob] does not start with [TEST CLAUDE].']
References($record)
staticTestData.php:174static function References(array $record): array