30 Commits

Author SHA1 Message Date
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
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
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
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
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