Skip to content

Commit

Permalink
MDL-75788 testing: Handle new lines in menu profile field generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou authored and lameze committed Dec 2, 2022
1 parent 1d863c3 commit 3923ef9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/testing/generator/data_generator.php
Expand Up @@ -1324,6 +1324,11 @@ public function create_custom_profile_field(array $data): \stdClass {
[$data['categoryid']]) + 1;
}

if ($data['datatype'] === 'menu' && isset($data['param1'])) {
// Convert new lines to the proper character.
$data['param1'] = str_replace('\n', "\n", $data['param1']);
}

// Defaults for other values.
$defaults = [
'description' => '',
Expand Down
7 changes: 7 additions & 0 deletions lib/testing/tests/testing_generator_test.php
Expand Up @@ -577,5 +577,12 @@ public function test_create_custom_profile_field() {
$field7 = $generator->create_custom_profile_field(
['datatype' => 'checkbox', 'shortname' => 'areyousure', 'name' => 'Are you sure?']);
$this->assertEquals(0, $field7->defaultdata);

// Check setting options for menu using \n work as expected.
$field8 = $generator->create_custom_profile_field([
'datatype' => 'menu', 'shortname' => 'cuisine', 'name' => 'Cuisine', 'param1' => 'French\nChinese\nLebanese',
'defaultdata' => 'Chinese'
]);
$this->assertEquals("French\nChinese\nLebanese", $field8->param1);
}
}
24 changes: 24 additions & 0 deletions user/tests/behat/custom_profile_fields.feature
Expand Up @@ -279,3 +279,27 @@ Feature: Custom profile fields should be visible and editable by those with the
| everyonevisible_field | everyonevisible_field_information |
| uservisible_field | uservisible_field_information |
| teachervisible_field | teachervisible_field_information |

@javascript
Scenario: Menu profile field's default data works as expected when editing user profile
Given the following "custom profile fields" exist:
| datatype | shortname | name | visible | param1 | defaultdata |
| menu | menufield | Menu field | 2 | OptA\nOptB\nOptC | OptB |
And I log in as "userwithinformation"
When I follow "Profile" in the user menu
And I click on "Edit profile" "link" in the "region-main" "region"
Then the following fields match these values:
| Menu field | OptB |

@javascript
Scenario: Menu profile field successfully updated when editing user profile
Given the following "custom profile fields" exist:
| datatype | shortname | name | visible | param1 |
| menu | menufield | Menu field | 2 | OptA\nOptB\nOptC |
And I log in as "userwithinformation"
When I follow "Profile" in the user menu
And I click on "Edit profile" "link" in the "region-main" "region"
And I set the following fields to these values:
| Menu field | OptC |
And I click on "Update profile" "button"
Then I should see "OptC"

0 comments on commit 3923ef9

Please sign in to comment.