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:
@@ -15,12 +15,22 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Test progressive_parser and progressive_parser_processor tests.
|
||||
*
|
||||
* @package core_backup
|
||||
* @category phpunit
|
||||
* @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
|
||||
*/
|
||||
|
||||
namespace core_backup;
|
||||
|
||||
use grouped_parser_processor;
|
||||
use progressive_parser;
|
||||
use progressive_parser_exception;
|
||||
use progressive_parser_processor;
|
||||
use simplified_parser_processor;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Include all the needed stuff
|
||||
@@ -30,10 +40,15 @@ require_once($CFG->dirroot . '/backup/util/xml/parser/processors/progressive_par
|
||||
require_once($CFG->dirroot . '/backup/util/xml/parser/processors/simplified_parser_processor.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/parser/processors/grouped_parser_processor.class.php');
|
||||
|
||||
/*
|
||||
* progressive_parser and progressive_parser_processor tests
|
||||
/**
|
||||
* Test progressive_parser and progressive_parser_processor tests.
|
||||
*
|
||||
* @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 progressive_parser_test extends advanced_testcase {
|
||||
class parser_test extends \advanced_testcase {
|
||||
|
||||
/*
|
||||
* test progressive_parser public methods
|
||||
@@ -50,7 +65,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->process();
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'undefined_parser_processor');
|
||||
}
|
||||
@@ -62,16 +77,16 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->process();
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'undefined_xml_to_parse');
|
||||
}
|
||||
|
||||
// Assign *invalid* processor to parser
|
||||
try {
|
||||
$pp->set_processor(new stdClass());
|
||||
$pp->set_processor(new \stdClass());
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_parser_processor');
|
||||
}
|
||||
@@ -87,7 +102,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test0.xml');
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_file_to_parse');
|
||||
}
|
||||
@@ -103,7 +118,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try {
|
||||
$pp->set_contents('');
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'invalid_contents_to_parse');
|
||||
}
|
||||
@@ -129,7 +144,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
$pp->set_file($CFG->dirroot . '/backup/util/xml/parser/tests/fixtures/test2.xml');
|
||||
try {
|
||||
$pp->process();
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'xml_parsing_error');
|
||||
}
|
||||
@@ -143,7 +158,7 @@ class progressive_parser_test extends advanced_testcase {
|
||||
try { // Second process, will throw exception
|
||||
$pp->process();
|
||||
$this->assertTrue(false);
|
||||
} catch (exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue($e instanceof progressive_parser_exception);
|
||||
$this->assertEquals($e->errorcode, 'progressive_parser_already_used');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user