MDL-73971 phpunit: Move more tests to use correct names and namespaces

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:

- Some fixtures, initially defined in the test files have been
  moved to new files in fixtures subdirectory, leaving the unit
  test files clearer:
  - moodle2_course_format_test.php
- Rename wrong named test:
  - baseoptiogroup_test = baseoptigroup_test
This commit is contained in:
Eloy Lafuente (stronk7)
2022-05-06 18:29:24 +02:00
parent 199974b45d
commit 1c33085ede
143 changed files with 1946 additions and 2337 deletions
@@ -14,12 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package core_backup
* @category phpunit
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_backup;
use base_atom_struct_exception;
use base_element_parent_exception;
use base_element_struct_exception;
use mock_base_attribute;
use mock_base_final_element;
use mock_base_nested_element;
defined('MOODLE_INTERNAL') || die();
@@ -28,9 +30,16 @@ require_once(__DIR__.'/fixtures/structure_fixtures.php');
/**
* Unit test case the base_nested_element class. Note: highly imbricated with base_final_element class
* Unit test case the base_nested_element class.
*
* Note: highly imbricated with base_final_element class
*
* @package core_backup
* @category test
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_base_nested_element_testcase extends basic_testcase {
class basenestedelement_test extends \basic_testcase {
/**
* Correct creation tests (attributes and final elements)
@@ -179,27 +188,27 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance = new mock_base_nested_element('');
$this->fail("Expecting base_atom_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_atom_struct_exception);
}
// Create instance with incorrect (object) final element
try {
$obj = new stdClass;
$obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_nested_element('TEST', null, $obj);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
// Create instance with array containing incorrect (object) final element
try {
$obj = new stdClass;
$obj = new \stdClass;
$obj->name = 'test_attr';
$instance = new mock_base_nested_element('TEST', null, array($obj));
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -207,7 +216,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance = new mock_base_nested_element('TEST', null, array('VAL1', 'VAL2', 'VAL1'));
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -216,7 +225,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance->get_value();
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -225,7 +234,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance->set_value('some_value');
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -234,7 +243,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$instance->clean_value('some_value');
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
}
@@ -304,17 +313,17 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
// Add non base_element object child
$parent = new mock_base_nested_element('PARENT');
$child = new stdClass();
$child = new \stdClass();
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -324,7 +333,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -336,7 +345,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -348,7 +357,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$grandparent->add_child($parent);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -364,7 +373,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$grandparent->add_child($parent2);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
}
@@ -376,7 +385,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$parent2->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_parent_exception);
}
@@ -386,7 +395,7 @@ class backup_base_nested_element_testcase extends basic_testcase {
try {
$nested->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
} catch (\Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
$this->assertEquals($e->errorcode, 'baseelementchildnameconflict');
$this->assertEquals($e->a, 'FINAL2');