197 Commits

Author SHA1 Message Date
Andrew Nicols
44d734147a MDL-77837 phpunit: Ensure that the cron user setter is used
When running an adhoc task in a unit test we should use the cron variant
of the set user method to mimic the behaviour of a real cron run.
2023-04-06 23:21:29 +08:00
Paul Holden
2d6139242c MDL-74671 phpunit: remove file/directory coverage duplicates. 2022-06-27 10:16:14 +01:00
Eloy Lafuente (stronk7)
a5c91474ee MDL-71807 cleanup: Replace deprecated codingStandardsIgnore annotations
The PHP_CodeSniffer @codingStandardsIgnore annotations are deprecated
and, since version 3.x, the new // phpcs:ignore comments should be used
instead.

This commits just reviews all the uses in core, replacing them for
the better new candidate, or removing when no longer needed.
2022-03-08 10:48:53 +01:00
Shamim Rezaie
7015cbf75f MDL-73592 phpunit: Run adhoc tasks after install 2022-02-18 02:09:49 +11:00
Andrew Nicols
3a70983d53 MDL-72701 unit tests: Generate default coverage 2021-12-21 09:24:00 +08:00
Paul Holden
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
Laurent David
93a3724d8e MDL-72496 question tests: fix assertTag if tag not found
* The basic_test::assertTag method will issue a warning as $tag is not
found, failing the PHP Unit test that uses this method.
* Add tests to check that assertTag is working
2021-09-30 13:04:45 +02:00
Dmitrii Metelkin
0fc73ee581 MDL-72085 core_phpunit: reset session notifications 2021-07-29 13:00:39 +10:00
Ferran Recio
21d93554d4 MDL-71863 courseformat: create courseformat subsystem 2021-06-28 13:50:18 +02:00
Michael Hawkins
18a7f0134d MDL-56873 admin: Set sensible default cURL security settings 2021-06-10 12:01:39 +08:00
Peter Dias
490c72f491 MDL-53544 core: Remove typo3 usages in core 2021-05-26 16:46:30 +08:00
Eloy Lafuente (stronk7)
cfba0366db Merge branch 'MDL-70893-master' of git://github.com/marinaglancy/moodle 2021-03-18 00:23:26 +01:00
Jun Pataleta
ebf078458d Merge branch 'MDL-71036' of https://github.com/stronk7/moodle 2021-03-17 20:05:25 +08:00
Eloy Lafuente (stronk7)
a148fd8602 MDL-71036 phpunit: xml config - deprecate whitelist from coverage
Following the changes in the schema, from "whitelists" to "includes",
we are deprecating these two properties from phpunit_coverage_info:

- whitelistfolders => includelistfolders
- whitelistfiles   => includelistfiles

They will continue working over the deprecation period but the init/util
scripts will throw some warnings about them being deprecated for 3.11 and
the way to replace them.

Standard 2y deprecation applies with final removed to happen @ MDL-71067
2021-03-11 23:04:31 +01:00
Eloy Lafuente (stronk7)
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
Eloy Lafuente (stronk7)
be30af0e23 MDL-71036 phpunit: Remove custom autoloader
Custom autoloaders are deprecated with PHPUnit 9 and will be removed
with PHPUnit 10.

Since PHPUnit 8.5 custom autoloaders don't do much because that
version removed the ability to launch unit tests by class name
and that's exactly the reason we had a custom autoloader (to map
class names to files within our tests). See MDL-67673 about
when direct use of classes was deprecated (8.5), now removed (9.5).

So, as far as it's unused, removing it now, test still can be
selectively using any of:

- a relative path to file (although there are some restrictions comming
  with PHPUnit 9, see https://github.com/sebastianbergmann/phpunit/issues/4105
- using --filter, to point to any classname[::method]
- using --testsuite to run a complete suite
- using --config to point to custom components.

Also, commented out the lib/ajax/tests directory because it doesn't
exist / is empty and PHPUnit 9 emits error when a configured test
directory does not exist. See
https://github.com/sebastianbergmann/phpunit/issues/4493.

Alternative was to completely remove the configuration line, but
decided to keep it around in case some day we want to add some
test there.
2021-03-11 19:22:24 +01:00
Eloy Lafuente (stronk7)
8a3663b175 MDL-71036 phpunit: XML load() method has been moved to new loader class
Used by our custom assertTag() and assertNotTag() assertions, that some
day we should deprecate... the loading of XML content for further
processing has been moved to new classes within the PHPUnit utils. We
are just following the move here.
2021-03-11 19:22:24 +01:00
Eloy Lafuente (stronk7)
5fcd5e1cf7 MDL-71036 phpunit: Stricter signature matching 2021-03-11 19:22:23 +01:00
Ferran Recio
1c839f9072 MDL-65974 course: move format_base to core_course\course_format 2021-03-11 17:36:34 +01:00
Marina Glancy
0eada7a5f9 MDL-70893 various: optional function arguments must be in the end 2021-02-15 16:53:37 +01:00
Eloy Lafuente (stronk7)
0dbeb9748b MDL-70010 core: reconcile MOODLE_310_STABLE and master
There are some unexpected differences between 310 and master,
better reconcile them now. Note this is not 100% critical but,
as far as nothing exclusively for 4.0 has landed to master yet
only branch/version differences should exist.
2020-10-26 10:48:53 +01:00
Eloy Lafuente (stronk7)
cc1c4de8dc MDL-67673 phpunit: Remove the rerun hint on failed test cases
That custom printer was using some hacks to be able to intercept
configuration switches, reflection and other tricks to be able to
print the:

To re-run:
 vendor/bin/phpunit --verbose "core_setuplib_testcase" lib/tests/setuplib_test.php

line on every failed/exceptional/skipped test. After some internal
discussion it was agreed that the normal phpunit output:

1) core_setuplib_testcase::test_localcachedir
Time is lower that allowed start value
Failed asserting that 1601976686 is equal to 1601976687 or is greater than 1601976687.

/var/www/html/lib/phpunit/classes/advanced_testcase.php:446
/var/www/html/lib/tests/setuplib_test.php:170
/var/www/html/lib/phpunit/classes/advanced_testcase.php:80

has already all the information at hand about how to rerun a test:

- vendor/bin/phpunit lib/tests/setuplib_test.php
- vendor/bin/phpunit --filter core_setuplib_testcase::test_localcachedir
- vendor/bin/phpunit --filter ::test_localcachedir
- vendor/bin/phpunit --testsuite componentname_testsuite
- vendor/bin/phpunit --config <<compoenent directory>>
- use --cache-result to get failed tests rerun with ease.
- ...

So better, let's use standard phpunit output and done. Also, note that,
with the upgrade to phpunit 8.5, the printer was not working correctly
any more, causing some switches, like --verbose ... to be ignored. Sure
it could have been fixed but, as commented above, no real need for all
that "parapheranlia" to print the rerun information.
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
447316a9f6 MDL-67673 phpunit: deprecate old phpunit/dbunit stuff
Apply the standard deprecation procedure to the old APIs, to
be removed in Moodle 4.2 (MDL-69882). Existing unit tests
cover the deprecation debugging.

Originally MDL-64600
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
8183def69e MDL-67673 phpunit: Move tests to use new phpunit_dataset
- Make advanced_testcase old methods to use new ones internally.
- Fix advanced_testcase, statslib, mod/quiz and mod/data tests.

Originally MDL-64600
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
ed103545dd MDL-67673 phpunit: Introduce a new, lightweight phpunit_dataset
In charge of taking over the, now removed/archived, phpunit/dbunit
package. It supports loading of CSV/XML files and strings and
PHP arrays, allowing to send the loaded information to database.

Perform some basic controls about the consistency of information,
surely not super-exhaustive but fair enough.

100% covered with unit test.

Planned like an "interim" replacement for phpunit/dbunit uses in
core that, ideally, should be moved to generators stuff at some
point.

Note, expect a few tests in core to fail with this commit, I've
changed some fixtures around. Next commit will fix existing uses.

Originally MDL-64600
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
80be8d2204 MDL-67673 phpunit: phpunit_constraint_object_is_equal_with_exceptions
Constraints are now declared final, so we cannot extend them anymore.

Hence, instead of extending PHPUnit\Framework\Constraint\IsEqual we
are just wrapping it into our constraint.
2020-10-21 12:45:59 +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
Dani Palou
703af2f91b MDL-68098 tests: Reset FILTERLIB_PRIVATE after tests 2020-09-23 11:18:41 +02:00
Brendan Heywood
f070dd126f MDL-67726 tool_phpunit: Removed webrunner tool 2020-02-07 08:08:48 +08:00
Eloy Lafuente (stronk7)
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
Andrew Nicols
fc1785b086 MDL-60978 testing: Support ability to run phpunit in isolated process 2019-06-21 14:36:13 +08:00
Jun Pataleta
6bcc5dfdb4 MDL-65204 phpunit: Fix valid CiBoT errors and warnings 2019-04-03 10:44:24 +08:00
Eloy Lafuente (stronk7)
032c75ec43 MDL-65204 phpunit: tweak constraint_object_is_equal_with_exceptions
In PHPUnit 7.x and above, IsEqual->value became private and, as far
as our with exceptions class inherits from it, we cannot access to
that anymore.

So, in order to avoid that, we are overriding the constructor, capturing
the original value for own use and forgetting.

A more formal, alternative, solution would be to make our
exceptional class to inherit from Constraint and make the
class a pure dispatcher to different constraints, with IsEqual being
just one of them.

But we followed the easiest path here. Not ideal, but efective.
2019-04-03 10:39:19 +08:00
Eloy Lafuente (stronk7)
26218b7852 MDL-65204 phpunit: make testcases match their expected signature 2019-04-03 10:39:19 +08:00
Andrew Nicols
0970aa10af MDL-63366 core_phpunit: Add ability to specify coverage filters 2019-03-01 10:30:31 +08:00
Marcus Boon
f33a614ec6 MDL-64599 phpunit: Fix typo in arraydataset 2019-01-18 07:07:25 +10: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
Jonathan Champ
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
Andrew Nicols
7bd269e82d MDL-62660 tool_dataprivacy: Add method for unit tests to run adhoc tasks 2018-08-20 15:31:20 +08:00
Adrian Greeve
5454e72c21 MDL-55188 events: First deprecation of eventslib.php 2018-07-30 09:23:54 +08:00
Michael Aherne
e99a39624e MDL-62577 unit tests: Quote class name in re-run command. 2018-05-25 16:46:45 +01:00
Mark Nelson
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
Eloy Lafuente (stronk7)
801a372dad MDL-60611 phpunit: switch to namespaced phunit classes 2017-11-02 23:45:34 +01:00
Tim Hunt
46a3753424 MDL-60139 phpunit: Make assertTag verify attribute values with ===
I had a test that cared about the difference between value="5.0" and value="5".
2017-10-30 12:52:00 +00:00
David Monllao
a272c25649 Merge branch 'MDL-60600_master' of https://github.com/marxjohnson/moodle 2017-10-26 18:33:49 +02:00
Mark Johnson
a9ca3fa167 MDL-60600 core_output: Clear static icon system cache between unit tests 2017-10-26 14:59:35 +01:00
David Monllao
3a89d0b541 MDL-60434 analytics: Analysables lazy loading 2017-10-25 14:16:35 +02:00
Eloy Lafuente (stronk7)
df4095ca6c Merge branch 'MDL-60342-master' of https://github.com/patkira/moodle 2017-10-19 23:23:49 +02:00
Pat Kira
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
Marina Glancy
78da366b56 MDL-60281 general: various strict corrections for PHP7.2
- count() can only be called on arrays or Countable, it can not be called on null
- recordset is neither so iterator_count() should be used
- instanceof or get_class() can not be applied to non-objects
- class methods must have the same arguments as methods in parent class
2017-10-16 09:37:20 +08:00