Skip to content

Commit

Permalink
MDL-73476 phpunit: events, external and search tescase names
Browse files Browse the repository at this point in the history
All events_test, external_test and search_test classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- 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 lib/external/tests/external_test.php:
- external is not a valid component
- hence, its only valid namespace is "core"
- also, it's testing lib/external/externallib.php
- hence, the file (and class) have been renamed to external_externallib_test.php
  (to avoid conflicts with other external_test that may exist in core)
  • Loading branch information
stronk7 committed Jan 14, 2022
1 parent 0e18847 commit 0c53a3d
Show file tree
Hide file tree
Showing 74 changed files with 1,999 additions and 1,848 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
* @since Moodle 3.8
*/

namespace tool_analytics\external;

use externallib_advanced_testcase;

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

global $CFG;

require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once(__DIR__ . '/../../../../analytics/tests/fixtures/test_indicator_max.php');
require_once(__DIR__ . '/../../../../analytics/tests/fixtures/test_target_course_level_shortname.php');
require_once($CFG->dirroot . '/analytics/tests/fixtures/test_indicator_max.php');
require_once($CFG->dirroot . '/analytics/tests/fixtures/test_target_course_level_shortname.php');

/**
* Tool analytics external functions tests
Expand All @@ -41,7 +45,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.8
*/
class tool_analytics_external_testcase extends externallib_advanced_testcase {
class external_test extends externallib_advanced_testcase {

/**
* test_potential_contexts description
Expand Down Expand Up @@ -73,7 +77,7 @@ public function test_potential_contexts_no_manager() {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);

$this->expectException(required_capability_exception::class);
$this->expectException(\required_capability_exception::class);
$this->assertCount(2, \tool_analytics\external::potential_contexts());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/

defined('MOODLE_INTERNAL') || die();
namespace tool_capability\event;

/**
* Class for capability overview events.
Expand All @@ -31,7 +31,7 @@
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class tool_capability_events_testcase extends advanced_testcase {
class events_test extends \advanced_testcase {

/**
* Setup testcase.
Expand All @@ -54,11 +54,11 @@ public function test_report_viewed() {
$event = reset($events);

$this->assertInstanceOf('\tool_capability\event\report_viewed', $event);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertEquals(\context_system::instance(), $event->get_context());
$expected = array(SITEID, "admin", "tool capability", "tool/capability/index.php");
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
$url = new moodle_url('/admin/tool/capability/index.php');
$url = new \moodle_url('/admin/tool/capability/index.php');
$this->assertEquals($url, $event->get_url());
$event->get_name();
}
Expand Down
Loading

0 comments on commit 0c53a3d

Please sign in to comment.