mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-81698' of https://github.com/stronk7/moodle
This commit is contained in:
commit
7fc931cdd8
143
.github/workflows/onebyone.yml
vendored
Normal file
143
.github/workflows/onebyone.yml
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
name: One by One Testing
|
||||
# Run all the individual unit tests one by one, with
|
||||
# fully independent PHPUnit executions. Useful to
|
||||
# detect issues with some tests that are using stuff
|
||||
# that has been made available by others, but is not
|
||||
# available when running individually.
|
||||
#
|
||||
# Note that we aren't using PHPUnit's own isolation
|
||||
# here but completely separated runs, one for each
|
||||
# test.
|
||||
#
|
||||
# The workflow will fail reporting all the tests
|
||||
# that have failed (and will pass if no failure is
|
||||
# detected, of course).
|
||||
#
|
||||
# It's only executed via workflow dispatch (automated
|
||||
# or manual), not by push/tag. And acceptd configuration
|
||||
# of phpunit, specially useful to run it with PHPUnit's
|
||||
# own isolation or any other option.
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
phpunit_extra_options:
|
||||
description: Additional options to apply to PHPUnit
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
env:
|
||||
chunks: 7
|
||||
|
||||
jobs:
|
||||
collect:
|
||||
name: Collect individual unit tests
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
matrix: ${{steps.individual-tests.outputs.matrix }}
|
||||
|
||||
steps:
|
||||
- name: Checking out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Looking for all individual tests
|
||||
id: individual-tests
|
||||
run: |
|
||||
count=0 # Number of individual tests found.
|
||||
while read -r testfile; do # For each test file.
|
||||
while read -r testname; do # For each unit test in a file.
|
||||
count=$((count + 1))
|
||||
# Sent it to the correct chunk file.
|
||||
chunk=$(((($count % $chunks)) + 1))
|
||||
echo "$testname $testfile" >> ./chunk_$chunk.txt
|
||||
done < <(grep "function test_" "${testfile}" | sed -r "s/^.*function (test_[a-zA-Z0-9_]+).*/\1/")
|
||||
done < <(find . -name "*_test.php")
|
||||
# Generate the matrix to run tests.
|
||||
echo "matrix=$(ls -1 chunk_*.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
|
||||
echo "$count individual tests collected in $chunks files"
|
||||
|
||||
- name: Upload individual tests files
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: individual_tests
|
||||
path: chunk_*.txt
|
||||
retention-days: 1
|
||||
|
||||
test:
|
||||
name: Run tests
|
||||
needs: collect
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
exttests:
|
||||
image: moodlehq/moodle-exttests
|
||||
ports:
|
||||
- 8080:80
|
||||
redis:
|
||||
image: redis
|
||||
ports:
|
||||
- 6379:6379
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
file: ${{ fromJson(needs.collect.outputs.matrix) }}
|
||||
|
||||
steps:
|
||||
- name: Setting up DB pgsql
|
||||
uses: m4nu56/postgresql-action@v1
|
||||
with:
|
||||
postgresql version: 13
|
||||
postgresql db: test
|
||||
postgresql user: test
|
||||
postgresql password: test
|
||||
|
||||
- name: Setting up PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.3
|
||||
ini-values: max_input_vars=5000
|
||||
coverage: none
|
||||
|
||||
- name: Checking out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download individual test files
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: individual_tests # Make all the chunk files available for the next steps.
|
||||
|
||||
- name: Setting up PHPUnit
|
||||
env:
|
||||
dbtype: pgsql
|
||||
run: |
|
||||
echo "pathtophp=$(which php)" >> $GITHUB_ENV
|
||||
cp .github/workflows/config-template.php config.php
|
||||
mkdir ../moodledata
|
||||
sudo locale-gen en_AU.UTF-8
|
||||
php admin/tool/phpunit/cli/init.php --no-composer-self-update
|
||||
|
||||
- name: Run PHPUnit test (one by one)
|
||||
env:
|
||||
dbtype: pgsql
|
||||
run: |
|
||||
status=0
|
||||
count=0
|
||||
while read -r line; do # For each line in the chunk file
|
||||
count=$((count + 1))
|
||||
filter="${line% *}"
|
||||
file="${line#* }"
|
||||
# Run the individual unit test and report problems if needed to.
|
||||
if ! php vendor/bin/phpunit \
|
||||
--fail-on-empty-test-suite \
|
||||
--fail-on-warning \
|
||||
--fail-on-risky \
|
||||
--filter "$filter" ${{ inputs.phpunit_extra_options }} \
|
||||
"$file" >/dev/null 2>&1; then
|
||||
if [ $status -eq 0 ]; then
|
||||
echo "Problems found, list of PHPUnit commands failing:"
|
||||
fi
|
||||
echo "vendor/bin/phpunit --filter '${filter}' ${{ inputs.phpunit_extra_options }} $file"
|
||||
status=$((status + 1))
|
||||
fi
|
||||
done < ${{ matrix.file }}
|
||||
echo "Finished: $count individual tests executed, $status tests failed"
|
||||
exit $status
|
@ -29,6 +29,14 @@ use stdClass;
|
||||
* @coversDefaultClass \core_adminpresets\manager
|
||||
*/
|
||||
class manager_test extends \advanced_testcase {
|
||||
/**
|
||||
* Include required libraries.
|
||||
*/
|
||||
public static function setUpBeforeClass(): void {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of protected get_site_settings method.
|
||||
*
|
||||
|
@ -25,6 +25,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_behat;
|
||||
|
||||
use behat_config_util;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@ -39,7 +43,7 @@ require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
|
||||
* @copyright 2016 Rajesh Taneja
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_behat_manager_util_testcase extends advanced_testcase {
|
||||
class manager_util_test extends \advanced_testcase {
|
||||
|
||||
/** @var array Fixtures features which are available. */
|
||||
private $featurepaths = array(
|
||||
|
@ -107,6 +107,7 @@ class helper_test extends \advanced_testcase {
|
||||
|
||||
public function test_get_restore_content_dir() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
|
||||
|
@ -27,6 +27,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php');
|
||||
require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php');
|
||||
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,14 @@ use backup;
|
||||
* @covers \restore_module_structure_step
|
||||
*/
|
||||
class backup_restore_activity_test extends \advanced_testcase {
|
||||
/**
|
||||
* Load the backup and restore classes.
|
||||
*/
|
||||
public static function setUpBeforeClass(): void {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that duplicating a page preserves the lang setting.
|
||||
|
@ -736,12 +736,15 @@ class plugin_test extends \advanced_testcase {
|
||||
* Test that a new group with the name of the course is created.
|
||||
*/
|
||||
public function test_enrol_meta_create_new_group() {
|
||||
global $DB;
|
||||
global $DB, $CFG;
|
||||
$this->resetAfterTest();
|
||||
// Create two courses.
|
||||
$course = $this->getDataGenerator()->create_course(array('fullname' => 'Mathematics'));
|
||||
$course2 = $this->getDataGenerator()->create_course(array('fullname' => 'Physics'));
|
||||
$metacourse = $this->getDataGenerator()->create_course(array('fullname' => 'All sciences'));
|
||||
|
||||
require_once($CFG->dirroot.'/enrol/meta/locallib.php');
|
||||
|
||||
// Run the function.
|
||||
$groupid = enrol_meta_create_new_group($metacourse->id, $course->id);
|
||||
// Check the results.
|
||||
|
@ -126,11 +126,15 @@ class grade_grade_test extends \grade_base_testcase {
|
||||
$this->assertEquals(40, \grade_grade::standardise_score(50, 30, 80, 0, 100));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Disabling this test: the set_locked() arguments have been modified, rendering these tests useless until they are re-written
|
||||
|
||||
protected function test_grade_grade_set_locked() {
|
||||
/**
|
||||
* Tests grade_grade::set_locked()
|
||||
*
|
||||
* @covers \grade_grade::set_locked
|
||||
*/
|
||||
public function test_grade_grade_set_locked(): void {
|
||||
// Skip this test because set_locked() arguments have been modified, rendering these tests
|
||||
// useless until they are re-written. Note this comes from MDL-32323 (2012!).
|
||||
$this->markTestSkipped('Useless set_locked() tests until they are re-written');
|
||||
$grade_item = new \grade_item($this->grade_items[0]);
|
||||
$grade = new \grade_grade($grade_item->get_final(1));
|
||||
$this->assertTrue(method_exists($grade, 'set_locked'));
|
||||
@ -154,7 +158,6 @@ class grade_grade_test extends \grade_base_testcase {
|
||||
|
||||
$this->assertTrue($grade->set_locked(true, false));
|
||||
}
|
||||
*/
|
||||
|
||||
protected function sub_test_grade_grade_is_locked() {
|
||||
$grade = new \grade_grade($this->grade_grades[0], false);
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace core;
|
||||
|
||||
use phpunit_util;
|
||||
|
||||
/**
|
||||
* Test basic_testcase extra features and PHPUnit Moodle integration.
|
||||
*
|
||||
@ -223,43 +225,156 @@ STRING;
|
||||
];
|
||||
}
|
||||
|
||||
// Uncomment following tests to see logging of unexpected changes in global state and database.
|
||||
/*
|
||||
public function test_db_modification() {
|
||||
global $DB;
|
||||
$DB->set_field('user', 'confirmed', 1, array('id'=>-1));
|
||||
}
|
||||
/**
|
||||
* Test that a database modification is detected.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @covers \phpunit_util
|
||||
*/
|
||||
public function test_db_modification(): void {
|
||||
global $DB;
|
||||
$DB->set_field('user', 'confirmed', 1, ['id' => -1]);
|
||||
|
||||
public function test_cfg_modification() {
|
||||
global $CFG;
|
||||
$CFG->xx = 'yy';
|
||||
unset($CFG->admin);
|
||||
$CFG->rolesactive = 0;
|
||||
}
|
||||
// Let's convert the user warnings into an assert-able exception.
|
||||
set_error_handler(
|
||||
static function ($errno, $errstr) {
|
||||
restore_error_handler();
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING // Or any other specific E_ that we want to assert.
|
||||
);
|
||||
|
||||
public function test_user_modification() {
|
||||
global $USER;
|
||||
$USER->id = 10;
|
||||
}
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Warning: unexpected database modification');
|
||||
phpunit_util::reset_all_data(true);
|
||||
}
|
||||
|
||||
public function test_course_modification() {
|
||||
global $COURSE;
|
||||
$COURSE->id = 10;
|
||||
}
|
||||
/**
|
||||
* Test that a $CFG modification is detected.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @covers \phpunit_util
|
||||
*/
|
||||
public function test_cfg_modification(): void {
|
||||
global $CFG;
|
||||
$CFG->xx = 'yy';
|
||||
unset($CFG->admin);
|
||||
$CFG->rolesactive = 0;
|
||||
|
||||
public function test_all_modifications() {
|
||||
global $DB, $CFG, $USER, $COURSE;
|
||||
$DB->set_field('user', 'confirmed', 1, array('id'=>-1));
|
||||
$CFG->xx = 'yy';
|
||||
unset($CFG->admin);
|
||||
$CFG->rolesactive = 0;
|
||||
$USER->id = 10;
|
||||
$COURSE->id = 10;
|
||||
}
|
||||
// Let's convert the user warnings into an assert-able exception.
|
||||
set_error_handler(
|
||||
static function ($errno, $errstr) {
|
||||
restore_error_handler();
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING // Or any other specific E_ that we want to assert.
|
||||
);
|
||||
|
||||
public function test_transaction_problem() {
|
||||
global $DB;
|
||||
$DB->start_delegated_transaction();
|
||||
}
|
||||
*/
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessageMatches('/rolesactive.*xx value.*removal.*admin/ms'); // 3 messages matched.
|
||||
phpunit_util::reset_all_data(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a $USER modification is detected.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @covers \phpunit_util
|
||||
*/
|
||||
public function test_user_modification(): void {
|
||||
global $USER;
|
||||
$USER->id = 10;
|
||||
|
||||
// Let's convert the user warnings into an assert-able exception.
|
||||
set_error_handler(
|
||||
static function ($errno, $errstr) {
|
||||
restore_error_handler();
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING // Or any other specific E_ that we want to assert.
|
||||
);
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Warning: unexpected change of $USER');
|
||||
phpunit_util::reset_all_data(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a $COURSE modification is detected.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @covers \phpunit_util
|
||||
*/
|
||||
public function test_course_modification(): void {
|
||||
global $COURSE;
|
||||
$COURSE->id = 10;
|
||||
|
||||
// Let's convert the user warnings into an assert-able exception.
|
||||
set_error_handler(
|
||||
static function ($errno, $errstr) {
|
||||
restore_error_handler();
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING // Or any other specific E_ that we want to assert.
|
||||
);
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Warning: unexpected change of $COURSE');
|
||||
phpunit_util::reset_all_data(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that all modifications are detected together.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @covers \phpunit_util
|
||||
*/
|
||||
public function test_all_modifications(): void {
|
||||
global $DB, $CFG, $USER, $COURSE;
|
||||
$DB->set_field('user', 'confirmed', 1, ['id' => -1]);
|
||||
$CFG->xx = 'yy';
|
||||
unset($CFG->admin);
|
||||
$CFG->rolesactive = 0;
|
||||
$USER->id = 10;
|
||||
$COURSE->id = 10;
|
||||
|
||||
// Let's convert the user warnings into an assert-able exception.
|
||||
set_error_handler(
|
||||
static function ($errno, $errstr) {
|
||||
restore_error_handler();
|
||||
throw new \Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING // Or any other specific E_ that we want to assert.
|
||||
);
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessageMatches('/resetting.*rolesactive.*new.*removal.*USER.*COURSE/ms'); // 6 messages matched.
|
||||
phpunit_util::reset_all_data(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an open transaction are managed ok by the reset code (silently rolled back).
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @covers \phpunit_util
|
||||
*/
|
||||
public function test_transaction_problem(): void {
|
||||
global $DB, $COURSE;
|
||||
$originalname = $DB->get_field('course', 'fullname', ['id' => $COURSE->id]); // Normally "PHPUnit test site".
|
||||
$changedname = 'Ongoing transaction test site';
|
||||
|
||||
// Start a transaction and make some database changes.
|
||||
$DB->start_delegated_transaction();
|
||||
$DB->set_field('course', 'fullname', $changedname, ['id' => $COURSE->id]);
|
||||
|
||||
// Assert that the transaction is open and the changes were made.
|
||||
$this->assertTrue($DB->is_transaction_started());
|
||||
$this->assertEquals($changedname, $DB->get_field('course', 'fullname', ['id' => $COURSE->id]));
|
||||
|
||||
phpunit_util::reset_all_data(false); // We don't want to detect/warn on database changes for this test.
|
||||
|
||||
// Assert that the transaction is now closed and the changes were rolled back.
|
||||
$this->assertFalse($DB->is_transaction_started());
|
||||
$this->assertEquals($originalname, $DB->get_field('course', 'fullname', ['id' => $COURSE->id]));
|
||||
}
|
||||
}
|
||||
|
@ -3515,9 +3515,9 @@ class accesslib_test extends advanced_testcase {
|
||||
// Test context_helper::reset_caches() method.
|
||||
|
||||
context_helper::reset_caches();
|
||||
$this->assertEquals(0, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals(0, context_inspection::check_context_cache_size());
|
||||
context_course::instance($SITE->id);
|
||||
$this->assertEquals(1, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals(1, context_inspection::check_context_cache_size());
|
||||
|
||||
|
||||
// Test context preloading.
|
||||
@ -3536,14 +3536,15 @@ class accesslib_test extends advanced_testcase {
|
||||
context_helper::preload_from_record($record);
|
||||
$this->assertEquals(new stdClass(), $record);
|
||||
}
|
||||
$this->assertEquals(count($records), context_inspection::test_context_cache_size());
|
||||
$this->assertEquals(count($records), context_inspection::check_context_cache_size());
|
||||
unset($records);
|
||||
unset($columns);
|
||||
|
||||
context_helper::reset_caches();
|
||||
context_helper::preload_course($SITE->id);
|
||||
$numfrontpagemodules = $DB->count_records('course_modules', array('course' => $SITE->id));
|
||||
$this->assertEquals(3 + $numfrontpagemodules, context_inspection::test_context_cache_size()); // Depends on number of default blocks.
|
||||
$this->assertEquals(3 + $numfrontpagemodules,
|
||||
context_inspection::check_context_cache_size()); // Depends on number of default blocks.
|
||||
|
||||
// Test assign_capability(), unassign_capability() functions.
|
||||
|
||||
@ -3967,13 +3968,13 @@ class accesslib_test extends advanced_testcase {
|
||||
$lastcourse = array_pop($testcourses);
|
||||
$this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$lastcourse)));
|
||||
$coursecontext = context_course::instance($lastcourse);
|
||||
$this->assertEquals(1, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals(1, context_inspection::check_context_cache_size());
|
||||
$this->assertNotEquals(CONTEXT_COURSE, $coursecontext->instanceid);
|
||||
$DB->delete_records('cache_flags', array());
|
||||
context_helper::delete_instance(CONTEXT_COURSE, $lastcourse);
|
||||
$dirty = get_cache_flags('accesslib/dirtycontexts', time()-2);
|
||||
$this->assertFalse(isset($dirty[$coursecontext->path]));
|
||||
$this->assertEquals(0, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals(0, context_inspection::check_context_cache_size());
|
||||
$this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$lastcourse)));
|
||||
context_course::instance($lastcourse);
|
||||
|
||||
@ -4028,20 +4029,21 @@ class accesslib_test extends advanced_testcase {
|
||||
for ($i=0; $i<CONTEXT_CACHE_MAX_SIZE + 100; $i++) {
|
||||
context_user::instance($testusers[$i]);
|
||||
if ($i == CONTEXT_CACHE_MAX_SIZE - 1) {
|
||||
$this->assertEquals(CONTEXT_CACHE_MAX_SIZE, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals(CONTEXT_CACHE_MAX_SIZE, context_inspection::check_context_cache_size());
|
||||
} else if ($i == CONTEXT_CACHE_MAX_SIZE) {
|
||||
// Once the limit is reached roughly 1/3 of records should be removed from cache.
|
||||
$this->assertEquals((int)ceil(CONTEXT_CACHE_MAX_SIZE * (2/3) + 101), context_inspection::test_context_cache_size());
|
||||
$this->assertEquals((int)ceil(CONTEXT_CACHE_MAX_SIZE * (2 / 3) + 101),
|
||||
context_inspection::check_context_cache_size());
|
||||
}
|
||||
}
|
||||
// We keep the first 100 cached.
|
||||
$prevsize = context_inspection::test_context_cache_size();
|
||||
$prevsize = context_inspection::check_context_cache_size();
|
||||
for ($i=0; $i<100; $i++) {
|
||||
context_user::instance($testusers[$i]);
|
||||
$this->assertEquals($prevsize, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals($prevsize, context_inspection::check_context_cache_size());
|
||||
}
|
||||
context_user::instance($testusers[102]);
|
||||
$this->assertEquals($prevsize+1, context_inspection::test_context_cache_size());
|
||||
$this->assertEquals($prevsize + 1, context_inspection::check_context_cache_size());
|
||||
unset($testusers);
|
||||
|
||||
|
||||
@ -5283,7 +5285,12 @@ class accesslib_test extends advanced_testcase {
|
||||
* Context caching fixture
|
||||
*/
|
||||
abstract class context_inspection extends \core\context_helper {
|
||||
public static function test_context_cache_size() {
|
||||
/**
|
||||
* Return the cached contexts count for testing purposes.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function check_context_cache_size() {
|
||||
return self::$cache_count;
|
||||
}
|
||||
}
|
||||
|
@ -1690,7 +1690,8 @@ class completionlib_test extends advanced_testcase {
|
||||
* @covers \aggregate_completions
|
||||
*/
|
||||
public function test_aggregate_completions() {
|
||||
global $DB;
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_activity.php');
|
||||
$this->resetAfterTest(true);
|
||||
$time = time();
|
||||
|
||||
|
@ -149,6 +149,9 @@ final class manager_test extends \advanced_testcase {
|
||||
* Test hook dispatching, that is callback execution.
|
||||
*/
|
||||
public function test_dispatch_with_invalid(): void {
|
||||
require_once(__DIR__ . '/../fixtures/hook/hook.php');
|
||||
require_once(__DIR__ . '/../fixtures/hook/callbacks.php');
|
||||
|
||||
// Missing callbacks is ignored.
|
||||
$componentfiles = [
|
||||
'test_plugin1' => __DIR__ . '/../fixtures/hook/hooks1_missing.php',
|
||||
|
@ -16,11 +16,6 @@
|
||||
|
||||
namespace core;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/lib/myprofilelib.php');
|
||||
|
||||
/**
|
||||
* Tests for myprofilelib apis.
|
||||
*
|
||||
@ -44,6 +39,16 @@ class myprofilelib_test extends \advanced_testcase {
|
||||
* @var \core_user\output\myprofile\tree The navigation tree.
|
||||
*/
|
||||
private $tree;
|
||||
|
||||
/**
|
||||
* Load required test libraries
|
||||
*/
|
||||
public static function setUpBeforeClass(): void {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/lib/myprofilelib.php');
|
||||
require_once($CFG->dirroot . '/user/profile/lib.php');
|
||||
}
|
||||
|
||||
public function setUp(): void {
|
||||
// Set the $PAGE->url value so core_myprofile_navigation() doesn't complain.
|
||||
global $PAGE;
|
||||
|
@ -1129,12 +1129,11 @@ class rtlcss_test extends basic_testcase {
|
||||
* @param array $data the provider data.
|
||||
* @dataProvider background_image_provider
|
||||
*/
|
||||
/* Not supported by MoodleHQ/RTLCSS yet.
|
||||
public function test_background_image($data) {
|
||||
$this->markTestSkipped('Not yet supported!');
|
||||
$output = new OutputFormat();
|
||||
$this->assert_sample($data, $output);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test background position.
|
||||
@ -1197,14 +1196,13 @@ class rtlcss_test extends basic_testcase {
|
||||
* @param array $data the provider data.
|
||||
* @dataProvider special_provider
|
||||
*/
|
||||
/* Not supported by MoodleHQ/RTLCSS yet.
|
||||
public function test_special($data) {
|
||||
$this->markTestSkipped('Not yet supported!');
|
||||
$output = new OutputFormat();
|
||||
$output->set('SpaceBeforeRules', ' ');
|
||||
$output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
|
||||
$this->assert_sample($data, $output);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test transform original.
|
||||
@ -1226,15 +1224,14 @@ class rtlcss_test extends basic_testcase {
|
||||
* @param array $data the provider data.
|
||||
* @dataProvider transforms_provider
|
||||
*/
|
||||
/* Not supported by MoodleHQ/RTLCSS yet.
|
||||
public function test_transforms($data) {
|
||||
$this->markTestSkipped('Not yet supported!');
|
||||
$output = new OutputFormat();
|
||||
$output->set('SpaceBeforeRules', ' ');
|
||||
$output->set('SpaceAfterRules', ' ');
|
||||
$output->set('SpaceAfterListArgumentSeparator', array('default' => '', ',' => ' '));
|
||||
$this->assert_sample($data, $output);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test values n-syntax.
|
||||
|
@ -485,7 +485,7 @@ class logging_test extends \advanced_testcase {
|
||||
|
||||
// Note PHPUnit does not support mocking static functions.
|
||||
$CFG->task_log_class = logging_test_mocked_logger::class;
|
||||
logging_test_mocked_logger::test_reset();
|
||||
logging_test_mocked_logger::reset_test();
|
||||
|
||||
return $CFG->task_log_class;
|
||||
}
|
||||
@ -533,7 +533,7 @@ class logging_test_mocked_logger implements task_logger {
|
||||
/**
|
||||
* Reset the test class.
|
||||
*/
|
||||
public static function test_reset() {
|
||||
public static function reset_test() {
|
||||
self::$isconfigured = true;
|
||||
self::$storelogfortask = [];
|
||||
self::$haslogreport = true;
|
||||
|
@ -16,6 +16,14 @@
|
||||
|
||||
namespace core\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// We need to keep this here because there is a provider
|
||||
// needing \core\task\adhoc_test_task and cannot move it
|
||||
// to setUpBeforeClass() or similar. Whenever we allow to
|
||||
// autoload fixtures, this can be removed.
|
||||
require_once(__DIR__ . '/../fixtures/task_fixtures.php');
|
||||
|
||||
/**
|
||||
* This file contains the unit tests for the task manager.
|
||||
*
|
||||
@ -26,10 +34,6 @@ namespace core\task;
|
||||
* @covers \core\task\manager
|
||||
*/
|
||||
final class manager_test extends \advanced_testcase {
|
||||
public static function setUpBeforeClass(): void {
|
||||
require_once(__DIR__ . '/../fixtures/task_fixtures.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_get_candidate_adhoc_tasks.
|
||||
*
|
||||
|
@ -226,7 +226,9 @@ class generator_test extends \advanced_testcase {
|
||||
* @param string $type Type of page to test: LESSON_PAGE_CLUSTER, LESSON_PAGE_ENDOFCLUSTER or LESSON_PAGE_ENDOFBRANCH.
|
||||
*/
|
||||
public function test_create_cluster_pages(string $type): void {
|
||||
global $DB;
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/mod/lesson/locallib.php');
|
||||
require_once($CFG->dirroot . '/mod/lesson/pagetypes/cluster.php');
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
|
@ -28,6 +28,13 @@ use ltiservice_gradebookservices\local\service\gradebookservices;
|
||||
* @coversDefaultClass \mod_lti\service\gradebookservices\local\gradebookservices
|
||||
*/
|
||||
class gradebookservices_test extends \advanced_testcase {
|
||||
/**
|
||||
* Load the necessary libs for the tests.
|
||||
*/
|
||||
public static function setUpBeforeClass(): void {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::instance_added
|
||||
@ -37,9 +44,6 @@ class gradebookservices_test extends \advanced_testcase {
|
||||
* that can be retrieved using the gradebook service API.
|
||||
*/
|
||||
public function test_lti_add_coupled_lineitem() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -75,9 +79,6 @@ class gradebookservices_test extends \advanced_testcase {
|
||||
* that can be retrieved using the gradebook service API.
|
||||
*/
|
||||
public function test_lti_add_coupled_lineitem_default_subreview() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -128,9 +129,6 @@ class gradebookservices_test extends \advanced_testcase {
|
||||
* the line items should be actually passed.
|
||||
*/
|
||||
public function test_get_launch_parameters_coupled() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -162,9 +160,6 @@ class gradebookservices_test extends \advanced_testcase {
|
||||
* launch is submission review.
|
||||
*/
|
||||
public function test_get_launch_parameters_coupled_subreview_override() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -193,9 +188,6 @@ class gradebookservices_test extends \advanced_testcase {
|
||||
* launch is submission review.
|
||||
*/
|
||||
public function test_get_launch_parameters_coupled_subreview_override_default() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -224,9 +216,6 @@ class gradebookservices_test extends \advanced_testcase {
|
||||
* if there is a single line item attached to that lti instance.
|
||||
*/
|
||||
public function test_get_launch_parameters_decoupled() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
|
@ -30,6 +30,10 @@ use mod_lti\privacy\provider;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/lti/locallib.php');
|
||||
|
||||
/**
|
||||
* Privacy provider tests class.
|
||||
*
|
||||
|
@ -31,7 +31,9 @@ use restore_controller;
|
||||
final class restore_39_test extends advanced_testcase {
|
||||
|
||||
public function test_restore_random_question_39(): void {
|
||||
global $DB, $USER;
|
||||
global $DB, $CFG, $USER;
|
||||
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
@ -269,8 +269,6 @@ class question_test extends \advanced_testcase {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$qtype = new qtype_calculated();
|
||||
|
||||
// Create a question.
|
||||
$q = \test_question_maker::get_question_data('calculated', 'mult');
|
||||
$q->id = 99;
|
||||
@ -284,6 +282,7 @@ class question_test extends \advanced_testcase {
|
||||
$units[] = $unit;
|
||||
$DB->insert_records("question_numerical_units", $units);
|
||||
|
||||
$qtype = new qtype_calculated();
|
||||
$qtypeobj = question_bank::get_qtype($qtype->name());
|
||||
$fakedata = ["a" => "5.7", "b" => "3.3"];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user