| Línea 192... |
Línea 192... |
| 192 |
|
192 |
|
| Línea 193... |
Línea 193... |
| 193 |
$generator = self::getDataGenerator();
|
193 |
$generator = self::getDataGenerator();
|
| 194 |
|
194 |
|
| - |
|
195 |
// Create complex user profile field supporting multi-lang.
|
| - |
|
196 |
filter_set_global_state('multilang', TEXTFILTER_ON);
|
| 195 |
// Create complex user profile field supporting multi-lang.
|
197 |
filter_set_applies_to_strings('multilang', true);
|
| 196 |
filter_set_global_state('multilang', TEXTFILTER_ON);
|
198 |
|
| 197 |
$name = '<span lang="en" class="multilang">Employment status</span>'.
|
199 |
$name = '<span lang="en" class="multilang">Employment status</span>'.
|
| 198 |
'<span lang="es" class="multilang">Estado de Empleo</span>';
|
200 |
'<span lang="es" class="multilang">Estado de Empleo</span>';
|
| 199 |
$statuses = 'UE\nSE\n<span lang="en" class="multilang">Other</span><span lang="es" class="multilang">Otro</span>';
|
201 |
$statuses = 'UE\nSE\n<span lang="en" class="multilang">Other</span><span lang="es" class="multilang">Otro</span>';
|
| Línea 358... |
Línea 360... |
| 358 |
|
360 |
|
| Línea 359... |
Línea 361... |
| 359 |
$generator = self::getDataGenerator();
|
361 |
$generator = self::getDataGenerator();
|
| 360 |
|
362 |
|
| - |
|
363 |
// Create complex user profile field supporting multi-lang.
|
| - |
|
364 |
filter_set_global_state('multilang', TEXTFILTER_ON);
|
| 361 |
// Create complex user profile field supporting multi-lang.
|
365 |
filter_set_applies_to_strings('multilang', true);
|
| 362 |
filter_set_global_state('multilang', TEXTFILTER_ON);
|
366 |
|
| 363 |
$name = '<span lang="en" class="multilang">Employment status</span>' .
|
367 |
$name = '<span lang="en" class="multilang">Employment status</span>' .
|
| 364 |
'<span lang="es" class="multilang">Estado de Empleo</span>';
|
368 |
'<span lang="es" class="multilang">Estado de Empleo</span>';
|
| 365 |
$statuses = 'UE\nSE\n<span lang="en" class="multilang">Other</span><span lang="es" class="multilang">Otro</span>';
|
369 |
$statuses = 'UE\nSE\n<span lang="en" class="multilang">Other</span><span lang="es" class="multilang">Otro</span>';
|
| Línea 493... |
Línea 497... |
| 493 |
public function test_create_users(): void {
|
497 |
public function test_create_users(): void {
|
| 494 |
global $DB;
|
498 |
global $DB;
|
| Línea 495... |
Línea 499... |
| 495 |
|
499 |
|
| Línea 496... |
Línea 500... |
| 496 |
$this->resetAfterTest(true);
|
500 |
$this->resetAfterTest(true);
|
| 497 |
|
501 |
|
| 498 |
$user1 = array(
|
502 |
$user1 = [
|
| 499 |
'username' => 'usernametest1',
|
503 |
'username' => 'usernametest1',
|
| 500 |
'password' => 'Moodle2012!',
|
504 |
'password' => 'Moodle2012!',
|
| 501 |
'idnumber' => 'idnumbertest1',
|
505 |
'idnumber' => 'idnumbertest1',
|
| Línea 507... |
Línea 511... |
| 507 |
'alternatename' => 'Alternate Name User Test 1',
|
511 |
'alternatename' => 'Alternate Name User Test 1',
|
| 508 |
'email' => 'usertest1@example.com',
|
512 |
'email' => 'usertest1@example.com',
|
| 509 |
'description' => 'This is a description for user 1',
|
513 |
'description' => 'This is a description for user 1',
|
| 510 |
'city' => 'Perth',
|
514 |
'city' => 'Perth',
|
| 511 |
'country' => 'AU',
|
515 |
'country' => 'AU',
|
| 512 |
'preferences' => [[
|
516 |
'preferences' => [
|
| - |
|
517 |
[
|
| 513 |
'type' => 'htmleditor',
|
518 |
'type' => 'htmleditor',
|
| 514 |
'value' => 'atto'
|
519 |
'value' => 'tiny',
|
| 515 |
], [
|
520 |
],
|
| - |
|
521 |
[
|
| 516 |
'type' => 'invalidpreference',
|
522 |
'type' => 'invalidpreference',
|
| 517 |
'value' => 'abcd'
|
523 |
'value' => 'abcd',
|
| 518 |
]
|
524 |
],
|
| 519 |
],
|
525 |
],
|
| 520 |
'department' => 'College of Science',
|
526 |
'department' => 'College of Science',
|
| 521 |
'institution' => 'National Institute of Physics',
|
527 |
'institution' => 'National Institute of Physics',
|
| 522 |
'phone1' => '01 2345 6789',
|
528 |
'phone1' => '01 2345 6789',
|
| 523 |
'maildisplay' => 1,
|
529 |
'maildisplay' => 1,
|
| 524 |
'interests' => 'badminton, basketball, cooking, '
|
530 |
'interests' => 'badminton, basketball, cooking, ',
|
| 525 |
);
|
531 |
];
|
| Línea 526... |
Línea 532... |
| 526 |
|
532 |
|
| 527 |
// User with an authentication method done externally.
|
533 |
// User with an authentication method done externally.
|
| 528 |
$user2 = array(
|
534 |
$user2 = array(
|
| 529 |
'username' => 'usernametest2',
|
535 |
'username' => 'usernametest2',
|
| Línea 549... |
Línea 555... |
| 549 |
foreach($createdusers as $createduser) {
|
555 |
foreach($createdusers as $createduser) {
|
| 550 |
$dbuser = $DB->get_record('user', array('id' => $createduser['id']));
|
556 |
$dbuser = $DB->get_record('user', array('id' => $createduser['id']));
|
| Línea 551... |
Línea 557... |
| 551 |
|
557 |
|
| 552 |
if ($createduser['username'] === $user1['username']) {
|
558 |
if ($createduser['username'] === $user1['username']) {
|
| 553 |
$usertotest = $user1;
|
559 |
$usertotest = $user1;
|
| 554 |
$this->assertEquals('atto', get_user_preferences('htmleditor', null, $dbuser));
|
560 |
$this->assertEquals('tiny', get_user_preferences('htmleditor', null, $dbuser));
|
| 555 |
$this->assertEquals(null, get_user_preferences('invalidpreference', null, $dbuser));
|
561 |
$this->assertEquals(null, get_user_preferences('invalidpreference', null, $dbuser));
|
| 556 |
// Confirm user interests have been saved.
|
562 |
// Confirm user interests have been saved.
|
| 557 |
$interests = \core_tag_tag::get_item_tags_array('core', 'user', $createduser['id'],
|
563 |
$interests = \core_tag_tag::get_item_tags_array('core', 'user', $createduser['id'],
|
| 558 |
\core_tag_tag::BOTH_STANDARD_AND_NOT, 0, false);
|
564 |
\core_tag_tag::BOTH_STANDARD_AND_NOT, 0, false);
|
| Línea 606... |
Línea 612... |
| 606 |
}
|
612 |
}
|
| Línea 607... |
Línea 613... |
| 607 |
|
613 |
|
| 608 |
/**
|
614 |
/**
|
| 609 |
* Data provider for \core_user_externallib_testcase::test_create_users_with_same_emails().
|
615 |
* Data provider for \core_user_externallib_testcase::test_create_users_with_same_emails().
|
| 610 |
*/
|
616 |
*/
|
| 611 |
public function create_users_provider_with_same_emails() {
|
617 |
public static function create_users_provider_with_same_emails(): array {
|
| 612 |
return [
|
618 |
return [
|
| 613 |
'Same emails allowed, same case' => [
|
619 |
'Same emails allowed, same case' => [
|
| 614 |
1, false
|
620 |
1, false
|
| 615 |
],
|
621 |
],
|
| Línea 692... |
Línea 698... |
| 692 |
/**
|
698 |
/**
|
| 693 |
* Data provider for {@see self::test_create_users_invalid_parameter()}.
|
699 |
* Data provider for {@see self::test_create_users_invalid_parameter()}.
|
| 694 |
*
|
700 |
*
|
| 695 |
* @return array
|
701 |
* @return array
|
| 696 |
*/
|
702 |
*/
|
| 697 |
public function data_create_users_invalid_parameter() {
|
703 |
public static function data_create_users_invalid_parameter(): array {
|
| 698 |
return [
|
704 |
return [
|
| 699 |
'blank_username' => [
|
705 |
'blank_username' => [
|
| 700 |
'data' => [
|
706 |
'data' => [
|
| 701 |
'username' => '',
|
707 |
'username' => '',
|
| 702 |
'firstname' => 'Foo',
|
708 |
'firstname' => 'Foo',
|
| Línea 804... |
Línea 810... |
| 804 |
|
810 |
|
| Línea 805... |
Línea 811... |
| 805 |
$draftid = $draftfile['itemid'];
|
811 |
$draftid = $draftfile['itemid'];
|
| Línea 806... |
Línea 812... |
| 806 |
|
812 |
|
| 807 |
$user1 = self::getDataGenerator()->create_user();
|
813 |
$user1 = self::getDataGenerator()->create_user();
|
| 808 |
|
814 |
|
| 809 |
$user1 = array(
|
815 |
$user1 = [
|
| 810 |
'id' => $user1->id,
|
816 |
'id' => $user1->id,
|
| 811 |
'username' => 'usernametest1',
|
817 |
'username' => 'usernametest1',
|
| Línea 820... |
Línea 826... |
| 820 |
'email' => 'usertest1@example.com',
|
826 |
'email' => 'usertest1@example.com',
|
| 821 |
'description' => 'This is a description for user 1',
|
827 |
'description' => 'This is a description for user 1',
|
| 822 |
'city' => 'Perth',
|
828 |
'city' => 'Perth',
|
| 823 |
'userpicture' => $draftid,
|
829 |
'userpicture' => $draftid,
|
| 824 |
'country' => 'AU',
|
830 |
'country' => 'AU',
|
| 825 |
'preferences' => [[
|
831 |
'preferences' => [
|
| - |
|
832 |
[
|
| 826 |
'type' => 'htmleditor',
|
833 |
'type' => 'htmleditor',
|
| 827 |
'value' => 'atto'
|
834 |
'value' => 'textarea',
|
| 828 |
], [
|
835 |
],
|
| - |
|
836 |
[
|
| 829 |
'type' => 'invialidpreference',
|
837 |
'type' => 'invialidpreference',
|
| 830 |
'value' => 'abcd'
|
838 |
'value' => 'abcd',
|
| 831 |
]
|
839 |
],
|
| 832 |
],
|
840 |
],
|
| 833 |
'department' => 'College of Science',
|
841 |
'department' => 'College of Science',
|
| 834 |
'institution' => 'National Institute of Physics',
|
842 |
'institution' => 'National Institute of Physics',
|
| 835 |
'phone1' => '01 2345 6789',
|
843 |
'phone1' => '01 2345 6789',
|
| 836 |
'maildisplay' => 1,
|
844 |
'maildisplay' => 1,
|
| 837 |
'interests' => 'badminton, basketball, cooking, '
|
845 |
'interests' => 'badminton, basketball, cooking, ',
|
| 838 |
);
|
846 |
];
|
| Línea 839... |
Línea 847... |
| 839 |
|
847 |
|
| 840 |
$context = \context_system::instance();
|
848 |
$context = \context_system::instance();
|
| 841 |
$roleid = $this->assignUserCapability('moodle/user:update', $context->id);
|
849 |
$roleid = $this->assignUserCapability('moodle/user:update', $context->id);
|
| Línea 886... |
Línea 894... |
| 886 |
$this->assertNotEquals(0, $dbuser->picture, 'Picture must be set to the new icon itemid for this user');
|
894 |
$this->assertNotEquals(0, $dbuser->picture, 'Picture must be set to the new icon itemid for this user');
|
| 887 |
$this->assertEquals($dbuser->department, $user1['department']);
|
895 |
$this->assertEquals($dbuser->department, $user1['department']);
|
| 888 |
$this->assertEquals($dbuser->institution, $user1['institution']);
|
896 |
$this->assertEquals($dbuser->institution, $user1['institution']);
|
| 889 |
$this->assertEquals($dbuser->phone1, $user1['phone1']);
|
897 |
$this->assertEquals($dbuser->phone1, $user1['phone1']);
|
| 890 |
$this->assertEquals($dbuser->maildisplay, $user1['maildisplay']);
|
898 |
$this->assertEquals($dbuser->maildisplay, $user1['maildisplay']);
|
| 891 |
$this->assertEquals('atto', get_user_preferences('htmleditor', null, $dbuser));
|
899 |
$this->assertEquals('textarea', get_user_preferences('htmleditor', null, $dbuser));
|
| 892 |
$this->assertEquals(null, get_user_preferences('invalidpreference', null, $dbuser));
|
900 |
$this->assertEquals(null, get_user_preferences('invalidpreference', null, $dbuser));
|
| Línea 893... |
Línea 901... |
| 893 |
|
901 |
|
| 894 |
// Confirm user interests have been saved.
|
902 |
// Confirm user interests have been saved.
|
| 895 |
$interests = \core_tag_tag::get_item_tags_array('core', 'user', $user1['id'], \core_tag_tag::BOTH_STANDARD_AND_NOT, 0, false);
|
903 |
$interests = \core_tag_tag::get_item_tags_array('core', 'user', $user1['id'], \core_tag_tag::BOTH_STANDARD_AND_NOT, 0, false);
|
| Línea 951... |
Línea 959... |
| 951 |
/**
|
959 |
/**
|
| 952 |
* Data provider for testing \core_user_external::update_users() for users with same emails
|
960 |
* Data provider for testing \core_user_external::update_users() for users with same emails
|
| 953 |
*
|
961 |
*
|
| 954 |
* @return array
|
962 |
* @return array
|
| 955 |
*/
|
963 |
*/
|
| 956 |
public function users_with_same_emails() {
|
964 |
public static function users_with_same_emails(): array {
|
| 957 |
return [
|
965 |
return [
|
| 958 |
'Same emails not allowed: Update name using exactly the same email' => [
|
966 |
'Same emails not allowed: Update name using exactly the same email' => [
|
| 959 |
0, 'John', 's1@example.com', 'Johnny', 's1@example.com', false, true
|
967 |
0, 'John', 's1@example.com', 'Johnny', 's1@example.com', false, true
|
| 960 |
],
|
968 |
],
|
| 961 |
'Same emails not allowed: Update using someone else\'s email' => [
|
969 |
'Same emails not allowed: Update using someone else\'s email' => [
|
| Línea 1379... |
Línea 1387... |
| 1379 |
// Save users preferences.
|
1387 |
// Save users preferences.
|
| 1380 |
$this->setAdminUser();
|
1388 |
$this->setAdminUser();
|
| 1381 |
$preferences = array(
|
1389 |
$preferences = array(
|
| 1382 |
array(
|
1390 |
array(
|
| 1383 |
'name' => 'htmleditor',
|
1391 |
'name' => 'htmleditor',
|
| 1384 |
'value' => 'atto',
|
1392 |
'value' => 'textarea',
|
| 1385 |
'userid' => $user1->id,
|
1393 |
'userid' => $user1->id,
|
| 1386 |
),
|
1394 |
),
|
| 1387 |
array(
|
1395 |
array(
|
| 1388 |
'name' => 'htmleditor',
|
1396 |
'name' => 'htmleditor',
|
| 1389 |
'value' => 'tiny',
|
1397 |
'value' => 'tiny',
|
| Línea 1395... |
Línea 1403... |
| 1395 |
$result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
|
1403 |
$result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
|
| 1396 |
$this->assertCount(0, $result['warnings']);
|
1404 |
$this->assertCount(0, $result['warnings']);
|
| 1397 |
$this->assertCount(2, $result['saved']);
|
1405 |
$this->assertCount(2, $result['saved']);
|
| Línea 1398... |
Línea 1406... |
| 1398 |
|
1406 |
|
| 1399 |
// Get preference from DB to avoid cache.
|
1407 |
// Get preference from DB to avoid cache.
|
| 1400 |
$this->assertEquals('atto', $DB->get_field('user_preferences', 'value',
|
1408 |
$this->assertEquals('textarea', $DB->get_field('user_preferences', 'value',
|
| 1401 |
array('userid' => $user1->id, 'name' => 'htmleditor')));
|
1409 |
array('userid' => $user1->id, 'name' => 'htmleditor')));
|
| 1402 |
$this->assertEquals('tiny', $DB->get_field('user_preferences', 'value',
|
1410 |
$this->assertEquals('tiny', $DB->get_field('user_preferences', 'value',
|
| 1403 |
array('userid' => $user2->id, 'name' => 'htmleditor')));
|
1411 |
array('userid' => $user2->id, 'name' => 'htmleditor')));
|
| Línea 1519... |
Línea 1527... |
| 1519 |
// Save users preferences.
|
1527 |
// Save users preferences.
|
| 1520 |
$this->setAdminUser();
|
1528 |
$this->setAdminUser();
|
| 1521 |
$preferences = array(
|
1529 |
$preferences = array(
|
| 1522 |
array(
|
1530 |
array(
|
| 1523 |
'name' => 'htmleditor',
|
1531 |
'name' => 'htmleditor',
|
| 1524 |
'value' => 'atto',
|
1532 |
'value' => 'textarea',
|
| 1525 |
'userid' => $user->id,
|
1533 |
'userid' => $user->id,
|
| 1526 |
)
|
1534 |
)
|
| 1527 |
);
|
1535 |
);
|
| Línea 1528... |
Línea 1536... |
| 1528 |
|
1536 |
|
| 1529 |
$result = core_user_external::set_user_preferences($preferences);
|
1537 |
$result = core_user_external::set_user_preferences($preferences);
|
| 1530 |
$result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
|
1538 |
$result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
|
| 1531 |
$this->assertCount(0, $result['warnings']);
|
1539 |
$this->assertCount(0, $result['warnings']);
|
| Línea 1532... |
Línea 1540... |
| 1532 |
$this->assertCount(1, $result['saved']);
|
1540 |
$this->assertCount(1, $result['saved']);
|
| 1533 |
|
1541 |
|
| 1534 |
// Get preference from DB to avoid cache.
|
1542 |
// Get preference from DB to avoid cache.
|
| Línea 1535... |
Línea 1543... |
| 1535 |
$this->assertEquals('atto', $DB->get_field('user_preferences', 'value',
|
1543 |
$this->assertEquals('textarea', $DB->get_field('user_preferences', 'value',
|
| 1536 |
array('userid' => $user->id, 'name' => 'htmleditor')));
|
1544 |
array('userid' => $user->id, 'name' => 'htmleditor')));
|