Skip to content

Commit

Permalink
MDL-74413 phpunit: Move more tests to use correct names and namespaces
Browse files Browse the repository at this point in the history
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:

- Moved to the level2 "privacy" namespace:
  - \mod_assign\privacy\feedback_legacy_polyfill_test
  - \mod_assign\privacy\submission_legacy_polyfill_test

- Moved to the level2 "task" namespace:
  - \core_message\task\migrate_message_data_test
  - \ltiservice_gradebookservices\task\cleanup_test
  - \message_email\task\send_email_test
  - \mod_lti\task\clean_access_tokens_test
  - \mod_workshop\task\cron_task_test

- Moved to the level2 "event" namespace:
  - \core_h5p\event\deleted_test
  - \core_h5p\event\viewed_test

- Renamed to a better name:
  - backup_forum_activity_task_test.php (missing "task")
  • Loading branch information
stronk7 committed May 7, 2022
1 parent 941a299 commit caf55ab
Show file tree
Hide file tree
Showing 106 changed files with 1,067 additions and 1,493 deletions.
20 changes: 10 additions & 10 deletions filter/mathjaxloader/tests/filtermath_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides the {@link filter_mathjaxloader_filtermath_testcase} class.
*
* @package filter_mathjaxloader
* @category test
* @copyright 2018 Markku Riekkinen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace filter_mathjaxloader;

use filter_mathjaxloader;

defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/filter/mathjaxloader/filter.php');

/**
* Unit tests for the MathJax loader filter.
*
* @package filter_mathjaxloader
* @category test
* @copyright 2018 Markku Riekkinen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_mathjaxloader_filtermath_testcase extends advanced_testcase {
class filtermath_test extends \advanced_testcase {

/**
* Test the functionality of {@link filter_mathjaxloader::filter()}.
Expand All @@ -41,7 +41,7 @@ class filter_mathjaxloader_filtermath_testcase extends advanced_testcase {
* @dataProvider test_math_filtering_inputs
*/
public function test_math_filtering($inputtext, $expected) {
$filter = new filter_mathjaxloader(context_system::instance(), []);
$filter = new filter_mathjaxloader(\context_system::instance(), []);
$this->assertEquals($expected, $filter->filter($inputtext));
}

Expand Down
13 changes: 4 additions & 9 deletions grade/grading/form/guide/tests/guide_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Unit tests for Marking Guide grading method.
*
* @package gradingform_guide
* @category test
* @copyright 2015 Nikita Kalinin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradingform_guide;

use gradingform_controller;

defined('MOODLE_INTERNAL') || die();

Expand All @@ -37,7 +32,7 @@
* @copyright 2015 Nikita Kalinin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class gradingform_guide_testcase extends advanced_testcase {
class guide_test extends \advanced_testcase {
/**
* Unit test to get draft instance and create new instance.
*/
Expand Down
42 changes: 12 additions & 30 deletions grade/grading/tests/grading_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Unit tests for the advanced grading subsystem
*
* @package core_grading
* @category phpunit
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_grading;

use grading_manager;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/grade/grading/lib.php'); // Include the code to test


/**
* Makes protected method accessible for testing purposes
*
* @package core_grading
* @category phpunit
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_grading_manager extends grading_manager {
}


/**
* Test cases for the grading manager API
*
* @package core_grading
* @category phpunit
* @category test
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_grade_grading_manager_testcase extends advanced_testcase {
class grading_manager_test extends \advanced_testcase {
public function test_basic_instantiation() {
$manager1 = get_grading_manager();

Expand Down Expand Up @@ -103,7 +85,7 @@ public function test_set_and_get_grading_area() {
$this->assertEquals('rubric', $gradingman->get_active_method());

// attempting to set an invalid method
$this->expectException(moodle_exception::class);
$this->expectException(\moodle_exception::class);
$gradingman->set_active_method('no_one_should_ever_try_to_implement_a_method_with_this_silly_name');
}

Expand All @@ -115,27 +97,27 @@ public function test_tokenize() {
$UTFfailuremessage = 'A test using UTF-8 characters has failed. Consider updating PHP and PHP\'s PCRE or INTL extensions (MDL-30494)';

$needle = " šašek, \n\n \r a král; \t";
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(2, count($tokens), $UTFfailuremessage);
$this->assertTrue(in_array('šašek', $tokens), $UTFfailuremessage);
$this->assertTrue(in_array('král', $tokens), $UTFfailuremessage);

$needle = ' " šašek a král " ';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(1, count($tokens));
$this->assertTrue(in_array('šašek a král', $tokens));

$needle = '""';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertTrue(empty($tokens));

$needle = '"0"';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(1, count($tokens));
$this->assertTrue(in_array('0', $tokens));

$needle = '<span>Aha</span>, then who\'s a bad guy here he?';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertEquals(8, count($tokens));
$this->assertTrue(in_array('span', $tokens)); // Extracted the tag name
$this->assertTrue(in_array('Aha', $tokens));
Expand All @@ -144,7 +126,7 @@ public function test_tokenize() {
$this->assertTrue(in_array('he', $tokens)); // Removed the trailing ?
$needle = 'grammar, "english language"';
$tokens = testable_grading_manager::tokenize($needle);
$tokens = grading_manager::tokenize($needle);
$this->assertTrue(in_array('grammar', $tokens));
$this->assertTrue(in_array('english', $tokens));
$this->assertTrue(in_array('language', $tokens));
Expand Down
Loading

0 comments on commit caf55ab

Please sign in to comment.