Skip to content

Commit 0238c21

Browse files
committed
iss1171 - UPdate Behat to check freeform metadata
1 parent 611313c commit 0238c21

5 files changed

Lines changed: 98 additions & 8 deletions

File tree

.github/workflows/moodle-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ jobs:
268268
if: ${{matrix.moodle-branch == 'MOODLE_502_STABLE'}}
269269
run: |
270270
cd plugin/tests/jest
271-
npm ci
271+
npm install
272272
npm test
273273
274274
- name: Behat features

doc/content/metadata.png

58.7 KB
Loading

doc/en/Authoring/Metadata.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ New questions will be created with editable `metadata` similar to the following:
1717
],
1818
"license": "unknown", // $CFG->sitedefaultlicense
1919
"isPartOf": "",
20-
"additional": {}
20+
"additional": {},
21+
"freeform" {}
2122
}
2223
```
23-
A question has one creator but can have multiple contributors.
24+
A question has one creator but can have multiple contributors. `Last name` is required.
2425

2526
Additional metadata is stored in Scope->Property->Qualifier->Value or Scope->Property->Value format. Scope identifies the metadata scheme being used. For instance, two institutions might have the property `Level` that has different meanings. Scope allows differentiation between the two:
2627
```
@@ -77,13 +78,15 @@ If any entry for a property has a qualifier, then all entries must do so in orde
7778
}
7879
}
7980
```
80-
All information in the `metadata` field can be updated via the button 'View and edit full metadata' in the question edit form. This launches a pop-up where the metadata information can be updated via input boxes or the JSON can be manually amended and validated.
81+
The freeform metadata input allows entry of further metadata in whatever format the user requires. It simply has to be valid JSON. This can also be added in the main JSON metadata input field but (unlike `additional` entries) does not create additional input fields and buttons. This field is for power users who require greater nesting depth in their metadata.
82+
83+
All information in the question `metadata` field can be updated via the button 'View and edit full metadata' in the question edit form. This launches a pop-up where the metadata information can be updated via input boxes or the JSON can be manually amended and validated.
8184

8285
![Metadata popup in action](../../content/metadata.png)
8386

8487
Update the input boxes and click 'Validate inputs and update JSON' to display the JSON output. Update the JSON and click 'Update inputs from JSON' to fill in the input boxes from the JSON. 'Validate and close' will take the contents of the input boxes, validate them and then create and store JSON ready to be saved as part of the STACK question. The question edit form must still be saved normally once the pop-up has closed in order to save this JSON to the question.
8588

86-
Please note that although you can update either the JSON or the input boxes, the form saves the contents of the input boxes. If you update the JSON you must click 'Update inputs from JSON' without a JSON error being displayed before clicking 'Validate and close'.
89+
Please note that although you can update either the JSON or the input boxes, the form saves the contents of the input boxes. If you update the JSON you must click 'Update inputs from JSON' without a JSON error being displayed before clicking 'Validate and close'.
8790

8891
Example metadata:
8992
```
@@ -135,7 +138,8 @@ Example metadata:
135138
"Workbook": "10",
136139
"Level": "Basic"
137140
}
138-
}
141+
},
142+
"freeform": {}
139143
}
140144
```
141145
Both metadata fields are exported and imported normally as part of Moodle XML, allowing automated addition of metadata to large question banks with the aid of Gitsync.
@@ -144,6 +148,6 @@ Both metadata fields are exported and imported normally as part of Moodle XML, a
144148
{"id": XXXX-XXX-XXXX_XXXX}
145149
</prescribedmetadata>
146150
<metadata>
147-
{"creator":{"firstName":"Dave","lastName":"Summers","institution":"Edinburgh","year":"2025"},"contributor":[{"firstName":"Bob","lastName":"Smith","institution":"Open University","year":"2026"}],"language":["en"],"isPartOf":"HELM","license":"cc-4.0","additional":{"UoE":{"Course":{"Name":"Introductory Maths","Week":"3"},"Topic":"Calculus"}}}
151+
{"creator":{"firstName":"Dave","lastName":"Summers","institution":"Edinburgh","year":"2025"},"contributor":[{"firstName":"Bob","lastName":"Smith","institution":"Open University","year":"2026"}],"language":["en"],"isPartOf":"HELM","license":"cc-4.0","additional":{"UoE":{"Course":{"Name":"Introductory Maths","Week":"3"},"Topic":"Calculus"}},"freeform":{}}
148152
</metadata>
149153
```

doc/en/Developer/Unit_tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,6 @@ In the STACK directory
194194

195195
In the tests/jest directory as a user with write permissions:
196196
```
197-
npm ci
197+
npm install
198198
npm test
199199
```

tests/behat/metadata.feature

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,92 @@ Feature: Create and edit STACK metadata
261261
Then I should see "v2 (latest)"
262262
And I check the hidden input "metadata" is '{"creator":{"firstName":"Bob","lastName":"Smith","institution":"MIT","year":"2024"},"contributor":[{"firstName":"Mike","lastName":"Jones","institution":"Bath","year":"2023"}],"language":["en"],"isPartOf":"Everything","license":"cc-nc-4.1","additional":{"Added":{"Cat":{"Breed":"Al$%&^"},"Horse":["Dobbin","Champion"],"Dog":{"Teeth":"50","Tails":"1"}},"Added too":{"Fish":{"Gills":["2","3"]}}},"freeform":{}}'
263263

264+
@javascript @current
265+
Scenario: Create and edit STACK freeform metadata
266+
When I am on the "Algebraic input" "core_question > edit" page logged in as teacher
267+
And I click on "View and edit full metadata" "button"
268+
And I should see "STACK metadata is stored as a JSON object."
269+
And I set the field "id_metadata_json" to multiline:
270+
"""
271+
{
272+
"creator": {
273+
"firstName": "Bob",
274+
"lastName": "Smith",
275+
"institution": "MIT",
276+
"year": "2024"
277+
},
278+
"contributor": [
279+
{
280+
"firstName": "Mike",
281+
"lastName": "Jones",
282+
"institution": "Bath",
283+
"year": "2023"
284+
}
285+
],
286+
"language": [
287+
"en"
288+
],
289+
"isPartOf": "Everything",
290+
"license": "cc-nc-4.1",
291+
"additional":
292+
{
293+
"additional": {
294+
"Cat": {
295+
"Breed": "Al$%&^"
296+
},
297+
"Horse": "Dobbin",
298+
"Dog": {
299+
"Teeth": "50",
300+
"Tails": "1"
301+
},
302+
"Multi": [
303+
1,2,3
304+
],
305+
"Multi1": {
306+
"Multi2": [
307+
4,5,6
308+
]
309+
}
310+
},
311+
"Added too": {
312+
"Fish": {
313+
"Gills": "2"
314+
}
315+
}
316+
},
317+
"freeform":
318+
{
319+
"license": {
320+
"Cat": {
321+
"Breed": "Al$%&^"
322+
},
323+
"Horse": "Dobbin",
324+
"Dog": {
325+
"Teeth": "50",
326+
"Tails": "1"
327+
}
328+
},
329+
"Freeform too": {
330+
"Fish": {
331+
"Gills": "2"
332+
}
333+
}
334+
}
335+
}
336+
"""
337+
And I click on "Update inputs from JSON" "button"
338+
And I should see "{\"license\":{\"Cat\":{\"Breed\":\"Al$%&^\"},\"Horse\":\"Dobbin\",\"Dog\":{\"Teeth\":\"50\",\"Tails\":\"1\"}},\"Freeform too\":{\"Fish\":{\"Gills\":\"2\"}}}"
339+
And I click on "Validate and close" "button"
340+
And I check the hidden input "metadata" is '{"creator":{"firstName":"Bob","lastName":"Smith","institution":"MIT","year":"2024"},"contributor":[{"firstName":"Mike","lastName":"Jones","institution":"Bath","year":"2023"}],"language":["en"],"isPartOf":"Everything","license":"cc-nc-4.1","additional":{"additional":{"Cat":{"Breed":"Al$%&^"},"Horse":"Dobbin","Dog":{"Teeth":"50","Tails":"1"},"Multi":["1","2","3"],"Multi1":{"Multi2":["4","5","6"]}},"Added too":{"Fish":{"Gills":"2"}}},"freeform":{"license":{"Cat":{"Breed":"Al$%&^"},"Horse":"Dobbin","Dog":{"Teeth":"50","Tails":"1"}},"Freeform too":{"Fish":{"Gills":"2"}}}}'
341+
And I click on "View and edit full metadata" "button"
342+
And I should see "STACK metadata is stored as a JSON object."
343+
And I set the field "smdi_0_freeform_value" to multiline:
344+
"""
345+
{"x":[{"additional":"b"},{"license":"d"}]}
346+
"""
347+
And I click on "Validate and close" "button"
348+
And I check the hidden input "metadata" is '{"creator":{"firstName":"Bob","lastName":"Smith","institution":"MIT","year":"2024"},"contributor":[{"firstName":"Mike","lastName":"Jones","institution":"Bath","year":"2023"}],"language":["en"],"isPartOf":"Everything","license":"cc-nc-4.1","additional":{"additional":{"Cat":{"Breed":"Al$%&^"},"Horse":"Dobbin","Dog":{"Teeth":"50","Tails":"1"},"Multi":["1","2","3"],"Multi1":{"Multi2":["4","5","6"]}},"Added too":{"Fish":{"Gills":"2"}}},"freeform":{"x":[{"additional":"b"},{"license":"d"}]}}'
349+
264350
@javascript
265351
Scenario: New question metadata
266352
When I am on the "Course 1" "core_question > course question bank" page logged in as "teacher"

0 commit comments

Comments
 (0)