mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Improved variable naming in unit pluginsTest
Also fixed a bug where invalid plugin addon names were being checked
This commit is contained in:
@@ -26,86 +26,79 @@
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkPlugin($plugin, $debug=false)
|
private function makePluginReport($pluginDir, $debug=false)
|
||||||
{
|
{
|
||||||
|
$debug_text = "\n\n---- Log \n\n";
|
||||||
|
|
||||||
|
|
||||||
$text = "\n\n---- Log \n\n";
|
|
||||||
$log = e107::getPlugin()->getLog();
|
$log = e107::getPlugin()->getLog();
|
||||||
|
|
||||||
foreach($log as $line)
|
foreach($log as $line)
|
||||||
{
|
{
|
||||||
$text .= " - ".$line."\n";
|
$debug_text .= " - ".$line."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$text .= "----------------------------------------\n\n";
|
$debug_text .= "----------------------------------------\n\n";
|
||||||
|
|
||||||
$text .= "---- Pref: plug_installed (version)\n\n";
|
$debug_text .= "---- Pref: plug_installed (version)\n\n";
|
||||||
$pref = e107::getConfig('core',true,true)->get('plug_installed');
|
$pref = e107::getConfig('core',true,true)->get('plug_installed');
|
||||||
|
|
||||||
$text .= print_r($pref[$plugin],true);
|
$debug_text .= print_r($pref[$pluginDir],true);
|
||||||
|
|
||||||
$installedPref = isset($pref[$plugin]) ? $pref[$plugin] : false;
|
$installedPref = isset($pref[$pluginDir]) ? $pref[$pluginDir] : false;
|
||||||
|
|
||||||
$text .= "\n\n---- Plugin Prefs: \n\n";
|
$debug_text .= "\n\n---- Plugin Prefs: \n\n";
|
||||||
$pluginPref = e107::pref($plugin);
|
$pluginPref = e107::pref($pluginDir);
|
||||||
$text .= print_r($pluginPref,true);
|
$debug_text .= print_r($pluginPref,true);
|
||||||
|
|
||||||
|
|
||||||
$text .= "\n---- Plugin Table: ".$plugin."\n\n";
|
$debug_text .= "\n---- Plugin Table: ".$pluginDir."\n\n";
|
||||||
$pluginTable = e107::getDb()->retrieve('plugin','*', "plugin_path='".$plugin."' LIMIT 1", true);
|
$pluginTable = e107::getDb()->retrieve('plugin','*', "plugin_path='".$pluginDir."' LIMIT 1", true);
|
||||||
$text .= print_r($pluginTable,true);
|
$debug_text .= print_r($pluginTable,true);
|
||||||
|
|
||||||
$text .= "\n---- Menu Table: ".$plugin."\n\n";
|
$debug_text .= "\n---- Menu Table: ".$pluginDir."\n\n";
|
||||||
$menuTable = e107::getDb()->retrieve('menus','*', "menu_location = 0 AND menu_path='".$plugin."/' LIMIT 10", true);
|
$menuTable = e107::getDb()->retrieve('menus','*', "menu_location = 0 AND menu_path='".$pluginDir."/' LIMIT 10", true);
|
||||||
$text .= print_r($menuTable, true);
|
$debug_text .= print_r($menuTable, true);
|
||||||
|
|
||||||
$text .= "\n---- Site Links Table: ".$plugin."\n\n";
|
$debug_text .= "\n---- Site Links Table: ".$pluginDir."\n\n";
|
||||||
$linksTable = e107::getDb()->retrieve('links','*', "link_owner='".$plugin."' ", true);
|
$linksTable = e107::getDb()->retrieve('links','*', "link_owner='".$pluginDir."' ", true);
|
||||||
$text .= print_r($linksTable, true);
|
$debug_text .= print_r($linksTable, true);
|
||||||
|
|
||||||
$dir = scandir(e_PLUGIN.$plugin);
|
$files_in_plugin_directory = scandir(e_PLUGIN.$pluginDir);
|
||||||
$corePref = e107::getConfig('core',true,true)->getPref();
|
$corePref = e107::getConfig('core',true,true)->getPref();
|
||||||
|
|
||||||
|
|
||||||
$text .= "\n---- Addons\n\n";
|
$debug_text .= "\n---- Addons\n\n";
|
||||||
$text .= "-------------------------------------------------------------------\n";
|
$debug_text .= "-------------------------------------------------------------------\n";
|
||||||
$text .= "Addon file In Core pref e_xxxx_list \n";
|
$debug_text .= "Addon file In Core pref e_xxxx_list \n";
|
||||||
$text .= "-------------------------------------------------------------------\n";
|
$debug_text .= "-------------------------------------------------------------------\n";
|
||||||
|
|
||||||
$addonPref = array();
|
$addonPref = array();
|
||||||
|
|
||||||
foreach($dir as $file)
|
$plugin_addon_names = $this->pluginFileListToPluginAddonNames($files_in_plugin_directory);
|
||||||
|
|
||||||
|
foreach($plugin_addon_names as $plugin_addon_name)
|
||||||
{
|
{
|
||||||
$name = basename($file,".php");
|
$key = $plugin_addon_name."_list";
|
||||||
|
$addon_pref_is_present = !empty($corePref[$key][$pluginDir]);
|
||||||
if(substr($file,0,2) === 'e_')
|
$debug_addon_pref_is_present = ($addon_pref_is_present) ? 'YES' : 'NO';
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
$key = $name."_list";
|
|
||||||
$status = !empty($corePref[$key][$plugin]) ? 'YES' : 'NO';
|
|
||||||
|
|
||||||
if($key === 'e_help_list')
|
if($key === 'e_help_list')
|
||||||
{
|
{
|
||||||
$status = "DEPRECATED by Admin-UI renderHelp()";
|
$debug_addon_pref_is_present = "DEPRECATED by Admin-UI renderHelp()";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$addonPref[$name] = ($status === 'YES') ? true : false;
|
$addonPref[$plugin_addon_name] = $addon_pref_is_present;
|
||||||
}
|
}
|
||||||
|
|
||||||
$text .= str_pad($file,20)."\t\t".$status."\n";
|
$debug_text .= str_pad("$plugin_addon_name.php",20)
|
||||||
|
."\t\t$debug_addon_pref_is_present\n";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$text .= "-------------------------------------------------------------------\n";
|
$debug_text .= "-------------------------------------------------------------------\n";
|
||||||
|
|
||||||
if($debug === true)
|
if($debug === true)
|
||||||
{
|
{
|
||||||
echo $text;
|
codecept_debug($debug_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
@@ -117,9 +110,6 @@
|
|||||||
'linksTable' => $linksTable,
|
'linksTable' => $linksTable,
|
||||||
'addonPref' => $addonPref
|
'addonPref' => $addonPref
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBanner()
|
public function testBanner()
|
||||||
@@ -132,9 +122,10 @@
|
|||||||
$this->assertContains("<img class='e-banner img-responsive img-fluid'",$result);
|
$this->assertContains("<img class='e-banner img-responsive img-fluid'",$result);
|
||||||
|
|
||||||
$this->pluginUninstall('banner');
|
$this->pluginUninstall('banner');
|
||||||
$result2 = $tp->parseTemplate("{BANNER=e107promo}",true); // should return null since plugin is uninstalled.
|
$result2 = $tp->parseTemplate("{BANNER=e107promo}",true);
|
||||||
|
|
||||||
|
|
||||||
|
// The expected value below was the actual observed output when the assertion was written:
|
||||||
|
$this->assertEquals(' ', $result2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChatbox_Menu()
|
public function testChatbox_Menu()
|
||||||
@@ -228,9 +219,7 @@
|
|||||||
|
|
||||||
e107::getPlugin()->install($pluginDir);
|
e107::getPlugin()->install($pluginDir);
|
||||||
|
|
||||||
$install = $this->checkPlugin($pluginDir, false); // set to true to see more info
|
$install = $this->makePluginReport($pluginDir, false); // set to true to see more info
|
||||||
|
|
||||||
// print_r($install);
|
|
||||||
|
|
||||||
//todo additional checks
|
//todo additional checks
|
||||||
|
|
||||||
@@ -238,9 +227,6 @@
|
|||||||
{
|
{
|
||||||
$this->assertTrue($val, $key." list pref is missing for ".$pluginDir);
|
$this->assertTrue($val, $key." list pref is missing for ".$pluginDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function pluginUninstall($pluginDir)
|
private function pluginUninstall($pluginDir)
|
||||||
@@ -252,9 +238,7 @@
|
|||||||
|
|
||||||
e107::getPlugin()->uninstall($pluginDir, $opts);
|
e107::getPlugin()->uninstall($pluginDir, $opts);
|
||||||
|
|
||||||
$uninstall = $this->checkPlugin($pluginDir, false); // set to true to see more info
|
$uninstall = $this->makePluginReport($pluginDir, false); // set to true to see more info
|
||||||
|
|
||||||
// print_r($uninstall);
|
|
||||||
|
|
||||||
//todo additional checks
|
//todo additional checks
|
||||||
|
|
||||||
@@ -265,15 +249,32 @@
|
|||||||
$message = $key." list pref still contains '".$pluginDir."' after uninstall of ".$pluginDir.". ";
|
$message = $key." list pref still contains '".$pluginDir."' after uninstall of ".$pluginDir.". ";
|
||||||
$this->assertEmpty($val, $message);
|
$this->assertEmpty($val, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $plugin_file_list
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function pluginFileListToPluginAddonNames($plugin_file_list): array
|
||||||
|
{
|
||||||
|
$plugin_addon_names = array_map(function ($addon_path) {
|
||||||
|
return basename($addon_path, '.php');
|
||||||
|
}, $plugin_file_list);
|
||||||
|
|
||||||
|
$class_name_that_has_plugin_addons_array = 'e107plugin';
|
||||||
|
try {
|
||||||
|
$reflectionClass = new ReflectionClass($class_name_that_has_plugin_addons_array);
|
||||||
|
} catch (ReflectionException $e) {
|
||||||
|
$this->fail("Could not instantiate $class_name_that_has_plugin_addons_array to get \$plugin_addons");
|
||||||
|
}
|
||||||
|
$reflectionProperty = $reflectionClass->getProperty('plugin_addons');
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
$valid_plugin_addon_names = $reflectionProperty->getValue(new $class_name_that_has_plugin_addons_array());
|
||||||
|
|
||||||
|
$plugin_addon_names = array_filter($plugin_addon_names, function ($plugin_addon_name) use ($valid_plugin_addon_names) {
|
||||||
|
return in_array($plugin_addon_name, $valid_plugin_addon_names);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $plugin_addon_names;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user