64 Commits

Author SHA1 Message Date
Eloy Lafuente (stronk7)
674497a12c
MDL-81523 phpunit: Add all missing setUp/tearDown parent calls
All setUp(), tearDown(), setUpBeforeClass() and tearDownAfterClass()
must, always, call to parent, to ensure that everything is properly
set and cleaned.

While in a lot of situations this is not needed (parents may not
have anything to run), with PHPUnit >= 10 this can become more
important because we are going to move the reset code from current
placement @ runBare() to setUp()/tearDown().

Note that all the changes performed in this commit have been detected
and fixed by moodle-cs (ParentSetUpTearDownSniffTest).
2024-06-14 16:04:57 +02:00
Eloy Lafuente (stronk7)
4f7631113c
MDL-81522 phpunit: Add missing void return type to all tests #2
This commit includes more changes, all them also adding the :void
return type to unit tests missing them.

The difference is that all these changes, while also detected
perfectly by the moodle.PHPUnit.TestReturnType sniff, were not
auto-fixed (like the previous commit ones), because all them
do include some "return" statement and, for safety, we don't
fix them.

All the cases have been visually inspected and confirmed that
the existing "return" statements always belong to anon
functions within the test body and not the test own return statement.
2024-06-11 11:55:08 +02:00
Eloy Lafuente (stronk7)
01148a0816
MDL-81522 phpunit: Add missing void return type to all tests
While this change is not 100% required now, it's good habit
and we are checking for it since Moodle 4.4.

All the changes in this commit have been applied automatically
using the moodle.PHPUnit.TestReturnType sniff and are, exclusively
adding the ": void" return types when missing.
2024-06-11 11:55:07 +02:00
Eloy Lafuente (stronk7)
29a541724f
MDL-65292 style: Fix all the function declaration ordering
This has been generated running the following Sniff,
part of the Moodle's CodeSniffer standard:
- PSR2.Methods.MethodDeclaration

It just ensures all the function declarations have
the correct order for:
- abstract and final.
- visibility (public, protected, private).
- static.

So, all the lines modified by this commit are function declarations
and the only changes are in the positions of those keywords.
2024-02-28 23:47:47 +01:00
Peter Mayer
cdc66a5ff4 MDL-77439 lib_filebrowser: Splitup query to speedup get_courses 2023-05-16 20:36:50 +08:00
Marina Glancy
8fc1486d36 MDL-77164 various: fix incorrect phpdocs 2023-04-13 11:35:06 +01:00
Andrew Nicols
b0aa0b63e0 MDL-76362 core_file: Check prefix exists before checking length 2023-01-23 09:15:55 +08:00
Marina Glancy
b0a83aa7bd MDL-76362 various: Avoid passing nulls to functions that don't allow nulls
PHP 8.1 is more strict on the parameter type. Functions such as trim(), strlen(), str_replace(), etc
show notice when null is passed as an argument
2023-01-23 09:15:54 +08:00
Eloy Lafuente (stronk7)
83b490a594 MDL-75111 phpunit: Move tests to use correct names and ns (take#4)
Applied the following changes to various testcase classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.

Special mention to:

- The following task tests have been moved within the level2 directory:
  - \core\adhoc_task_test => \core\task\adhoc_task_test
  - \core\scheduled_task_test => \core\task\scheduled_task_test
  - \core\calendar_cron_task_test => \core\task\calendar_cron_task_test
  - \core\h5p_get_content_types_task_test => \core\task\h5p_get_content_types_task_test
  - \core\task_database_logger_test => \core\task\database_logger_test
  - \core\task_logging_test => \core\task\logging_test

- The following event tests have been moved within level2 directory:
  - \core\event_context_locked_test => \core\event\context_locked_test
  - \core\event_deprecated_test => \core\event\deprecated_test
  - \core\event_grade_deleted_test => \core\event\grade_deleted_test
  - \core\event_profile_field_test => \core\event\profile_field_test
  - \core\event_unknown_logged_test => \core\event\unknown_logged_test
  - \core\event_user_graded_test => \core\event\user_graded_test
  - \core\event_user_password_updated_test => \core\event\user_password_updated_test

- The following output tests have been moved within level2 directory:
  - \core\mustache_template_finder_test => \core\output\mustache_template_finder_test
  - \core\mustache_template_source_loader_test => \core\output\mustache_template_source_loader_test
  - \core\output_mustache_helper_collection_test => \core\output\mustache_helper_collection_test

- The following tests have been moved to their correct tests directories:
  - lib/tests/time_splittings_test.php => analytics/tests/time_splittings_test.php

- All the classes and tests under lib/filebrowser and lib/filestorage
  belong to core, not to core_files. Some day we should move
  them to their correct subsystem.
- All the classes and tests under lib/grade belong to core, not
  to core_grades. Some day we should move them to their correct
  subsystem.
- The core_grades_external class and its \core\grades_external_test
  unit test should belong to the grades subsystem or, alternatively,
  to \core\external, they both should be moved together.
- The core_grading_external class and its \core\grading_external_test
  unit test should belong to the grading subsystem or, alternatively,
  to \core\external, they both should be moved together.
- The \core\message\message and \core\message\inbound (may be others)
  classes, and their associated tests should go to the core_message
  subsystem.
- The core_user class, and its associated tests should go to the
  core_user subsystem.
- The \core\update namespace is plain wrong (update is not valid API)
  and needs action 1) create it or 2) move elsewhere.
2022-08-26 16:34:20 +02:00
Eloy Lafuente (stronk7)
f6711bb394 MDL-67673 phpunit: Fix the return type of template methods
All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.

At the same time, fix a few wrong function names,
provider data and param types, return statements...
2020-10-21 12:45:59 +02:00
Marina Glancy
beff3806d6 MDL-10965 courses: capability to browse course list 2019-04-10 12:35:28 +02:00
Neill Magill
1b43c84980 MDL-63103 filebrowser: Speed up finding activities with files
Before this change the query examined at every course_module record in
the context table.

With this change we use the course_modules table to more efficiently
find all the activities in the course, which means that many less
records in the context table need to be examined.
2019-01-11 08:58:39 +00:00
Andrew Nicols
0616f045c3 MDL-53566 core: Add support for context locking
This chagne adds support for a new feature known as Context Locking.
This allows a context to be locked, thereby removing all write
capabilities for all users (including admin) for that context, and all
child contexts.
2018-11-13 21:17:40 +08:00
Marina Glancy
442f12f81a MDL-62742 core: rename coursecat->core_course_category
Also rename course_in_list -> core_course_list_element
Deprecate class coursecat_sortable_records
2018-08-28 11:36:23 +02:00
Mihail Geshoski
02de9f2014 MDL-62798 repositories: Report sections by name in server repository 2018-08-06 09:55:35 +08:00
Mark Johnson
3bc65933cf MDL-62488 filebrowser: Stop unit tests assuming number of categories 2018-05-17 16:01:26 +01:00
Jake Dallimore
54945fa728 MDL-35429 roles: teachers and managers can restore automated backups
Changes the default for the 'moodle/restore:viewautomatedfilearea'
cap from 'Not set' to 'Allow' for the teacher and manager role
archetypes.
2017-10-09 10:29:07 +08:00
Jake Dallimore
521d900f06 MDL-35429 restore: fixed downloading of automated backup files 2017-10-09 10:29:07 +08:00
Marina Glancy
ed483bda8d MDL-35668 filebrowser: system context is similar to coursecat 2017-08-31 13:56:59 +08:00
Marina Glancy
84d815611c MDL-35668 filebrowser: perf improvements for courses
When searching for non-empty children first retrieve list of all non-empty
fileareas in modules and then check access for each of them. This will be
much faster than checking access for each module and then look for files
and areas inside this module.

Do the same with course file areas
2017-08-30 12:43:26 +08:00
Marina Glancy
10122f009e MDL-35668 filebrowser: small improvements to modules
- Store cm_info in file_info_context_module instead of object
- Use correct API calls to component_callback_exists
- Use human readable name of module type
2017-08-30 12:43:26 +08:00
Marina Glancy
ade66228fa MDL-35668 filebrowser: cache enrolled courses 2017-08-30 12:43:26 +08:00
Marina Glancy
2d939622b8 MDL-35668 filebrowser: perf improvements to coursecat
- Preload contexts of subcategories and courses when retrieving their lists
- When there are enrolled courses in hidden subcategories retrieve them together with direct children courses
- Do not call browser->get_file_info - it retrieves the coursecat/course again, instead initialise the instance
of file_info_context_coursecat or file_info_context_course
2017-08-30 12:43:22 +08:00
Marina Glancy
c524a6dce0 MDL-35668 filebrowser: unittests 2017-08-29 09:57:59 +08:00
Marina Glancy
07d4777816 MDL-33741 file_info: show courses in hidden categories
This also has a couple of bugfixes:
- file_info_context_system::get_children() was looking for courses with parent=0, it is impossible, block removed;
- file_info_context_coursecat::get_area_coursecat_description() was checking the wrong capability to view files in description
2016-08-01 09:12:36 +08:00
Mark Nelson
94f78b0d15 MDL-46927 core_files: fixed issue with system course restores
When clicking on 'Restore' next to a file in the 'Course
backup area' in the system context the message 'Sorry,
the requested file could not be found' was displayed.
This fix adds missing functionality to the class
'file_info_context_system' so that the file information
is correctly returned.
2015-06-01 23:08:40 -07:00
James Henestofel
b8db22818a MDL-42068 Filepicker course listing use setting courselistshortname to show shortname and fullname 2013-10-04 13:09:10 -04:00
Petr Škoda
2f1e464a88 MDL-40438 migrate all collatorlib:: and textlib:: uses 2013-08-06 21:04:35 +02:00
Mark Nelson
dd33f4af0a MDL-40462 libraries: deprecated get_course_context() 2013-07-11 13:28:45 +08:00
Rajesh Taneja
7f5b51c4e6 MDL-40404 Libraries: Deprecated get_parent_contextid() 2013-07-09 14:33:21 +08:00
Marina Glancy
d1f8c1bd62 MDL-38708 Added course overview files (most often images) to courses 2013-04-02 11:08:21 +11:00
Dan Poltawski
a1d9f433ec Merge branch 'w51_MDL-37301_m25_coursecatinfoas' of git://github.com/skodak/moodle 2013-01-08 10:26:44 +08:00
Petr Škoda
dd9cd338cf MDL-37301 fix missing AS in select
This was breaking pg 8.3. Credit goes to Thomas Robb, thanks.
2012-12-26 22:25:24 +01:00
Petr Škoda
171215d465 MDL-37254 add missing AS keyword 2012-12-22 14:11:22 +01:00
Sam Hemelryk
f7de90a74a MDL-33857 fixed up whitespace 2012-10-16 13:32:34 +08:00
Marina Glancy
43aadf0401 MDL-33857 Increase performance of queries for Server files repository (small improvements) 2012-10-10 15:21:27 +08:00
Marina Glancy
b8de262139 MDL-33857 Increase performance of queries for Server files repository
- file_info class now has new methods get_non_empty_children and count_non_empty_children; added default implementation;
- all core classes extending file_info have their implementation of those methods;
- class repository_local_file used for caching get_children() results is removed;
- class repository_local rewritten to use new methods from file_info;
- added caching of retrieved modules in file_browser::get_file_info_context_module() - this query is slow and executed multiple times on big servers
2012-10-10 15:21:26 +08:00
Ankit Agarwal
5fbe2118bc MDL-34549 libraries: Changing strictness of context::instance_by_id() when required 2012-08-24 11:30:35 +08:00
Ankit Agarwal
d197ea4300 MDL-34549 libraries: Replace get_context_instance_by_id() by context::instance_by_id() 2012-08-24 11:30:10 +08:00
Adrian Greeve
b0c6dc1cac MDL-34465 - lib - Replacing get_context_instance with context_XXXX::instance (group 8) 2012-07-27 10:10:46 +08:00
Aparup Banerjee
7cacb2ef08 Merge branch 'wip-MDL-33297-master' of git://github.com/abgreeve/moodle 2012-06-21 17:34:57 +08:00
Adrian Greeve
35ca63c166 MDL-33297 - forum - workshop - glossary - data - Updated the check for files to allow students to see files they recently uploaded. 2012-06-20 10:49:18 +08:00
Marina Glancy
1778f310f3 MDL-33417 Show reference icon for files in filepicker 2012-06-19 11:15:51 +08:00
Marina Glancy
0b2bfbd1c6 MDL-33550 Correctly process situation when file reference source is missing
- do not die with fatal error if source file in moodle internal repository is missing;
- moved code duplication for moodle repositories into class repository (functions send_file, get_reference_details, get_file_by_reference, get_file_reference);
- update file status after repository::sync_external_file so we know that it is missing (or not missing anymore). Do not run this function more than once for file within one request;
- display readable name for Private Files and Server files with the new format;
- display broken icon in filemanager if we know that source is missing, display information (for admin) where it was located before: see repository::get_reference_details() and extending classes;
- removed unnecessary queries in stored_file::sync_external_file();
- syncronize files before displaying it's size in mod_resource, do not query  directly
2012-06-13 12:11:06 +08:00
Marina Glancy
2dfa16ef8a MDL-33409 Newly copied files should take on the userid of the current user, and dates reset
- changed function repository::copy_to_area so it accepts more file attributes, pass changed attributes to it
- changed file_info::copy_to_storage and file_info_stored::copy_to_storage to accept more file attributes
- simplified file size check for moodle files in repository/repository_ajax.php
- removed unused code in repository/repository_ajax.php
2012-06-05 09:26:26 +08:00
Sam Hemelryk
849b9a6af7 MDL-33399 mixed: Fixed up calls to get_area_files that used empty sorts 2012-05-29 16:44:28 +12:00
Marina Glancy
9dbdf31f8c MDL-32867 Display a list of references pointing to the file in filemanager 2012-05-21 11:57:54 +08:00
David Mudrak
97b603c621 MDL-31901 fixed the name of user draft file serving handler
Files stored in user context, draft are must be served by draftfile.php,
not the pluginfile.php.
2012-05-21 11:57:53 +08:00
David Mudrak
0dbf6c88bb MDL-31901 file_info_stored now provides access to the wrapped stored_file's get_imageinfo() method 2012-05-21 11:57:53 +08:00
Marina Glancy
e2652f1a31 MDL-27236: Server files, improve tree view
- Removed 'Private files' from 'Server files' repository;
- Show only non-empty directories (taking into account filetype filter);
- If there is only one non-empty filearea within a module, do not show it and skip the extra subdirectory level;
- If the user is not admin (does not have 'moodle/course:update' capability in system context), do not show course categories, just list available courses;
- Also when retrieving the course files capability to managefiles is checked before retrieving the modules list for performance tuning on sites with a lot of courses
2012-03-21 13:55:22 +08:00