Commit Graph

129 Commits

Author SHA1 Message Date
c9d48f6f25 MDL-81581 phpunit: Create the normalise_line_endings() method
And apply it to all the obvious places related with the issue.

Note that surely there are way more in code base, but it's
out of scope for this issue.
2024-04-25 18:52:25 +02:00
62c560dff2 MDL-81456 core: Correct namespace imports 2024-04-09 16:13:42 +08:00
fa2e11105a MDL-81456 core: Stop injecting test data into real hook manager 2024-04-08 09:36:21 +08:00
2b49ad42f5 MDL-81456 core: Use DI for all hook access
Using DI for all hook access means that it becomes significantly easier
to mock hooks and callbacks for unit testing without fundamentally
altering the structure of the code purely for the purposes of unit
testing.
2024-04-08 09:35:41 +08:00
788556f652 MDL-80099 hooks: Add mechanism to deprecate class callbacks 2024-03-20 14:58:16 +00:00
361dfe8145 MDL-75952 general: Since php81, refection->setAccessible() is no-op
Refereces:
- https://wiki.php.net/rfc/make-reflection-setaccessible-no-op
- https://www.php.net/manual/en/reflectionproperty.setaccessible.php
- https://www.php.net/manual/en/reflectionmethod.setaccessible.php

As of PHP 8.1.0, calling this method has no effect; all methods are
invokable by default. So, let's remove all uses from core, they are
no-op.
2024-03-10 21:15:00 +01:00
ba1f804ffa MDL-65292 style: Fix all function declarations white space
This has been generated running the following Sniffs, all
them part of the Moodle's CodeSniffer standard:
- PSR12.Functions.ReturnTypeDeclaration
- PSR12.Functions.NullableTypeDeclaration
- moodle.Methods.MethodDeclarationSpacing
- Squiz.Whitespace.ScopeKeywordSpacing

All them are, exclusively, about correct spacing, so the changes
are, all them, only white space changes.

Only exceptions to the above are 3 changes what were setting the
return type in a new line, and, when that happens, the closing
parenthesis (bracket) has to go to the same line than the colon.
2024-02-28 23:33:26 +01:00
6e2c5b7b45 MDL-80844 phpunit: Only some tests can use the debugging sink
The only tests that have COMPLETE* support for the debugging sink
are the advanced_testcase and the database_driver ones (store and
report). So we must ensure that the rest of tests don't use the
debugging sink at all.

Right now we are using it for storing, but later there is not
reporting, so any debugging happening within non advanced tests
is not detected.

This commit just ensures that we stop making that storing for
non advanced/database_driver tests. Nothing more, nothing less.

* Note that we have had to add a few missing bits to the
database_driver testcase because it was not 100% complete. Now
it behaves 100% the same than the advanced_testcase one regarding
the debugging sink.
2024-02-15 18:46:16 +01:00
9ed3f83dd2 MDL-80072 core: Add \core\di wrapper to php-di
The \core\di class is a Moodle wrapper to php-di which is intended to
allow Moodle to switch to an alternate DI solution in the future if
required. All interaction with the container uses the PSR-11 Container
interfaces, which allows for normalisation of configuration, setting,
and retrieving of DI container-identified classes.
2024-02-12 11:11:16 +08:00
99a6cd12b2 MDL-79637 phpunit: Do not reset DB during init of isolated tests
During the bootstrap of PHPUnit we ensure that the database has been
reset to its initial state.

We do this by checking the internally-stored DB write count between
runs. If the count is not yet set (null), or it has been increased, we
force a reset.

When running an isolated test the test runner resets the database, it
then sets up a new isolated test environment by writing a new PHPUnit
test case and passing it to a new PHP Process using standard in. As part
of this, the bootstrap is run for that process.

Because we are in a new process, the db write count is fresh and not yet
set. This has been leading to an additional db reset before the isolated
test.

To handle this we want to _not_ perform a reset during the
initialisation for isolated runs. We know that the DB is in a fresh
state before we start the run.

To support this we need to know whether the test is an isolated test
during the bootstrap, which means we cannot use the previous approach to
calculating this.

Instead we look at the PHP_SELF value. PHP sets this to "Standard input
code" when run from stdin, instead of running a file.

There should not be any other legitimate reason to run a PHPUnit
bootstrap via this stdin approach.

Unfortunately this approach is a little bit risky as it depends on the
presence of a specific string, however this string has been in place
since 2016, and there is no legitimate way of calculating this.

I did consider looking at whether the called script included `/vendor/`
and `/phpunit`, but this is also likely a risky approach if someone
calls PHPUnit in an unexpected way.

This approach is itself unit tested so any change to PHP's stdin string
before we deprecate this approach entirely in 12 months time will be
caught.
2023-10-11 09:29:26 +08:00
b2a2d3dc66 MDL-79338 core: add support for hook callback redirection in tests 2023-09-14 11:47:52 +02:00
d8a4cc9533 MDL-67186 group: add custom fields 2023-08-09 11:02:49 +10:00
8fc1486d36 MDL-77164 various: fix incorrect phpdocs 2023-04-13 11:35:06 +01:00
c11d4284be MDL-77130 cohort: add custom fields 2023-04-04 13:01:40 +10:00
7015cbf75f MDL-73592 phpunit: Run adhoc tasks after install 2022-02-18 02:09:49 +11:00
3a70983d53 MDL-72701 unit tests: Generate default coverage 2021-12-21 09:24:00 +08:00
0188af39a1 MDL-72588 reportbuilder: performance improvement to report loader.
Statically cache list of loaded reports during request lifecycle,
this ensures that computationally heavy initialisation routines
in system reports are only executed once (e.g. the access tab).
2021-10-29 12:50:20 +02:00
0fc73ee581 MDL-72085 core_phpunit: reset session notifications 2021-07-29 13:00:39 +10:00
21d93554d4 MDL-71863 courseformat: create courseformat subsystem 2021-06-28 13:50:18 +02:00
18a7f0134d MDL-56873 admin: Set sensible default cURL security settings 2021-06-10 12:01:39 +08:00
490c72f491 MDL-53544 core: Remove typo3 usages in core 2021-05-26 16:46:30 +08:00
cfba0366db Merge branch 'MDL-70893-master' of git://github.com/marinaglancy/moodle 2021-03-18 00:23:26 +01:00
ebf078458d Merge branch 'MDL-71036' of https://github.com/stronk7/moodle 2021-03-17 20:05:25 +08:00
682ce8f07a MDL-71036 phpunit: xml config - change generation code to follow xsd
This performs all the changes needed in the util generator to
produce XML files compliant with the new schema (see previous
commit for description of changes).

- All the occurrences in code of filter => coverage.
- All the occurrences in code of whitelist => include.
- Apply all the changes to comply with the new schema.

- Remove processUncoveredFilesFromWhitelist attribute, useless (false
    is its default value, and now have another name).
- Move from 4-spaces indented XML to 2-spaces indented.
- Small linefeed tweaks to generate better-looking XML.
2021-03-11 23:04:31 +01:00
1c839f9072 MDL-65974 course: move format_base to core_course\course_format 2021-03-11 17:36:34 +01:00
0eada7a5f9 MDL-70893 various: optional function arguments must be in the end 2021-02-15 16:53:37 +01:00
703af2f91b MDL-68098 tests: Reset FILTERLIB_PRIVATE after tests 2020-09-23 11:18:41 +02:00
f070dd126f MDL-67726 tool_phpunit: Removed webrunner tool 2020-02-07 08:08:48 +08:00
4af44dbc8e MDL-67353 course: move form tearDown() to reset_all_data()
We are already cleaning all sort of caches, statics, singletons
there and it's better to ensure they are always reset to avoid
myterious failures @ distance.
2020-01-29 23:43:57 +01:00
fc1785b086 MDL-60978 testing: Support ability to run phpunit in isolated process 2019-06-21 14:36:13 +08:00
0970aa10af MDL-63366 core_phpunit: Add ability to specify coverage filters 2019-03-01 10:30:31 +08:00
b2f349a433 MDL-54035 accesslib: separate role definition cache clear
Thanks to MDL-49398, we can separate the combined user session and role
definition cache clearing function into two separate functions. At the
same time, we want to identify and remove mark_dirty() calls that were
added for role definition changes but were incorrectly left behind.

Change highlights:
 - Remove unnecessary mark_dirty() calls performed after
   assign_capability(), unassign_capability(), delete_role(),
   deleted contexts, brand new contexts
 - Move role definition cache clear from the user-centric
   accesslib_clear_all_caches() to the newly created,
   role-dedicated accesslib_reset_role_cache()
2018-09-21 09:17:42 -04:00
5454e72c21 MDL-55188 events: First deprecation of eventslib.php 2018-07-30 09:23:54 +08:00
883ce42127 MDL-36941 core: convert existing api to use new table structure
Also deprecated the following functions -

1. message_move_userfrom_unread2read - It is not necessary
   for us to mark a message as read on user deletion.
2. message_get_blocked_users - Horrible logic used to
   determine if a user is blocked via reference on some
   randomly chosen 'isblocked' variable.
3. message_get_contacts - The same as above. This can be
   done in a much nicer way.
4. message_mark_message_read - We want two functions to do
   this to avoid confusing messages and notifications.
5. message_can_delete_message - This assumed the variable
   $message contained the 'useridto' property, which
   was present in the old table structure. We do not want
   future usages where a query is done on the new table
   and is simply passed as this won't contain this property.
6. message_delete_message - Same as above.
2018-03-23 12:30:27 +08:00
801a372dad MDL-60611 phpunit: switch to namespaced phunit classes 2017-11-02 23:45:34 +01:00
a272c25649 Merge branch 'MDL-60600_master' of https://github.com/marxjohnson/moodle 2017-10-26 18:33:49 +02:00
a9ca3fa167 MDL-60600 core_output: Clear static icon system cache between unit tests 2017-10-26 14:59:35 +01:00
3a89d0b541 MDL-60434 analytics: Analysables lazy loading 2017-10-25 14:16:35 +02:00
5a97f26be9 MDL-60342 test: Reset user agent after tests
- Add a test that proves this useragent is not being reset after a test
- Reset user agent
2017-10-18 14:03:24 +11:00
2db6e9811b MDL-59212 analytics: Core indicators tests
Part of MDL-57791 epic.
2017-07-24 08:37:01 +02:00
63e9e38202 MDL-58911 calendar: use the same callbacks in unittests and prod
Remove unittest-specific callbacks for checking access and displaying
the calendar events on the dashboard.

This will allow plugin developers unittest the full behavior
of how their plugins add events to the dashboard.

Reset all static caches between unittests.
2017-06-20 16:13:35 +08:00
f98ad251ae Merge branch 'MDL-55139' of git://github.com/stronk7/moodle 2017-03-28 18:33:19 +01:00
36cc9f8e37 MDL-54628 behat: Set behat dir for each run under behat_dataroot
Before this patch behat_dataroot for parallel runs
were created at same level as ->behat_dataroot
After this patch, it will be created 1 level under
->behat_dataroot with BEHAT_PARALLEL_SITE_NAME
prefix and run number as suffix. This will allow
common files as test enabled and parallel run info
to be saved in parent directory and access it easily.
2017-01-30 08:51:53 +08:00
f6d9efefaa MDL-48498 core_files: curl_security_helper_base and implementation
Base class and core implementation providing a means to check URLs
against the curl security admin settings entries.
2016-11-08 15:11:15 +08:00
90abff01b3 Merge branch 'MDL-54751-master-v5' of https://github.com/snake/moodle 2016-11-07 08:55:44 +08:00
3704ff8cde MDL-54751 phpunit: Support adhoc module and section deletion in phpunit
Created a new phpunit util function run_all_adhoc_tasks which runs any
pending tasks, for use in unit tests. Added new recyclebin and course
unit tests covering the new functionality.
2016-11-07 07:41:59 +08:00
fab11235d8 MDL-38158 core_media: Convert media players to new plugin type
AMOS BEGIN
  MOV [siteyoutube,core_media],[pluginname,media_youtube]
  MOV [siteyoutube_desc,core_media],[pluginname_help,media_youtube]
  MOV [sitevimeo,core_media],[pluginname,media_vimeo]
  MOV [sitevimeo_desc,core_media],[pluginname_help,media_vimeo]
  MOV [html5audio,core_media],[pluginname,media_html5audio]
  MOV [html5audio_desc,core_media],[pluginname_help,media_html5audio]
  MOV [html5video,core_media],[pluginname,media_html5video]
  MOV [html5video_desc,core_media],[pluginname_help,media_html5video]
  MOV [flashanimation,core_media],[pluginname,media_swf]
  MOV [flashanimation_desc,core_media],[pluginname_help,media_swf]
AMOS END
2016-11-04 17:30:40 +08:00
ef15173794 MDL-56354 unittests: Put debug messages in the failure notice. 2016-10-26 08:39:10 +11:00
9123439e06 MDL-55139 unit tests: Make code-coverage for components way better
By specifying the filter on all those partial phpunit.xml files
we are restricting in a 99% the effort (time and memory) needed
by phpunit to process xdebug execution coverage, retricting it
to the target files within a component.
2016-10-07 00:41:22 +02:00
972a367b98 MDL-55741 phpunit: does not reset get_log_manager cache 2016-08-26 17:14:17 +01:00