forked from gocodebox/lifterlms
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also add LLMS_Module_Loader::$instance->is_module_loaded($name) as a way to check if a module has been loaded.
- Loading branch information
1 parent
cbf476e
commit 3de0beb
Showing
2 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
tests/unit-tests/modules/class-llms-test-module-loader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Tests for LifterLMS Module loader | ||
* | ||
* @group modules | ||
* | ||
* @since [version] | ||
* @version [version] | ||
*/ | ||
class LLMS_Test_Module_Loader extends LLMS_UnitTestCase { | ||
|
||
/** | ||
* Test the modules loading. | ||
* | ||
* @since [version] | ||
* | ||
* @return void | ||
*/ | ||
public function test_load() { | ||
|
||
// get modules to be loades. | ||
$modules = $this->_get_load_info(); | ||
|
||
// check they've been loaded. | ||
foreach ( $modules as &$module ) { | ||
$module['actions'] = did_action( "lifterlms_module_{$module['name']}_loaded" ); | ||
$this->assertEquals( 1, $module['actions'] ); | ||
LLMS_Module_Loader::instance()->is_module_loaded( $module['name'] ); | ||
} | ||
|
||
// define module constants to false so to skip the loading. | ||
foreach ( $modules as $module ) { | ||
! defined( $module['constant_name'] ) && define( $module['constant_name'], FALSE ); | ||
} | ||
|
||
// Fire the loading once again. | ||
$loaded = LLMS_Unit_Test_Util::call_method( LLMS_Module_Loader::instance(), 'load' ); | ||
|
||
// check they've not been loaded this time. | ||
$this->assertEquals( array(), $loaded ); | ||
|
||
foreach ( $modules as &$module ) { | ||
$actions_counter = $module['actions']; | ||
$module['actions'] = did_action( "lifterlms_module_{$module['name']}_loaded" ); | ||
$this->assertEquals( $actions_counter, $module['actions'] ); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Get the array of modules to load. | ||
* Of the type: | ||
* $module = array( | ||
* 'name' => 'module-name', | ||
* 'file_path' => 'lifterlms/includes/modules/module-name/class-llms-module-name.php', | ||
* 'constant_name' => 'LLMS_MODULE_NAME', | ||
* ); | ||
* | ||
* @since [version] | ||
* | ||
* @return array | ||
*/ | ||
private function _get_load_info() { | ||
return LLMS_Unit_Test_Util::call_method( LLMS_Module_Loader::instance(), 'load_info' ); | ||
} | ||
} |