Skip to content

Commit

Permalink
Merge branch 'MDL-75952' of https://github.com/stronk7/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 12, 2024
2 parents 5c0ad52 + 361dfe8 commit 9cdc585
Show file tree
Hide file tree
Showing 134 changed files with 7 additions and 383 deletions.
2 changes: 0 additions & 2 deletions admin/presets/tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ private function add_to_config_log(string $name, string $oldvalue, string $value
public function access_protected($object, string $property) {
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($property);
$property->setAccessible(true);
return $property->getValue($object);
}

Expand All @@ -244,7 +243,6 @@ public function get_admin_preset_setting(string $category, string $settingname):

// Set method accessibility.
$method = new ReflectionMethod(manager::class, 'get_setting');
$method->setAccessible(true);

// Get the proper adminpresets_setting instance.
$settingpage = $adminroot->locate($category);
Expand Down
2 changes: 0 additions & 2 deletions admin/tool/dataprivacy/tests/expired_contexts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,6 @@ public function test_progress_tracer_default() {
$rc = new \ReflectionClass(\tool_dataprivacy\expired_contexts_manager::class);
$rcm = $rc->getMethod('get_progress');

$rcm->setAccessible(true);
$this->assertInstanceOf(\text_progress_trace::class, $rcm->invoke($manager));
}

Expand All @@ -2094,7 +2093,6 @@ public function test_progress_tracer_set() {
$rc = new \ReflectionClass(\tool_dataprivacy\expired_contexts_manager::class);
$rcm = $rc->getMethod('get_progress');

$rcm->setAccessible(true);
$this->assertSame($mytrace, $rcm->invoke($manager));
}

Expand Down
1 change: 0 additions & 1 deletion admin/tool/dataprivacy/tests/filtered_userlist_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function test_apply_expired_contexts_filters(array $initial, array $expir

$rc = new \ReflectionClass(\tool_dataprivacy\filtered_userlist::class);
$rcm = $rc->getMethod('set_userids');
$rcm->setAccessible(true);
$rcm->invoke($userlist, $initial);


Expand Down
1 change: 0 additions & 1 deletion admin/tool/langimport/tests/locale_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function test_set_locale(string $set, string $ret) {
$loc = new locale();
$rc = new \ReflectionClass(locale::class);
$rm = $rc->getMethod('set_locale');
$rm->setAccessible(true);

// Capture current locale for later restore (funnily, using the set_locale() method itself.
$originallocale = $rm->invokeArgs($loc, [LC_ALL, 0]);
Expand Down
5 changes: 0 additions & 5 deletions admin/tool/licensemanager/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function test_edit_existing_license() {

// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
$method->setAccessible(true); // Allow accessing of private method.
$method->invoke($manager, \tool_licensemanager\manager::ACTION_UPDATE, $testlicense->shortname);

// Should not create a new license when updating an existing license.
Expand All @@ -90,7 +89,6 @@ public function test_edit_license_not_exists() {

// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
$method->setAccessible(true); // Allow accessing of private method.

// Attempt to update a license that doesn't exist.
$formdata = [
Expand All @@ -111,7 +109,6 @@ public function test_edit_license_no_shortname() {

// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
$method->setAccessible(true); // Allow accessing of private method.

// Attempt to update a license without passing license shortname.
$formdata = [
Expand Down Expand Up @@ -148,7 +145,6 @@ public function test_edit_create_license() {

// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'edit');
$method->setAccessible(true); // Allow accessing of private method.
$method->invoke($manager, \tool_licensemanager\manager::ACTION_CREATE, $formdata['shortname']);

// Should create a new license in database.
Expand Down Expand Up @@ -180,7 +176,6 @@ public function test_change_license_order() {

// We're testing a private method, so we need to setup reflector magic.
$method = new ReflectionMethod('\tool_licensemanager\manager', 'change_license_order');
$method->setAccessible(true); // Allow accessing of private method.
$method->invoke($manager, \tool_licensemanager\manager::ACTION_MOVE_UP, 'cc-nc-4.0');

$licenseorder = array_keys(license_manager::get_licenses());
Expand Down
2 changes: 0 additions & 2 deletions admin/tool/mfa/factor/email/tests/factor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function test_check_verification_code() {
$emailfactorclass = new \factor_email\factor('email');
$rc = new \ReflectionClass($emailfactorclass::class);
$rcm = $rc->getMethod('check_verification_code');
$rcm->setAccessible(true);

// Assigned email to be used in getting the email factor.
$USER->email = '[email protected]';
Expand Down Expand Up @@ -76,7 +75,6 @@ public function test_check_verification_code() {

// Cleans up email records once MFA passed.
$rcm = $rc->getMethod('post_pass_state');
$rcm->setAccessible(true);
$rcm->invoke($emailfactorclass);

// Check if the email records have been deleted.
Expand Down
1 change: 0 additions & 1 deletion admin/tool/mfa/factor/sms/tests/factor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public function test_check_verification_code(): void {

// Check verification code.
$rcm = $rc->getMethod('check_verification_code');
$rcm->setAccessible(true);
$this->assertTrue($rcm->invoke($smsfactor, $secretcode));

// Test that calling the revoke on the generic type revokes all.
Expand Down
5 changes: 0 additions & 5 deletions admin/tool/mfa/factor/token/tests/factor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function test_calculate_expiry_time_in_general() {

set_config('expireovernight', 0, 'factor_token');
$method = new \ReflectionMethod($this->factor, 'calculate_expiry_time');
$method->setAccessible(true);

// Test that non-overnight timestamps are just exactly as configured.
// We don't need to care about 0 or negative ints, they will just make the cookie expire immediately.
Expand Down Expand Up @@ -95,7 +94,6 @@ public function test_calculate_expiry_time_in_general() {
public function test_calculate_expiry_time_for_overnight_expiry_with_one_day_expiry($timestamp) {
// Setup configuration.
$method = new \ReflectionMethod($this->factor, 'calculate_expiry_time');
$method->setAccessible(true);
set_config('expireovernight', 1, 'factor_token');
set_config('expiry', DAYSECS, 'factor_token');

Expand Down Expand Up @@ -144,7 +142,6 @@ public function test_calculate_expiry_time_for_overnight_expiry_with_one_day_exp
public function test_calculate_expiry_time_for_overnight_expiry_with_two_day_expiry($timestamp) {
// Setup configuration.
$method = new \ReflectionMethod($this->factor, 'calculate_expiry_time');
$method->setAccessible(true);
set_config('expireovernight', 1, 'factor_token');
set_config('expiry', 2 * DAYSECS, 'factor_token');

Expand Down Expand Up @@ -195,7 +192,6 @@ public function test_calculate_expiry_time_for_overnight_expiry_with_two_day_exp
public function test_calculate_expiry_time_for_overnight_expiry_with_three_hour_expiry($timestamp) {
// Setup configuration.
$method = new \ReflectionMethod($this->factor, 'calculate_expiry_time');
$method->setAccessible(true);
set_config('expireovernight', 1, 'factor_token');
set_config('expiry', 3 * HOURSECS, 'factor_token');

Expand Down Expand Up @@ -240,7 +236,6 @@ public function test_calculate_expiry_time_for_overnight_expiry_with_three_hour_
public function test_calculate_expiry_time_for_overnight_expiry_with_an_hour_expiry($timestamp) {
// Setup configuration.
$method = new \ReflectionMethod($this->factor, 'calculate_expiry_time');
$method->setAccessible(true);
set_config('expireovernight', 1, 'factor_token');
set_config('expiry', HOURSECS, 'factor_token');

Expand Down
5 changes: 0 additions & 5 deletions admin/tool/mfa/tests/secret_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function test_create_secret() {

// Mutate the sessionid using reflection.
$reflectedsessionid = new \ReflectionProperty($secman, 'sessionid');
$reflectedsessionid->setAccessible(true);
$reflectedsessionid->setValue($secman, 'fakesession');

$sec1 = $secman->create_secret(1800, false);
Expand Down Expand Up @@ -97,7 +96,6 @@ public function test_add_secret_to_db() {
// Let's make stuff public using reflection.
$reflectedscanner = new \ReflectionClass($secman);
$reflectedmethod = $reflectedscanner->getMethod('add_secret_to_db');
$reflectedmethod->setAccessible(true);

// Now add a secret and confirm it creates the correct record.
$reflectedmethod->invoke($secman, 'code', 1800);
Expand Down Expand Up @@ -164,7 +162,6 @@ public function test_validate_secret() {
// Session locked code from the same session id.
// Mutate the sessionid using reflection.
$reflectedsessionid = new \ReflectionProperty($secman, 'sessionid');
$reflectedsessionid->setAccessible(true);
$reflectedsessionid->setValue($secman, 'fakesession');

$secret = $secman->create_secret(1800, true);
Expand Down Expand Up @@ -227,7 +224,6 @@ public function test_has_active_secret() {
$reflectedscanner = new \ReflectionClass($secman);

$reflectedmethod = $reflectedscanner->getMethod('has_active_secret');
$reflectedmethod->setAccessible(true);

// DB secrets.
$this->assertFalse($reflectedmethod->invoke($secman));
Expand All @@ -244,7 +240,6 @@ public function test_has_active_secret() {
// Now check a secret with session involvement.
// Mutate the sessionid using reflection.
$reflectedsessionid = new \ReflectionProperty($secman, 'sessionid');
$reflectedsessionid->setAccessible(true);
$reflectedsessionid->setValue($secman, 'fakesession');

$this->assertFalse($reflectedmethod->invoke($secman, true));
Expand Down
2 changes: 0 additions & 2 deletions admin/tool/usertours/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function test_sesskey_required($function, $arguments) {

$rc = new \ReflectionClass('\tool_usertours\manager');
$rcm = $rc->getMethod($function);
$rcm->setAccessible(true);

$this->expectException('moodle_exception');
$rcm->invokeArgs($manager, $arguments);
Expand Down Expand Up @@ -186,7 +185,6 @@ public function test_move_tour($alltours, $movetourname, $direction, $expectedso
// Call protected method via reflection.
$class = new \ReflectionClass(\tool_usertours\manager::class);
$method = $class->getMethod('_move_tour');
$method->setAccessible(true);
$method->invokeArgs(null, [$tour, $direction]);

// Assert expected sortorder.
Expand Down
15 changes: 0 additions & 15 deletions admin/tool/usertours/tests/step_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public function test_fetch() {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcm = $rc->getMethod('fetch');
$rcm->setAccessible(true);

$id = rand(1, 100);
$this->assertEquals($retval, $rcm->invoke($step, 'fetch', $id));
Expand All @@ -150,7 +149,6 @@ public function test_dirty_values($name, $value) {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('dirty');
$rcp->setAccessible(true);

$this->assertTrue($rcp->getValue($step));
}
Expand Down Expand Up @@ -234,7 +232,6 @@ public function test_get_config_no_keys() {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('config');
$rcp->setAccessible(true);

$allvalues = (object) [
'some' => 'value',
Expand Down Expand Up @@ -361,7 +358,6 @@ public function test_get_config_valid_keys($values, $key, $default, $tourconfig,

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('config');
$rcp->setAccessible(true);
$rcp->setValue($step, $values);

$target = $this->getMockBuilder(\tool_usertours\local\target\base::class)
Expand Down Expand Up @@ -465,7 +461,6 @@ public function test_set_config($initialvalues, $key, $newvalue, $expected) {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('config');
$rcp->setAccessible(true);
$rcp->setValue($step, $initialvalues);

$target = $this->getMockBuilder(\tool_usertours\local\target\base::class)
Expand Down Expand Up @@ -542,12 +537,10 @@ public function test_persist_dirty_new() {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('dirty');
$rcp->setAccessible(true);
$rcp->setValue($step, true);

$tour = $this->createMock(\tool_usertours\tour::class);
$rcp = $rc->getProperty('tour');
$rcp->setAccessible(true);
$rcp->setValue($step, $tour);

$this->assertSame($step, $step->persist());
Expand Down Expand Up @@ -592,7 +585,6 @@ public function test_persist_force_new() {
$tour = $this->createMock(\tool_usertours\tour::class);
$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('tour');
$rcp->setAccessible(true);
$rcp->setValue($step, $tour);

$this->assertSame($step, $step->persist(true));
Expand Down Expand Up @@ -633,16 +625,13 @@ public function test_persist_dirty_existing() {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('id');
$rcp->setAccessible(true);
$rcp->setValue($step, 42);

$rcp = $rc->getProperty('dirty');
$rcp->setAccessible(true);
$rcp->setValue($step, true);

$tour = $this->createMock(\tool_usertours\tour::class);
$rcp = $rc->getProperty('tour');
$rcp->setAccessible(true);
$rcp->setValue($step, $tour);

$this->assertSame($step, $step->persist());
Expand Down Expand Up @@ -685,12 +674,10 @@ public function test_persist_force_existing() {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('id');
$rcp->setAccessible(true);
$rcp->setValue($step, 42);

$tour = $this->createMock(\tool_usertours\tour::class);
$rcp = $rc->getProperty('tour');
$rcp->setAccessible(true);
$rcp->setValue($step, $tour);

$this->assertSame($step, $step->persist(true));
Expand Down Expand Up @@ -752,7 +739,6 @@ public function test_remove_persisted() {

$rc = new \ReflectionClass(\tool_usertours\step::class);
$rcp = $rc->getProperty('id');
$rcp->setAccessible(true);
$rcp->setValue($step, $id);

$this->assertEquals($id, $step->get_id());
Expand Down Expand Up @@ -810,7 +796,6 @@ public function test_getters($key, $value) {
$rc = new \ReflectionClass(\tool_usertours\step::class);

$rcp = $rc->getProperty($key);
$rcp->setAccessible(true);
$rcp->setValue($step, $value);

$getter = 'get_' . $key;
Expand Down
Loading

0 comments on commit 9cdc585

Please sign in to comment.