_plg = $this->make('e107plugin');
}
catch (Exception $e)
{
$this->assertTrue(false, "Couldn't load e107plugin object");
}*/
}
private function makePluginReport($pluginDir)
{
$debug = $this->_debugPlugin;
$debug_text = "\n\n---- Log \n\n";
$log = e107::getPlugin()->getLog();
foreach($log as $line)
{
$debug_text .= " - ".$line."\n";
}
$debug_text .= "----------------------------------------\n\n";
$debug_text .= "---- Pref: plug_installed (version)\n\n";
$pref = e107::getConfig('core',true,true)->get('plug_installed');
$installedPref = isset($pref[$pluginDir]) ? $pref[$pluginDir] : false;
$debug_text .= print_r($installedPref,true);
$debug_text .= "\n\n---- Plugin Prefs: \n\n";
$pluginPref = e107::pref($pluginDir);
$debug_text .= print_r($pluginPref,true);
$debug_text .= "\n---- Plugin Table: ".$pluginDir."\n\n";
$pluginTable = e107::getDb()->retrieve('plugin','*', "plugin_path='".$pluginDir."' LIMIT 1", true);
$debug_text .= print_r($pluginTable,true);
$debug_text .= "\n---- Menu Table: ".$pluginDir."\n\n";
$menuTable = e107::getDb()->retrieve('menus','*', "menu_location = 0 AND menu_path='".$pluginDir."/' LIMIT 10", true);
$debug_text .= print_r($menuTable, true);
$debug_text .= "\n---- Site Links Table: ".$pluginDir."\n\n";
$linksTable = e107::getDb()->retrieve('links','*', "link_owner='".$pluginDir."' ", true);
$debug_text .= print_r($linksTable, true);
$files_in_plugin_directory = @scandir(e_PLUGIN.$pluginDir) ?: [];
$corePref = e107::getConfig('core',true,true)->getPref();
$debug_text .= "\n---- Addons\n\n";
$debug_text .= "-------------------------------------------------------------------\n";
$debug_text .= "Addon file In Core pref e_xxxx_list \n";
$debug_text .= "-------------------------------------------------------------------\n";
$addonPref = array();
$plugin_addon_names = $this->pluginFileListToPluginAddonNames($files_in_plugin_directory);
foreach($plugin_addon_names as $plugin_addon_name)
{
$key = $plugin_addon_name."_list";
$addon_pref_is_present = !empty($corePref[$key][$pluginDir]);
$debug_addon_pref_is_present = ($addon_pref_is_present) ? 'YES' : 'NO';
if($key === 'e_admin_events_list')
{
$debug_addon_pref_is_present = "DEPRECATED by Admin-UI events";
}
if($key === 'e_help_list')
{
$debug_addon_pref_is_present = "DEPRECATED by Admin-UI renderHelp()";
}
else
{
$addonPref[$plugin_addon_name] = $addon_pref_is_present;
}
$debug_text .= str_pad("$plugin_addon_name.php",20)
."\t\t$debug_addon_pref_is_present\n";
}
$debug_text .= "-------------------------------------------------------------------\n";
if(!empty($debug) && $pluginDir === $debug)
{
codecept_debug($debug_text);
echo $debug_text;
}
return array(
'log' => $log,
'installedPref' => $installedPref,
'pluginPref' => $pluginPref,
'pluginTable' => $pluginTable,
'menuTable' => $menuTable,
'linksTable' => $linksTable,
'addonPref' => $addonPref
);
}
/**
* @see https://github.com/e107inc/e107/issues/3547
*/
public function testBlank()
{
// $this->_debugPlugin = '_blank';
$this->pluginInstall('_blank');
// $this->pluginUninstall('_blank');
}
public function testSortOrderPeriodUnderscore()
{
$expected = ['banner.php', 'banner_menu.php'];
$input = ['banner_menu.php', 'banner.php'];
sort($input);
$this->assertEquals($expected, $input);
}
public function testPluginScripts()
{
$core = e107::getPlug()->getCorePluginList();
$exclude = array(
'forum/forum_post.php',
'forum/forum_viewtopic.php', // needs a major cleanup.
'forum/index.php',
'online/online_menu.php', // FIXME missing template for member/new
'pm/pm.php', // FIXME contains exit, needs rework.
'poll/admin_config.php', // FIXME convert to admin-ui
'rss_menu/rss.php', // FIXME rework code into class.
'tagcloud/tagcloud_menu.php', // FIXME - strange (PHP bug?), doesn't see the render() method.
'tinymce4/wysiwyg.php', // javascript generator.
);
//DEBUG A SPECIFIC FILE : dir => file
// $focus = array('tagcloud'=>'tagcloud_menu.php');
foreach($core as $plug)
{
$parm = null; //
e107::plugLan($plug, 'global'); // load global language (usually done in class2.php)
e107::getConfig()->setPref('plug_installed/'.$plug, 1); // simulate installed.
$path = e_PLUGIN.$plug;
$files = scandir($path);
unset($files[0], $files[1]); // . and ..
sort($files);
if(!empty($focus) && !isset($focus[$plug]))
{
continue;
}
foreach($files as $f)
{
$filePath = $path.'/'.$f;
if(!empty($focus) && $f !== $focus[$plug])
{
continue;
}
if(is_dir($filePath) || (strpos($f, '_sql.php') !== false) || strpos($f, '.php') === false || in_array($plug.'/'.$f, $exclude))
{
continue;
}
// echo " --- ".$filePath." --- \n";
if(empty($focus))
{
ob_start();
}
require_once( $filePath);
if(empty($focus))
{
ob_end_clean();
}
// echo $plug.'/'.$f."\n";
}
}
}
/**
* @see https://github.com/e107inc/e107/issues/3547
*/
public function testBanner()
{
$this->pluginInstall('banner');
// App needs e_parse_shortcode to be reloaded because another test
// could have initialized e_parse_shortcode already before the
// "banner" plugin was installed.
e107::getScParser()->__construct();
$tp = e107::getParser();
$result = $tp->parseTemplate("{BANNER=e107promo}", true);
$this->assertStringContainsString('
parseTemplate("{BANNER=e107promo}", false, e107::getScBatch('banner', true));
$this->assertStringContainsString('
parseTemplate("{BANNER=e107promo}", false);
$this->assertEquals("", $result);
$this->pluginUninstall('banner');
$result = $tp->parseTemplate("{BANNER=e107promo}", true);
// The expected value below was the actual observed output when the assertion was written:
$this->assertEquals(' ', $result,
"Banner shortcode is not returning an empty value, despite banner being uninstalled");
}
public function testChatbox_Menu()
{
$this->pluginInstall('chatbox_menu');
$this->pluginUninstall('chatbox_menu');
}
public function testDownload()
{
$this->pluginInstall('download');
$this->pluginUninstall('download');
}
public function testFaqs()
{
$this->pluginInstall('faqs');
$this->pluginUninstall('faqs');
}
public function testFeaturebox()
{
$this->pluginInstall('featurebox');
$this->pluginUninstall('featurebox');
}
public function testForum()
{
$this->pluginInstall('forum');
$this->pluginUninstall('forum');
}
public function testGallery()
{
$this->pluginInstall('gallery');
$this->pluginUninstall('gallery');
}
public function testGsitemap()
{
$this->pluginInstall('gsitemap');
$this->pluginUninstall('gsitemap');
}
public function testImport()
{
$this->pluginInstall('import');
$this->pluginUninstall('import');
}
public function testLinkwords()
{
$this->pluginInstall('linkwords');
$pref1 = e107::pref('linkwords', 'lw_custom_class');
$this->assertNotEmpty($pref1);
$pref2 = e107::pref('linkwords', 'lw_context_visibility');
$this->assertNotEmpty($pref2['SUMMARY']);
$this->pluginUninstall('linkwords');
$pref2 = e107::pref('linkwords', 'lw_context_visibility');
$this->assertEmpty($pref2);
}
public function testPm()
{
$this->pluginInstall('pm');
$this->pluginUninstall('pm');
}
public function testPoll()
{
$this->pluginInstall('poll');
$this->pluginUninstall('poll');
}
public function testRss_menu()
{
$this->pluginInstall('rss_menu');
$this->pluginUninstall('rss_menu');
}
public function testSocial()
{
$this->pluginUninstall('social');
$this->pluginInstall('social');
}
public function testTagcloud()
{
$this->pluginInstall('tagcloud');
$this->pluginUninstall('tagcloud');
}
/*
public function testThirdParty()
{
$coreList = e107::getPlug()->getCorePluginList();
$all = scandir(e_PLUGIN);
unset($all[0], $all[1]);
$diff = array_diff($all, $coreList);
foreach($diff as $plug)
{
if(!is_dir(e_PLUGIN.$plug) || !is_dir(e_PLUGIN.$plug.'/tests'))
{
continue;
}
$tests = scandir(e_PLUGIN.$plug.'/tests');
unset($tests[0], $tests[1]);
foreach($tests as $t)
{
require_once(e_PLUGIN.$plug.'/tests/'.$t);
$Codecept = new \Codeception\Codecept(array(
'steps' => true,
'verbosity' => 1,
// some other options (see Codeception docs/sources)
));
// var_export($Codecept);
$Codecept->run('unit');
// require_once '/path/to/codeception/autoload.php';
}
}
//array_intersect(
}*/
public function testVstore()
{
if(!is_dir(e_PLUGIN."vstore"))
{
return ;
}
$this->pluginInstall('vstore');
$this->pluginRefresh('vstore');
$links = e107::getDb()->retrieve('links', '*', 'link_owner = "vstore"', true);
$this->assertNotEmpty($links);
$this->assertCount(2, $links);
$this->pluginUninstall('vstore');
}
public function testplugInstalledStatus()
{
$sql = e107::getDb();
$plg = e107::getPlug()->clearCache();
$plg->load('tagcloud');
// check it's NOT installed.
$status = $plg->isInstalled();
$dbStatus = (bool) $sql->retrieve('plugin', "plugin_installflag", "plugin_path='tagcloud'");
$this->assertEquals($status,$dbStatus,"e_plugin:isInstalled() doesn't match plugin_installflag in db table.");
$this->assertFalse($status, "Status for tagcloud being installed should be false");
e107::getPlugin()->install('tagcloud');
// check it's installed.
$status = (int) $plg->isInstalled();
$actual = (bool) $status;
$dbStatus = (int) $sql->retrieve('plugin', "plugin_installflag", "plugin_path='tagcloud'");
$this->assertEquals($status,$dbStatus,"e_plugin:isInstalled() = ".$status." but plugin_installflag = ".$dbStatus." after install.");
$this->assertTrue($actual, "Status for tagcloud being installed should be true after being installed.");
e107::getPlugin()->uninstall('tagcloud');
// check it's NOT installed.
$status = (int) $plg->isInstalled();
$actual = (bool) $status;
$dbStatus = (int) $sql->retrieve('plugin', "plugin_installflag", "plugin_path='tagcloud'");
$this->assertEquals($status,$dbStatus,"e_plugin:isInstalled() = ".$status." but plugin_installflag = ".$dbStatus." after uninstall.");
$this->assertFalse($actual, "Status for tagcloud being installed should be false after being uninstalled.");
}
public function testPluginAddons()
{
$plg = e107::getPlug()->clearCache();
$plg->buildAddonPrefLists();
$errors = array(
1 => 'PHP tag Syntax issue',
2 => "File Missing",
);
foreach($plg->getCorePluginList() as $folder)
{
$plg->load($folder);
$errMsg = '';
$addons = $plg->getAddons();
foreach(explode(',', $addons) as $this_addon)
{
if(empty($this_addon))
{
continue;
}
$result = $plg->getAddonErrors($this_addon);
if(is_numeric($result) && $result != 0)
{
$errMsg = " (".$errors[$result].")";
}
elseif(isset($result['msg']))
{
$errMsg = " (".$result['msg'].")";
}
$this->assertEmpty($result, $folder." > ".$this_addon." returned error #".$result.$errMsg);
}
}
}
public function testRemotePlugin()
{
require_once(e_HANDLER."e_marketplace.php");
try
{
$mock_adapter = $this->make('e_marketplace_adapter_wsdl',
[
'getRemoteFile' => function($remote_url, $local_file, $type='temp')
{
file_put_contents(e_TEMP.$local_file, self::samplePluginContents());
return true;
}
]);
$mp = $this->make('e_marketplace',
[
'adapter' => $mock_adapter
]);
}
catch (Exception $e)
{
$this->fail("Couldn't load e_marketplace object");
}
$mp->__construct();
$id = 912; // No-follow plugin on e107.org
$this->assertFalse(is_dir(e_PLUGIN."nofollow"), "Plugin nofollow exists before download");
$mp->download($id, '', 'plugin');
$this->assertTrue(is_dir(e_PLUGIN."nofollow"), "Plugin nofollow is missing after download");
$this->pluginInstall('nofollow');
$opts = array(
'delete_tables' => 1,
'delete_files' => 1
);
$this->pluginUninstall('nofollow',$opts);
$status = is_dir(e_PLUGIN."nofollow");
$this->assertFalse($status,"nofollow plugin still exists, despite opt to have it removed during uninstall.");
}
private function pluginRefresh($pluginDir)
{
$return_text = e107::getPlugin()->refresh($pluginDir);
}
private function pluginInstall($pluginDir)
{
e107::setRegistry('core/form/related'); // reset.
e107::getPlugin()->uninstall($pluginDir);
$return_text = e107::getPlugin()->install($pluginDir);
$this->assertNotEquals("Plugin is already installed.", $return_text);
$install = $this->makePluginReport($pluginDir);
//todo additional checks
foreach($install['addonPref'] as $key=>$val)
{
$this->assertTrue($val, $key." list pref is missing for ".$pluginDir);
}
}
private function pluginUninstall($pluginDir, $opts=array())
{
if(empty($opts))
{
$opts = array(
'delete_tables' => 1,
'delete_files' => 0
);
}
e107::getPlugin()->uninstall($pluginDir, $opts);
$uninstall = $this->makePluginReport($pluginDir);
//todo additional checks
$this->assertEmpty($uninstall['linksTable'], $pluginDir." link still exists in the links table");
foreach($uninstall['addonPref'] as $key=>$val)
{
$message = $key." list pref still contains '".$pluginDir."' after uninstall of ".$pluginDir.". ";
$message .= print_r($uninstall,true);
$this->assertEmpty($val, $message);
}
return $uninstall;
}
/**
* @param $plugin_file_list
* @return array
*/
private function pluginFileListToPluginAddonNames($plugin_file_list)
{
$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;
}
private static function samplePluginContents()
{
return base64_decode(<<