41 Commits

Author SHA1 Message Date
Andrew Nicols
7bb9f136d2
MDL-81520 core: Fix test finality 2024-12-11 12:30:21 +08:00
Andrew Nicols
024e36be17
MDL-81634 core: Fix all implicitly defined nullables
Note: This does not impact third-party libraries.
2024-08-02 14:11:12 +08:00
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)
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
Daniel Ziegenberg
08027e408c
MDL-81281 phpunit: assertObjectHasAttribute is deprecated
To be integrated as part of MDL-81266

When running PHPUnit 9.6 we get the following deprecation warnings:
"assertObjectHasAttribute() is deprecated and will be removed in PHPUnit
10. Refactor your test to use assertObjectHasProperty() instead."

So we replace all instances of assertObjectHasAttribute with
assertObjectHasProperty.

PHPUnit justifies the change with:
> PHPUnit currently refers to "fields" (see above) as "attributes". This
> is (or will become) confusing considering the introduction of
> attributes in PHP 8 and their support in PHPUnit.  PHPUnit will be
> changed to use the term "property" instead of "attribute" where "field"
> is meant.

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
2024-03-25 16:21:45 +01:00
Eloy Lafuente (stronk7)
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
Meirza
4937a1fd1c MDL-77350 favourites: Added class properties that are not declared
In PHP 8.2 and later, setting a value to an undeclared class property is
deprecated and emits a deprecation notice.
So we need to add missing class properties that still need to be declared.

// Removed test_add_malformed_favourite()
PHPUnit version >= 9.5 no longer converts PHP deprecations to exceptions by default.
To comply with PHP 8.2, which will deprecate the dynamic properties,
we need to remove test_add_malformed_favourite()
because the test will raise a warning for dynamic property deprecations.
2023-05-16 01:03:01 +07:00
Sara Arjona
1147a9fe9d MDL-72350 mod: Remove mod_assignment
The Assignment 2.2 activity module was disabled in 2012 but kept to
enable pre-2.2 backups to be restored and have the assignments
auto-converted to new assignments. After almost 10 years, it's time
to remove it from Moodle core.
2023-03-30 09:00:10 +08:00
Eloy Lafuente (stronk7)
9f53b0e965 MDL-73971 phpunit: Move more tests to use correct names and namespaces
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:

- Some fixtures, initially defined in the test files have been
  moved to new files in fixtures subdirectory, leaving the unit
  test files clearer:
  - moodle2_course_format_test.php
- Rename wrong named test:
  - baseoptiogroup_test = baseoptigroup_test
2022-05-06 18:29:11 +02:00
Eloy Lafuente (stronk7)
e4a2d9c1d4 MDL-73348 phpunit: normalize all privacy provider tests
As far as now all them have correct privacy level2 namespace:
- Move them to "privacy" subdir.
- Rename the files to "provider_test.php", this includes old
  privacy_test.php and privacy_provider_test.php files
- Rename the testcase to provider_test too (to match file name)

Also, change some relative paths and comments to point to new
locations.
2021-12-17 14:21:02 +01:00
Eloy Lafuente (stronk7)
57e6fb7ad9 MDL-73348 phpunit: privacy and privacy_provider testcase names
All privacy_test and privacy_provider_test classes:

- Namespaced with component\privacy.
- Fixed incorrect use statements with leading backslash.
- Changed code to point to global scope when needed.
- Renamed a few files to make all be privacy_test or privacy_provider_test.php
- All them passing individually.
- Complete runs passing too.
2021-12-17 14:21:02 +01:00
Eloy Lafuente (stronk7)
81407f18ec MDL-71036 phpunit: Mock->setMethods() silently deprecated
The current ->setMethods() has been silently (won't emit any
warning) in PHPUnit 9. And will stop working (current plans)
in PHPUnit 10.

Basically the now deprecated method has been split into:

- onlyMethods(): To point to existing methods in the mocked artifact.
- addMethods(): To point to non existing (yet) methods in the mocked
  artifact.

In practice that means that all our current setMethods() calls can be
converted to onlyMethods() (existing) and done. The addMethods() is
mostly useful on development phases, not final testing.

Finally note that <null> isn't accepted anymore as parameter to
double all the methods. Instead empty array [] must be used.

Link: https://github.com/sebastianbergmann/phpunit/issues/3770
2021-03-11 23:04:31 +01:00
Eloy Lafuente (stronk7)
3a5641cb74 MDL-67673 phpunit: Remove deprecated assertEquals() params
The optional parameters of assertEquals() and assertNotEquals()
are deprecated in PHPUnit 8 (to be removed in PHPUnit 9):

- delta => use assertEqualsWithDelta()
- canonicalize => use assertEqualsCanonicalizing()
- ignoreCase => use assertEqualsIgnoringCase
- maxDepth => removed without replacement.

More info @ https://github.com/sebastianbergmann/phpunit/issues/3341

Initial search done with:

ag 'assert(Not)?Equals\(.*,.*,' --php

Then, running tests and fixing remaining cases.
2020-10-21 12:46:00 +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
Peter
3d7d25afce MDL-68019 favourites: Unit test 2020-03-03 13:19:46 +08:00
Peter
b3b2d72c1e MDL-68019 course: Performance improvement with component favourites
Add the ability to get all/select itemtypes within a component
2020-02-28 11:28:15 +08:00
Eloy Lafuente (stronk7)
7899cd4f6c MDL-67353 favourites: Random DB id matching solved
Depending on the tests executed it was possible to arrive
to favourites tests with 2 "concepts" (say userid and contextid,
or userid and itemid) having the same ID.

Then, the array_diff() operations used by some mock stuff in the
tests wrongly was returning matches by value, ultimately causing
the test to fail.

Now, the matching is performed using array_diff_assoc() that takes
keys into considation when performing the match.
2020-01-24 11:26:56 +01:00
Jake Dallimore
35500af896 MDL-65323 core_favourites: replace use of deprecated phpunit methods 2019-09-13 10:21:06 +08:00
Jake Dallimore
a0523b826e MDL-65313 core_favourites: component scoped deletion now requires itemid
This now requires itemid, which cannot be null. This is safer. The
context can still be passed in as an optional parameter.
2019-05-07 16:26:46 +08:00
Jun Pataleta
14b132750b Merge branch 'MDL-65313-master' of https://github.com/snake/moodle 2019-05-07 16:24:37 +08:00
Jake Dallimore
f962859b56 MDL-65313 core_favourite: add component-scoped favourite service class
Added a new type of service which can be used to interact with the
all favourites for a given component, not just those owned by a a
specific user. As such, objects of this type are scoped to a component.
2019-05-06 14:01:34 +08:00
Amaia Anabitarte
888a467a78 MDL-64993 core_message: Adding self-conversations to unit tests 2019-05-06 00:47:52 +02:00
Jake Dallimore
92bea7db2a MDL-64057 core_favourites: add get_join_sql_by_type() to service layer
This provides a way for external queries to include information about
favourited items.
2018-11-23 11:02:18 +08:00
Andrew Nicols
08cd15658a Merge branch 'MDL-63692-master' of git://github.com/sarjona/moodle 2018-11-20 07:51:40 +08:00
Sara Arjona
16913e60b3 MDL-63692 core_message: Add favourite conversations to Privacy API 2018-11-19 22:09:13 +01:00
Andrew Nicols
18b947671b Merge branch 'MDL-63969-master-4' of git://github.com/mihailges/moodle 2018-11-19 12:27:37 +08:00
Mihail Geshoski
61fafe8127 MDL-63969 core_favourites: Add support for removal of context users 2018-11-16 12:18:22 +08:00
Ryan Wyllie
9e189a914d MDL-63303 core_favourites: add get and count functions 2018-11-15 14:40:11 +08:00
Jake Dallimore
b81722e22f MDL-63058 core_favourites: add existence checks to the service layer
This allows someone using the user_favourite_service to check whether
an item is already marked as a favourite.
2018-10-20 12:19:10 +02:00
Jake Dallimore
21b50ebe19 MDL-63658 core_favourites: fix errors discovered on oracle db
- Assuming 1 would be a record that didn't exist. should be using 0.
- Missing space before AND in sql in provider.
2018-10-18 17:11:07 +08:00
Jake Dallimore
68eaa3150e MDL-63658 core_favourites: properly define interface methods and cleanup
This gets rid of specific repo functions which were unused, and makes
sure the following methods are defined on the interface, implemented
and tested:
- exists_by($criteria)
- find_by($criteria)
- delete_by($crtieria)
Also, added missing tests for find_favourite() repo method.
2018-10-18 15:39:57 +08:00
Jake Dallimore
8d9cd27b02 MDL-63658 core_favourites: let service object use get_component_names
This was using a helper, but now we have the function in core to achieve
the same thing, so use this instead.
2018-10-18 08:22:08 +08:00
Jake Dallimore
b7a3ec6f8d MDL-63658 core_favourites: consolidate interfaces and rename
Let's worry about reuse of the crud code later, when that requirement
arises, so moved that into the ifavourite_repository interface, and then
renamed it favourite_repository_interface.
2018-10-18 08:22:07 +08:00
Jake Dallimore
0551ed3569 MDL-63658 core_favourites: rename user_favourites_service and services
Now: user_favourite_service (singular) and service_factory
2018-10-18 08:22:07 +08:00
Jake Dallimore
cb90b549b6 MDL-63658 core_favourites: singularise the repository class types
Instead of favourites_repository we now have favourite_repository,
which is more in line with other implementations of this pattern.
2018-10-18 08:22:07 +08:00
Jake Dallimore
cfaf86b059 MDL-63658 core_favourites: make favourite a first class object
This patch adds several things:
- favourite entity class under local/entity
- refactoring of repository and service to use the new class instead
of stdClass.
- update repository unit tests to use the object instead of stdClass.
- update service_test so that the mock repo requires the object for
the add operation.
- remove unnecessary constructor from favourites_repository class.
2018-10-18 08:22:07 +08:00
Jake Dallimore
8ffbe9c163 MDL-63658 core_favourites: adding paging support to the service layer 2018-10-18 08:22:07 +08:00
Jake Dallimore
ac9138db1c MDL-63658 core_favourites: implement privacy API for favourites 2018-10-18 08:22:06 +08:00
Jake Dallimore
4a02aae5f5 MDL-63658 core_favourites: namespace the repositories and services 2018-10-18 08:22:06 +08:00
Jake Dallimore
771051325b MDL-63658 core_favourites: add business logic aware service layer 2018-10-18 08:22:06 +08:00
Jake Dallimore
d4e98ee580 MDL-63658 core_favourites: add a user favourites repository 2018-10-18 08:22:06 +08:00