Skip to content

Commit

Permalink
MDL-82431 phpunit: correct unit test filename and classname.
Browse files Browse the repository at this point in the history
Standardise the same test cases, e.g. make final, covers notation,
static data providers, namespaces, etc.

Once the tests run, a couple of them failed. They required changes
to assertions to make them pass.
  • Loading branch information
paulholden committed Jul 10, 2024
1 parent 7d7a871 commit 8413f61
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 14,29 @@
// 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 activities completed by classification.
*
* @package core_analytics
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_analytics;

defined('MOODLE_INTERNAL') || die();
use advanced_testcase;
use ReflectionClass;
use ReflectionMethod;
use stdClass;

/**
* Unit tests for activities completed by classification.
*
* @package core_analytics
* @covers \core_analytics\local\indicator\community_of_inquiry_activity
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class community_of_inquiry_activities_completed_by_testcase extends advanced_testcase {
final class community_of_inquiry_activities_completed_by_test extends advanced_testcase {

/**
* availability_levels
*
* @return array
*/
public function availability_levels() {
public static function availability_levels(): array {
return array(
'activity' => array('activity'),
'section' => array('section'),
Expand Down Expand Up @@ -147,7 145,7 @@ public function test_get_activities_with_weeks() {
$second = $startdate WEEKSECS;
$third = $startdate (WEEKSECS * 2);
$forth = $startdate (WEEKSECS * 3);
$this->assertCount(1, $method->invoke($indicator, $first, $first WEEKSECS, $stu1));
$this->assertCount(2, $method->invoke($indicator, $first, $first WEEKSECS, $stu1));
$this->assertCount(1, $method->invoke($indicator, $second, $second WEEKSECS, $stu1));
$this->assertCount(0, $method->invoke($indicator, $third, $third WEEKSECS, $stu1));
$this->assertCount(2, $method->invoke($indicator, $forth, $forth WEEKSECS, $stu1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 14,27 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace core\event;

use advanced_testcase;
use context_course;
use context_system;
use Exception;
use moodle_url;

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../fixtures/event_mod_fixtures.php');

/**
* Tests for base course module instance list viewed event.
*
* @package core
* @category phpunit
* @covers \core\event\course_module_instance_list_viewed
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/event_mod_fixtures.php');

/**
* Class core_event_course_module_instance_list_viewed_testcase
*
* Tests for event \core\event\course_module_instance_list_viewed_testcase
*/
class core_event_course_module_instance_list_viewed_testcase extends advanced_testcase {
final class course_module_instance_list_viewed_test extends advanced_testcase {

/**
* Test event properties and methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 14,27 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace core\event;

use advanced_testcase;
use coding_exception;
use context_module;
use stdClass;
use moodle_url;

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/../fixtures/event_fixtures.php');

/**
* Tests for base course module viewed event.
*
* @package core
* @category phpunit
* @covers \core\event\course_module_viewed
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/event_fixtures.php');

/**
* Class core_event_course_module_viewed_testcase
*
* Tests for event \core\event\course_module_viewed
*/
class core_event_course_module_viewed_testcase extends advanced_testcase {
final class course_module_viewed_test extends advanced_testcase {

/**
* Test event properties and methods.
Expand Down Expand Up @@ -80,6 83,9 @@ public function test_event_validations() {
$this->assertStringContainsString("course_module_viewed event must define objectid and object table.", $e->getMessage());
}

$this->assertDebuggingCalled('Inconsistent courseid - context combination detected.');
$this->resetDebugging();

try {
\core_tests\event\course_module_viewed::create(array(
'contextid' => 1,
Expand All @@ -88,5 94,7 @@ public function test_event_validations() {
} catch (coding_exception $e) {
$this->assertStringContainsString("course_module_viewed event must define objectid and object table.", $e->getMessage());
}

$this->assertDebuggingCalled('Inconsistent courseid - context combination detected.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* External function test for delete_entry.
*
* @package mod_glossary
* @category external
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_glossary\external;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -38,10 28,13 @@
* External function test for delete_entry.
*
* @package mod_glossary
* @category external
* @covers \mod_glossary\external\delete_entry
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_entry_testcase extends externallib_advanced_testcase {
final class delete_entry_test extends externallib_advanced_testcase {

/**
* Test the behaviour of delete_entry().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* External function test for prepare_entry.
*
* @package mod_glossary
* @category external
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_glossary\external;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -38,10 28,13 @@
* External function test for prepare_entry.
*
* @package mod_glossary
* @category external
* @covers \mod_glossary\external\prepare_entry
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class prepare_entry_testcase extends externallib_advanced_testcase {
final class prepare_entry_test extends externallib_advanced_testcase {

/**
* test_prepare_entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* External function test for update_entry.
*
* @package mod_glossary
* @category external
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_glossary\external;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -42,10 32,13 @@
* External function test for update_entry.
*
* @package mod_glossary
* @category external
* @covers \mod_glossary\external\update_entry
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class update_entry_testcase extends externallib_advanced_testcase {
final class update_entry_test extends externallib_advanced_testcase {

/**
* test_update_entry_without_optional_settings
Expand Down Expand Up @@ -152,7 145,7 @@ public function test_update_entry_with_aliases() {
$aliases = $DB->get_records('glossary_alias', ['entryid' => $entryid]);
$this->assertCount(2, $aliases);
foreach ($aliases as $alias) {
$this->assertContains($alias->alias, $newaliases);
$this->assertStringContainsString($alias->alias, $newaliases);
}
}

Expand Down Expand Up @@ -193,7 186,7 @@ public function test_update_entry_in_categories() {
$categories = $DB->get_records('glossary_entries_categories', ['entryid' => $entryid]);
$this->assertCount(2, $categories);
foreach ($categories as $category) {
$this->assertContains($category->categoryid, $newcategories);
$this->assertStringContainsString($category->categoryid, $newcategories);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* External function test for log_report_viewed.
*
* @package mod_h5pactivity
* @category external
* @since Moodle 3.11
* @copyright 2021 Ilya Tregubov <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_h5pactivity\external;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -39,10 29,14 @@
* External function test for log_report_viewed.
*
* @package mod_h5pactivity
* @category external
* @covers \mod_h5pactivity\external\log_report_viewed
* @since Moodle 3.11
* @copyright 2021 Ilya Tregubov <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class log_report_viewed_testcase extends externallib_advanced_testcase {
final class log_report_viewed_test extends externallib_advanced_testcase {

/**
* Test the behaviour of log_report_viewed.
*
Expand Down Expand Up @@ -110,7 104,7 @@ public function test_execute(int $enabletracking, int $reviewmode, string $login
*
* @return array
*/
public function execute_data(): array {
public static function execute_data(): array {
return [
'Student reviewing own attempt' => [
1, manager::REVIEWCOMPLETION, 'student', 'student'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 14,23 @@
// 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 a the collection of userlists class
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

global $CFG;
namespace core_privacy;

use advanced_testcase;
use \core_privacy\local\request\userlist_collection;
use \core_privacy\local\request\userlist;
use \core_privacy\local\request\approved_userlist;

/**
* Tests for the \core_privacy API's userlist collection functionality.
*
* @package core_privacy
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\request\userlist_collection
*/
class userlist_collection_test extends advanced_testcase {
final class userlist_collection_test extends advanced_testcase {

/**
* A userlist_collection should support the userlist type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 14,21 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Tests for the progress report sorting.
*
* @package report_progress
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace report_progress;

defined('MOODLE_INTERNAL') || die();
use advanced_testcase;
use completion_info;
use testing_data_generator;

/**
* Class for testing report progress helper.
*
* @package report_progress
* @covers \report_progress\local\helper
* @copyright 2021 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class report_progress_helper_testcase extends advanced_testcase {
final class report_progress_helper_test extends advanced_testcase {

/** @var testing_data_generator data generator.*/
protected $generator;
Expand Down

0 comments on commit 8413f61

Please sign in to comment.