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:
@@ -14,18 +14,7 @@
|
||||
// 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 the condition tree class and related logic.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_availability\capability_checker;
|
||||
use \core_availability\tree;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
namespace core_availability;
|
||||
|
||||
/**
|
||||
* Unit tests for the condition tree class and related logic.
|
||||
@@ -34,7 +23,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tree_testcase extends \advanced_testcase {
|
||||
class tree_test extends \advanced_testcase {
|
||||
public function setUp(): void {
|
||||
// Load the mock classes so they can be used.
|
||||
require_once(__DIR__ . '/fixtures/mock_condition.php');
|
||||
@@ -48,83 +37,83 @@ class tree_testcase extends \advanced_testcase {
|
||||
try {
|
||||
new tree('frog');
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('not object', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array());
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->op', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '*'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('unknown ->op', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->show', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => 0));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->show not bool', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '&'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->showc', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '&', 'showc' => 0));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->showc not array', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '&', 'showc' => array(0)));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->showc value not bool', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->c', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => 'side'));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->c not array', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => array(3)));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('child not object', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => array((object)array('type' => 'doesnotexist'))));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('Unknown condition type: doesnotexist', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
new tree((object)array('op' => '|', 'show' => true,
|
||||
'c' => array((object)array())));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('missing ->op', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
@@ -133,7 +122,7 @@ class tree_testcase extends \advanced_testcase {
|
||||
'showc' => array(true, true)
|
||||
));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
} catch (\coding_exception $e) {
|
||||
$this->assertStringContainsString('->c, ->showc mismatch', $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -336,7 +325,7 @@ class tree_testcase extends \advanced_testcase {
|
||||
/**
|
||||
* Shortcut function to check availability and also get information.
|
||||
*
|
||||
* @param stdClass $structure Tree structure
|
||||
* @param \stdClass $structure Tree structure
|
||||
* @param \core_availability\info $info Location info
|
||||
* @param int $userid User id
|
||||
*/
|
||||
@@ -355,7 +344,7 @@ class tree_testcase extends \advanced_testcase {
|
||||
/**
|
||||
* Shortcut function to render the full availability information.
|
||||
*
|
||||
* @param stdClass $structure Tree structure
|
||||
* @param \stdClass $structure Tree structure
|
||||
* @param \core_availability\info $info Location info
|
||||
*/
|
||||
protected function render_full_information($structure, \core_availability\info $info) {
|
||||
|
||||
Reference in New Issue
Block a user