50 Commits

Author SHA1 Message Date
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)
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)
40de097e65 MDL-67673 phpunit: Remove deprecated assertContains() uses on strings
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: https://github.com/sebastianbergmann/phpunit/issues/3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
f94195c320 MDL-67673 phpunit: Remove deprecated assertInternalType()
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.

From release notes:https://phpunit.de/announcements/phpunit-8.html

assertInternalType() is deprecated and will be removed in
PHPUnit 9. Refactor your test to use assertIsArray(), assertIsBool(),
assertIsFloat(), assertIsInt(), assertIsNumeric(), assertIsObject(),
assertIsResource(), assertIsString(), assertIsScalar(),
assertIsCallable(), or assertIsIterable() instead.
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
David Mudrák
469d4b7f35 MDL-67250 setup: Revert removal of the httpswwwroot setting
It is still used widely in the plugins that would stop working suddenly
without being warned via a debugging message. We must keep it forever as
an alias for the wwwroot.
2019-11-13 19:58:10 +01:00
Jun Pataleta
9320787005 MDL-46267 core: Remove $CFG->httpswwwroot
* It's unnecessary since $CFG->loginhttps has already been removed and
  it's no longer being used in core anymore.
2019-07-22 10:59:42 +08:00
Andrew Nicols
fc1785b086 MDL-60978 testing: Support ability to run phpunit in isolated process 2019-06-21 14:36:13 +08:00
David Mudrák
39d2c68856 MDL-61742 messaging: Do not send messages from inactive providers
Before this patch, we only checked that the given provider has been
configured in the user or system preferences. However, if the provider's
component is disabled, it does not even appear in these preferences.
Additionally, there was no check that the message / notification
provider is among providers allowed to be consumed by the recipient.

The patch checks that the message origin is among providers returned by
the message_get_providers_for_user() so disabled plugins can't act as
sources of messages and users can't receive messages from providers they
do not have capability for. This mitigates the risk of abusing a plugin
as a source of spam, for example.

Unit test is fixed and extended. When the $CFG->messaging is disabled,
no messages between users should be sent (I can't understand why the
unit test was written in an opposite way). Added assertions for the
raised debugging message.
2018-08-31 12:15:30 +02:00
Eloy Lafuente (stronk7)
801a372dad MDL-60611 phpunit: switch to namespaced phunit classes 2017-11-02 23:45:34 +01:00
John Okely
672f483670 MDL-42834 admin: Removal of httpswwwroot 2017-10-23 12:25:36 +08: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
Amanda Doughty
cc350fd9c8 MDL-47162 core_message: Add course id to message eventdata 2016-10-27 18:11:27 +02:00
Russell Smith
ef15173794 MDL-56354 unittests: Put debug messages in the failure notice. 2016-10-26 08:39:10 +11:00
Russell Smith
74ee9d29d2 MDL-55944 testing: Reduce sleep usage.
Remove sleep() and replace with waiting for a second to roll over,
this results in a simpler call the guarantee time() has moved forward
2016-09-14 09:49:30 +10:00
Rajesh Taneja
52f3e060e4
MDL-55091 phpunit: Following has been deprecated.
1. getMock()
2. setExpectedException()
3. checkForUnintentionallyCoveredCode renamed to beStrictAboutCoversAnnotation
4. beStrictAboutTestSize renamed to enforceTimeLimit
5. UnitTestCase class is now fully removed.
2016-07-26 10:11:30 +08:00
Rajesh Taneja
faea241337 MDL-52656 unittest: Reset original session while setting user 2016-01-08 09:41:28 +10:00
Andrew Nicols
46c18e0dd2 MDL-52060 phpunit: Add tests for test_set_table_modified_by_sql 2015-12-23 09:08:06 +08:00
rajesh Taneja
5ecf8e8f21 MDL-51266 unittest: replaced low level phpunit_util calls 2015-09-23 15:42:48 +08:00
Petr Skoda
d6e7a63d9a MDL-49684 timezones: rewrite timezone support
This patch replaces all homegrown timezone
stuff with standard PHP date/time code.

The main change is the introduction of core_date
class that returns normalised user and server
timezones. From now on nobody should be using
$CFG->timezone or $user->timezone directly!

Other new features and fixes:
* admins are prompted for timezone during install
* editing of other users is finally fixed
* timezones are displayed in user profile
* new $this->setTimezone() in phpunit
* time locale is now automatically reset in phpunit
* timezone is now automatically reset in phpunit
* phpunit has Australia/Perth as default timezone
2015-04-06 13:53:51 +12:00
Andrew Nicols
fc05c1b8e5 MDL-48197 testing: Normalise uses of noemailever and phpmailer sink 2014-11-19 09:09:50 +08:00
Petr Skoda
2e00d01db4 MDL-46099 session: fix use of references for session globals
This reverses the references used for global $USER and $SESSION,
the reason is that PHP does not allow references to references.
$USER is a reference to $GLOBALS['USER'] which means we cannot
put any references to it. Solution is to store the current user and session
objects in $GLOBALS['USER'] and $GLOBALS['SESSIOn'] are reference
them in $_SESSION.

This patch makes the session code behave the same way in CLI,
phpunit and normal web requests - this allows use to finally
unit test most aspects of the session code in Moodle.
2014-07-01 08:38:00 +12:00
Russell Smith
d2c58b95bb MDL-43835 phpunit: Correct unit tests.
When different ID's are set for each sequence a number
of unit test failures appear.  They have been corrected
to allow unit tests to pass with the new generator in place.
2014-06-17 19:08:01 +10:00
Juan Leyva
5e12b369af MDL-44954 messages: Fixed save notifications with the notification flag 2014-04-07 12:19:52 +02:00
Petr Škoda
2a67e105b6 MDL-41935 attempt to work around random time comparison test failures 2013-10-12 15:53:25 +02:00
Sam Hemelryk
52dc898d16 Merge branch 'MDL-41228_master' of https://github.com/totara/openbadges 2013-10-01 13:37:44 +13:00
Petr Škoda
d79d5ac276 MDL-31501 rework user session architecture
List of changes:
 * New OOP API using PHP namespace \core\session\.
 * All handlers now update the sessions table consistently.
 * Experimental DB session support in Oracle.
 * Full support for session file handler (filesystem locking required).
 * New option for alternative session directory.
 * Official memcached session handler support.
 * Workaround for memcached version with non-functional gc.
 * Improved security - forced session id regeneration.
 * Improved compatibility with recent PHP releases.
 * Fixed borked CSS during install in debug mode.
 * Switched to file based sessions in new installs.
 * DB session setting disappears if DB does not support sessions.
 * DB session setting disappears if session handler specified in config.php.
 * Fast purging of sessions used in request only.
 * No legacy distinction -  file, database and memcached support the same functionality.
 * Session handler name included in performance info.
 * Fixed user_loggedin and user_loggedout event triggering.
 * Other minor bugfixing and improvements.
 * Fixed database session segfault if MUC disposed before $DB.

Limitations:
 * Session access time is now updated right after session start.
 * Support for $CFG->sessionlockloggedinonly was removed.
 * First request does not update userid in sessions table.
 * The timeouts may break badly if server hosting forces PHP.ini session settings.
 * The session GC is a lot slower, we do not rely on external session timeouts.
 * There cannot be any hooks triggered at the session write time.
 * File and memcached handlers do not support session lock acquire timeouts.
 * Some low level PHP session functions can not be used directly in Moodle code.
2013-09-21 13:11:56 +02:00
Yuliya Bozhko
ed23ad31c7 MDL-41228 phpunit: Reset message processors list in unit tests 2013-09-03 17:43:53 +12:00
Petr Škoda
f52f2c9597 MDL-41022 cleanup core_phpunit_basic_testcase 2013-08-24 16:18:19 +02:00
Petr Škoda
3405d82c91 MDL-41022 cleanup core_phpunit_advanced_testcase 2013-08-24 16:18:19 +02:00
Petr Škoda
96f81ea385 MDL-39474 introduce $CFG->debugdeveloper and cleanup $CFG init 2013-08-12 13:01:47 +02:00
Jamie Pratt
596ea56f6b MDL-40388 Reset globals after each unit test 2013-07-09 12:26:28 +08:00
Petr Škoda
774d1d2429 MDL-37780 make sure there are no windows line endings in test files 2013-01-30 21:23:29 +01:00
Eloy Lafuente (stronk7)
fa669c49ad Merge branch 'w03_MDL-36411_m25_setup' of git://github.com/skodak/moodle 2013-01-21 20:08:12 +01:00
Petr Škoda
6a8e467916 MDL-36411 make sure asserts in setUp() do not cause problems 2013-01-19 13:19:49 +01:00
David Monllao
5c3c2c81be MDL-37457 testing Refactoring references 2013-01-15 11:07:43 +08:00
Dan Poltawski
1b01909597 Merge branch 'w47_MDL-36547_m24_sectiongen' of git://github.com/skodak/moodle 2012-11-21 15:26:15 +08:00
Petr Škoda
4f5789eae8 MDL-36703 very basic support for enrolments in data generator 2012-11-19 23:15:29 +01:00
Petr Škoda
b4126b0c8b MDL-36547 add test for section number when generating modules 2012-11-17 09:05:29 +01:00
Dan Poltawski
348be850c9 Merge branch 'w42_MDL-35854_m24_usergenerator' of git://github.com/skodak/moodle 2012-10-15 16:03:53 +08:00
Petr Škoda
4c9e03f0ac MDL-36031 implement message redirection for unit testing 2012-10-13 20:00:54 +02:00
Petr Škoda
fe67134eaa MDL-35854 fix username generator
This eliminates infinite loop and also fixes potentially invalid email derived from usernames created from unicode first/last name.
2012-10-13 09:57:35 +02:00
Eloy Lafuente (stronk7)
5ceded2869 Merge branch 'w38_MDL-35465_m24_cohortscleanup' of git://github.com/skodak/moodle 2012-09-18 16:55:42 +02:00
Petr Škoda
ef5b5e051e MDL-35479 debugging support in our phpunit integration 2012-09-17 11:27:57 +02:00
Petr Škoda
4729332b15 MDL-35465 add basic cohort lib tests and generator 2012-09-16 20:23:19 +02:00
Petr Škoda
4a38e65977 MDL-34912 fix invalid descriptionformat default handling 2012-08-18 09:52:31 +02:00
Petr Skoda
d59ef9c5ab MDL-32926 exorcise setUser(2) evil from phpunit 2012-05-12 21:42:07 +02:00
Petr Skoda
08ad325702 MDL-32960 put phpunit integration tests to one test suite and execute them first 2012-05-12 21:33:23 +02:00