mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-78167 lib: Added missing class properties in tests
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. Adding @runTestsInSeparateProcesses and removing setUp() and tearDown() at the component_test.php, so the test will run in a separate process making sure that whatever changes happen to the in-memory version of the component class in its thread, therefore does not impact other tests and makes it more safe.
This commit is contained in:
parent
4ed782dd03
commit
b7008d33ea
7 changed files with 39 additions and 32 deletions
|
@ -77,6 +77,12 @@ abstract class base {
|
|||
/** @var int Move a plugin down in the plugin order */
|
||||
public const MOVE_DOWN = 1;
|
||||
|
||||
/** @var array hold $plugin->supported in version.php */
|
||||
public $supported;
|
||||
|
||||
/** @var int hold $plugin->incompatible in version.php */
|
||||
public $incompatible;
|
||||
|
||||
/**
|
||||
* Whether this plugintype supports its plugins being disabled.
|
||||
*
|
||||
|
|
|
@ -142,7 +142,7 @@ EOF;
|
|||
}
|
||||
|
||||
if ($results->exception !== null) {
|
||||
throw new ExpectationException($results->exception, $this->session);
|
||||
throw new ExpectationException($results->exception, $this->getSession());
|
||||
}
|
||||
|
||||
$violations = $results->violations;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @covers \core_component
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class component_test extends advanced_testcase {
|
||||
|
||||
|
@ -33,25 +34,6 @@ class component_test extends advanced_testcase {
|
|||
*/
|
||||
const SUBSYSTEMCOUNT = 77;
|
||||
|
||||
public function setUp(): void {
|
||||
$psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces');
|
||||
$psr0namespaces->setAccessible(true);
|
||||
$this->oldpsr0namespaces = $psr0namespaces->getValue(null);
|
||||
|
||||
$psr4namespaces = new ReflectionProperty('core_component', 'psr4namespaces');
|
||||
$psr4namespaces->setAccessible(true);
|
||||
$this->oldpsr4namespaces = $psr4namespaces->getValue(null);
|
||||
}
|
||||
public function tearDown(): void {
|
||||
$psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces');
|
||||
$psr0namespaces->setAccessible(true);
|
||||
$psr0namespaces->setValue(null, $this->oldpsr0namespaces);
|
||||
|
||||
$psr4namespaces = new ReflectionProperty('core_component', 'psr4namespaces');
|
||||
$psr4namespaces->setAccessible(true);
|
||||
$psr4namespaces->setValue(null, $this->oldpsr4namespaces);
|
||||
}
|
||||
|
||||
public function test_get_core_subsystems() {
|
||||
global $CFG;
|
||||
|
||||
|
|
7
lib/tests/fixtures/test_renderer_factory.php
vendored
7
lib/tests/fixtures/test_renderer_factory.php
vendored
|
@ -43,7 +43,7 @@ class test_output_factory extends renderer_factory_base {
|
|||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->prefixes = array('theme_child', 'theme_parent');
|
||||
// Leave the construct empty to override the parent.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,6 +93,7 @@ class test_output_factory extends renderer_factory_base {
|
|||
* @return string[] of classnames
|
||||
*/
|
||||
public function get_theme_overridden_renderer_factory_search_paths($component, $subtype = null, $target = null) {
|
||||
$themeprefixes = ['theme_child', 'theme_parent'];
|
||||
$searchtargets = array();
|
||||
$classnames = $this->standard_renderer_classnames($component, $subtype);
|
||||
|
||||
|
@ -102,7 +103,7 @@ class test_output_factory extends renderer_factory_base {
|
|||
// when loading the theme configs.
|
||||
|
||||
// First try the renderers with correct suffix.
|
||||
foreach ($this->prefixes as $prefix) {
|
||||
foreach ($themeprefixes as $prefix) {
|
||||
foreach ($classnames as $classnamedetails) {
|
||||
if ($classnamedetails['validwithprefix']) {
|
||||
if ($classnamedetails['autoloaded']) {
|
||||
|
@ -122,7 +123,7 @@ class test_output_factory extends renderer_factory_base {
|
|||
}
|
||||
|
||||
// Then try general renderer.
|
||||
foreach ($this->prefixes as $prefix) {
|
||||
foreach ($themeprefixes as $prefix) {
|
||||
foreach ($classnames as $classnamedetails) {
|
||||
if ($classnamedetails['validwithprefix']) {
|
||||
if ($classnamedetails['autoloaded']) {
|
||||
|
|
|
@ -44,14 +44,12 @@ class myprofilelib_test extends \advanced_testcase {
|
|||
* @var \core_user\output\myprofile\tree The navigation tree.
|
||||
*/
|
||||
private $tree;
|
||||
|
||||
public function setUp(): void {
|
||||
// Set the $PAGE->url value so core_myprofile_navigation() doesn't complain.
|
||||
global $PAGE;
|
||||
$PAGE->set_url('/test');
|
||||
|
||||
$this->user = $this->getDataGenerator()->create_user();
|
||||
$this->user2 = $this->getDataGenerator()->create_user();
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->tree = new \core_user\output\myprofile\tree();
|
||||
$this->resetAfterTest();
|
||||
|
@ -87,7 +85,8 @@ class myprofilelib_test extends \advanced_testcase {
|
|||
* profile of another another user.
|
||||
*/
|
||||
public function test_core_myprofile_navigation_course_without_permission() {
|
||||
$this->setUser($this->user2);
|
||||
// User without permission.
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
$iscurrentuser = false;
|
||||
|
||||
core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
|
||||
|
@ -146,7 +145,7 @@ class myprofilelib_test extends \advanced_testcase {
|
|||
*/
|
||||
public function test_core_myprofile_navigation_preference_without_permission() {
|
||||
// Login as link for a user who doesn't have the capability to login as.
|
||||
$this->setUser($this->user2);
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
$iscurrentuser = false;
|
||||
|
||||
core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
|
||||
|
@ -211,7 +210,7 @@ class myprofilelib_test extends \advanced_testcase {
|
|||
$identityfields = explode(',', $CFG->showuseridentity);
|
||||
|
||||
// User without permission.
|
||||
$this->setUser($this->user2);
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null);
|
||||
$reflector = new \ReflectionObject($this->tree);
|
||||
$nodes = $reflector->getProperty('nodes');
|
||||
|
@ -300,7 +299,7 @@ class myprofilelib_test extends \advanced_testcase {
|
|||
public function test_core_myprofile_navigationn_login_activity_without_permission() {
|
||||
// User without permission.
|
||||
set_config("hiddenuserfields", "firstaccess,lastaccess,lastip");
|
||||
$this->setUser($this->user2);
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
$iscurrentuser = false;
|
||||
|
||||
core_myprofile_navigation($this->tree, $this->user, $iscurrentuser, null);
|
||||
|
|
|
@ -711,7 +711,6 @@ class exposed_global_navigation extends global_navigation {
|
|||
$page = $PAGE;
|
||||
}
|
||||
parent::__construct($page);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method, $this->exposedkey) !== false) {
|
||||
|
@ -763,9 +762,9 @@ class mock_initialise_global_navigation extends global_navigation {
|
|||
*/
|
||||
class exposed_navbar extends navbar {
|
||||
protected $exposedkey = 'exposed_';
|
||||
|
||||
public function __construct(\moodle_page $page) {
|
||||
parent::__construct($page);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method, $this->exposedkey) !== false) {
|
||||
|
@ -793,7 +792,6 @@ class exposed_settings_navigation extends settings_navigation {
|
|||
public function __construct() {
|
||||
global $PAGE;
|
||||
parent::__construct($PAGE);
|
||||
$this->cache = new navigation_cache('unittest_nav');
|
||||
}
|
||||
public function __call($method, $arguments) {
|
||||
if (strpos($method, $this->exposedkey) !== false) {
|
||||
|
|
|
@ -700,6 +700,27 @@ class core_testable_persistent extends persistent {
|
|||
|
||||
const TABLE = 'phpunit_persistent';
|
||||
|
||||
/** @var bool before validate status. */
|
||||
public ?bool $beforevalidate;
|
||||
|
||||
/** @var bool before create status. */
|
||||
public ?bool $beforecreate;
|
||||
|
||||
/** @var bool before update status. */
|
||||
public ?bool $beforeupdate;
|
||||
|
||||
/** @var bool before delete status. */
|
||||
public ?bool $beforedelete;
|
||||
|
||||
/** @var bool after create status. */
|
||||
public ?bool $aftercreate;
|
||||
|
||||
/** @var bool after update status. */
|
||||
public ?bool $afterupdate;
|
||||
|
||||
/** @var bool after delete status. */
|
||||
public ?bool $afterdelete;
|
||||
|
||||
protected static function define_properties() {
|
||||
return array(
|
||||
'shortname' => array(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue