e107 = e107::getInstance(); } catch(Exception $e) { self::fail("Couldn't load e107 object"); } } public function testGetInstance() { // $this->e107->getInstance(); //$res = $this->e107::getInstance(); // $this->assertTrue($res); } public function testInitCore() { //$res = null; include_once(APP_PATH . '/e107_config.php'); // contains $E107_CONFIG = array('site_path' => '000000test'); $e107_paths = @compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY', 'UPLOADS_DIRECTORY', 'SYSTEM_DIRECTORY', 'MEDIA_DIRECTORY', 'CACHE_DIRECTORY', 'LOGS_DIRECTORY', 'CORE_DIRECTORY', 'WEB_DIRECTORY'); $sql_info = @compact('mySQLserver', 'mySQLuser', 'mySQLpassword', 'mySQLdefaultdb', 'mySQLprefix', 'mySQLport'); $res = $this->e107->initCore($e107_paths, e_ROOT, $sql_info, varset($E107_CONFIG, array())); $this->assertEquals('000000test', $res->site_path); $this->assertEquals('/', e_HTTP); } public function testRenderLayout() { $opts = array ( 'magicSC' => array( '{---HEADER---}' => '
',
'E_16_TWITTER' => '
',
'E_16_GITHUB' => '
',
'E_16_E107' => '
',
'ADMIN_FILTER_ICON' => '',
'ADMIN_TRUE_ICON' => '✔',
'ADMIN_FALSE_ICON' => '⨯',
'ADMIN_WARNING_ICON' => '',
'ADMIN_GRID_ICON' => '',
'ADMIN_LIST_ICON' => '',
'ADMIN_EDIT_ICON' => '',
'ADMIN_DELETE_ICON' => '',
'ADMIN_SORT_ICON' => '',
'ADMIN_EXECUTE_ICON' => '',
'ADMIN_PAGES_ICON' => '',
'ADMIN_ADD_ICON' => '',
'ADMIN_INFO_ICON' => '',
'ADMIN_CONFIGURE_ICON' => '',
'ADMIN_VIEW_ICON' => '',
'ADMIN_URL_ICON' => '',
'ADMIN_INSTALLPLUGIN_ICON' => '',
'ADMIN_UNINSTALLPLUGIN_ICON' => '',
'ADMIN_UPGRADEPLUGIN_ICON' => '',
'ADMIN_REPAIRPLUGIN_ICON' => '',
'ADMIN_UP_ICON' => '',
'ADMIN_DOWN_ICON' => '',
'ADMIN_EDIT_ICON_PATH' => '/e107_images/admin_images/edit_32.png',
'ADMIN_DELETE_ICON_PATH' => '/e107_images/admin_images/delete_32.png',
'ADMIN_WARNING_ICON_PATH' => '/e107_images/admin_images/warning_32.png',
'E_24_PLUGIN' => " ",
);
$new = $e107::loadAdminIcons();
foreach($new as $key=>$val)
{
if(!isset($legacyList[$key]))
{
$this->fail("Remove {$key} FROM admin_icons_template");
}
$this->assertSame($legacyList[$key], $val, $key." should equal: ".$legacyList[$key]);
}
foreach($legacyList as $key=>$val)
{
if(!isset($new[$key]))
{
$this->fail("{$key} is missing from admin_icons_template");
}
}
$template2 = $e107::loadAdminIcons();
$this->assertSame($new, $template2);
$range = range(1,10);
foreach($range as $t)
{
e107::loadAdminIcons();
$e107::loadAdminIcons();
}
}
public function testGetCoreTemplate()
{
$e107 = $this->e107;
$templates = scandir(e_CORE . "templates");
// Load these constants before other tests fail because of what this test does:
$e107::loadAdminIcons();
$exclude = array(
'bbcode_template.php',
'online_template.php', // FIXME - convert the template to v2.x standards.
'sitedown_template.php', // FIXME - convert the template to v2.x standards.
);
foreach($templates as $file)
{
if(strpos($file, '_template.php') === false || in_array($file, $exclude))
{
continue;
}
$path = str_replace('_template.php', '', $file);
e107::coreLan($path);
if($path === 'signup')
{
e107::coreLan('user');
}
$result = $e107::getCoreTemplate($path);
$this->assertIsArray($result, $path . " template was not an array");
$this->assertNotEmpty($result, $path . " template was empty");
}
//$res = null;
//$this->assertTrue($res);
}
/*
private function clearRelatedRegistry($type)
{
$registry = e107::getRegistry('_all_');
$result = [];
foreach($registry as $reg => $v)
{
if(strpos($reg, $type) !== false)
{
e107::setRegistry($reg);
$result[] = $reg;
}
}
sort($result);
return $result;
}*/
/*
public function testGetTemplatePluginThemeMatch()
{
e107::plugLan('download', 'front', true);
e107::getConfig()->set('sitetheme', 'bootstrap3');
$template = e107::getTemplate('download', null, null);
var_export($template['header']);
echo "\n\n";
e107::getConfig()->set('sitetheme', '_blank');
$template = e107::getTemplate('download', null, null);
var_export($template['header']);
echo "\n\n";
e107::getConfig()->set('sitetheme', 'bootstrap3'); // doesn't have a download template, so fallback.
$template = e107::getTemplate('download', null, null); // theme override is enabled by default.
var_export($template['header']);
echo "\n\n";
e107::getConfig()->set('sitetheme', 'bootstrap3');
}
*/
public function testGetTemplateOverride()
{
// Loads e107_themes/bootstrap3/templates/gallery/gallery_template.php
$template = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true)
$this->assertEquals("My Gallery", $template['list']['caption']);
// Duplicate to load registry
$template2 = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true)
$this->assertEquals("My Gallery", $template2['list']['caption']);
$this->assertSame($template, $template2);
}
public function testGetTemplateOverrideMerge()
{
// Loads e107_plugins/gallery/templates/gallery_template.php then overwrites it with e107_themes/bootstrap3/templates/gallery/gallery_template.php
$template = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled.
$this->assertArrayHasKey('merged-example', $template);
$this->assertEquals("My Gallery", $template['list']['caption']); // ie. from the original
$this->assertNotEmpty($template['merged-example']);
// duplicate to load registry
$template2 = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled.
$this->assertArrayHasKey('merged-example', $template2);
$this->assertEquals("My Gallery", $template2['list']['caption']); // ie. from the original
$this->assertNotEmpty($template2['merged-example']);
$this->assertSame($template, $template2);
}
public function testGetTemplateMerge()
{
// // ie. should be from plugin template, not theme.
$template = e107::getTemplate('gallery', null, null, false, true); // theme override is disabled, theme merge is enabled.
$this->assertEquals("Gallery", $template['list']['caption']);
$this->assertArrayNotHasKey('merged-example', $template);
// duplicate to load registry.
$template2 = e107::getTemplate('gallery', null, null, false, true); // theme override is disabled, theme merge is enabled.
$this->assertEquals("Gallery", $template2['list']['caption']);
$this->assertArrayNotHasKey('merged-example', $template2);
$this->assertSame($template, $template2);
}
/**
* This test checks getTemplate() with no merging or override.
*/
public function testGetTemplate()
{
// Loads e107_plugins/gallery/templates/gallery_template.php
$template = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled.
$this->assertEquals("Gallery", $template['list']['caption']);
// Duplicate to load registry.
$template2 = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled.
$this->assertEquals("Gallery", $template2['list']['caption']);
$this->assertSame($template, $template2);
}
/*
public function testTemplateWrapper()
{
$res = null;
$this->assertTrue($res);
}
public function testScStyle()
{
$res = null;
$this->assertTrue($res);
}
public function testGetTemplateInfo()
{
$res = null;
$this->assertTrue($res);
}
public function testGetLayouts()
{
$res = null;
$this->assertTrue($res);
}
public function test_getTemplate()
{
$res = null;
$this->assertTrue($res);
}
public function testIncludeLan()
{
$res = null;
$this->assertTrue($res);
}
public function testCoreLan()
{
$res = null;
$this->assertTrue($res);
}
*/
public function testPlugLan()
{
$e107 = $this->e107;
$tests = array(
// plug, param 1, param 2, expected
0 => array('banner', '', false, 'e107_plugins/banner/languages/English_front.php'),
1 => array('forum', 'front', true, 'e107_plugins/forum/languages/English/English_front.php'),
2 => array('gallery', true, true, 'e107_plugins/gallery/languages/English/English_admin.php'),
3 => array('forum', 'menu', true, 'e107_plugins/forum/languages/English/English_menu.php'),
4 => array('banner', true, false, 'e107_plugins/banner/languages/English_admin.php'),
5 => array('chatbox_menu', e_LANGUAGE, false, 'e107_plugins/chatbox_menu/languages/English/English.php'),
6 => array('comment_menu', null, false, 'e107_plugins/comment_menu/languages/English.php'),
7 => array('poll', null, false, 'e107_plugins/poll/languages/English.php'),
8 => array('poll', null, false, 'e107_plugins/poll/languages/English.php'),
);
foreach($tests as $plug=>$var)
{
$result = $e107::plugLan($var[0], $var[1], $var[2], true);
if(!isset($var[3]))
{
echo $result."\n";
continue;
}
$this->assertStringContainsString($var[3], $result);
$e107::plugLan($var[0], $var[1], $var[2]);
}
/*
$registry = $e107::getRegistry('_all_');
foreach($registry as $k=>$v)
{
if(strpos($k, 'core/e107/pluglan/') !== false)
{
echo $k."\n";
}
}*/
}
function testDetectRoute()
{
e107::getPlugin()->install('forum');
$tests = array(
0 => array(
'plugin' => 'forum',
'uri' => '/e107_plugins/forum/forum.php?f=rules',
'expected' => 'forum/rules',
),
1 => array(
'plugin' => 'forum',
'uri' => '/e107_plugins/forum/forum_viewforum.php?id=543123',
'expected' => 'forum/forum',
),
);
foreach($tests as $index => $var)
{
$result = e107::detectRoute($var['plugin'], $var['uri']);
if(empty($var['expected']))
{
echo $result."\n";
continue;
}
$this->assertSame($var['expected'], $result);
}
e107::getPlugin()->uninstall('forum');
}
/*
public function testThemeLan()
{
$result = e107::themeLan(null, 'basic-light');
}*/
/*
public function testLan()
{
$res = null;
$this->assertTrue($res);
}
public function testPref()
{
$res = null;
$this->assertTrue($res);
}
*/
private function generateRows($var, $plugin)
{
preg_match_all('#\{([a-z_]*)\}#', $var['sef'], $matches);
$variables = array('-one-', '-two-', '-three-');
$ret = [];
if(!empty($matches[1]))
{
$c = 0;
foreach($matches[1] as $v)
{
if($v === 'alias' && !empty($var['alias']))
{
$ret['alias'] = $var['alias'];
}
else
{
$ret[$v] = $variables[$c];
$c++;
}
}
}
/*else
{
echo "\n".$plugin.' had no matches for: '.varset($var['sef'])."\n";
}*/
return $ret;
}
private function generateExpected($string, $rows)
{
$search = array('&');;
$replace = array('&');
foreach($rows as $k => $v)
{
$search[] = '{' . $k . '}';
$replace[] = $v;
}
return SITEURL . str_replace($search, $replace, $string);
}
public function testCanonical()
{
$e107 = $this->e107;
$e107::canonical('_RESET_');
$e107::canonical('news');
$result = $e107::canonical();
$this->assertSame("https://localhost/e107/news", $result);
}
public function testUrl()
{
$obj = $this->e107;
// Test FULL url option on Legacy url with new options['mode']
$tests = array(
0 => array(
'plugin' => 'news/view/item',
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
'row' => array(),
'options' => ['mode' => 'full'],
),
1 => array(
'plugin' => 'news/view/item',
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
'row' => 'full=1&encode=0',
'options' => ['mode' => 'full'],
),
2 => array(
'plugin' => 'news/view/item',
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
'row' => '',
'options' => ['mode' => 'full'],
),
3 => array(
'plugin' => 'news/view/item',
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
'row' => null,
'options' => ['mode' => 'full'],
),
);
foreach($tests as $v)
{
$result = $obj::url($v['plugin'], $v['key'], $v['row'], $v['options']);
self::assertStringContainsString('http', $result);
}
$tests = array();
$all = e107::getAddonConfig('e_url');
foreach($all as $plugin => $var)
{
if($plugin === 'gallery' || $plugin === 'rss_menu' || $plugin === 'vstore' || $plugin === '_blank') // fixme - sef may be enabled or disabled each time tests are run
{
continue;
}
foreach($var as $key => $value)
{
$rows = $this->generateRows($value, $plugin);
$tests[] = array(
'plugin' => $plugin,
'key' => $key,
'row' => $rows,
'options' => ['mode' => 'full'],
'_expected_' => $this->generateExpected($value['sef'], $rows),
);
}
}
foreach($tests as $index => $var)
{
if(empty($var['plugin']))
{
continue;
}
$result = $obj::url($var['plugin'], $var['key'], $var['row'], $var['options']);
if(empty($var['_expected_']))
{
echo $result . "\n";
continue;
}
self::assertEquals($var['_expected_'], $result, 'Failed on test #'.$index);
// $this->assertEquals("https://localhost/e107/news", $result);
}
}
public function testUrlDomain()
{
// e107 v2.4 - test for custom domain
$obj = $this->e107;
e107::getPlugin()->install('_blank');
$result = $obj::url('_blank', 'parked', null, ['mode'=>'full']);
self::assertSame('https://parked-domain.com/custom', $result);
e107::getPlugin()->uninstall('_blank');
}
/**
* /*
* e107::getUrl()->create('page/book/index', $row,'allow=chapter_id,chapter_sef,book_sef') ;
* e107::getUrl()->create('user/profile/view', $this->news_item)
* e107::getUrl()->create('user/profile/view', array('name' => $this->var['user_name'], 'id' => $this->var['user_id']));
* e107::getUrl()->create('page/chapter/index', $row,'allow=chapter_id,chapter_sef,book_sef') ;
* e107::getUrl()->create('user/myprofile/edit');
* e107::getUrl()->create('gallery/index/list', $this->var);
* e107::getUrl()->create('news/view/item', $row, array('full' => 1));
* e107::getUrl()->create('news/list/all'),
* e107::getUrl()->create('page/view/index',$row),
* e107::getUrl()->create('page/chapter/index', $sef),
* ($sef = $row;
* $sef['chapter_sef'] = $this->getSef($row['chapter_id']);
* $sef['book_sef'] = $this->getSef($row['chapter_parent']);)
*
* e107::getUrl()->create('news/list/tag', array('tag' => $word));
* $LINKTOFORUM = e107::getUrl()->create('forum/forum/view', array('id' => $row['thread_forum_id'])); //$e107->url->getUrl('forum', 'forum', "func=view&id={$row['thread_forum_id']}");
* e107::getUrl()->create('search');
*/
public function testUrlLegacy()
{
// set eURL config to 'Friendly'
$oldConfig = e107::getPref('url_config');
$newConfig = array(
'news' => 'core/sef_full',
'page' => 'core/sef_chapters',
'search' => 'core/rewrite',
'system' => 'core/rewrite',
'user' => 'core/rewrite',
// 'gallery' => 'plugin/rewrite'
);
$this->setUrlConfig($newConfig);
$legacyTests = array(
0 => array(
'route' => 'news/view/item',
'row' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/news/my-category/my-news-item'
),
1 => array(
'route' => 'news/view/item',
'row' => array('id' => 1, 'name' => 'my-news-item', 'category' => 'my-category'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/news/my-category/my-news-item'
),
2 => array(
'route' => 'news/list/short',
'row' => array('id' => 1, 'name' => 'my-news-item', 'category' => 'my-category'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/news/short/my-news-item'
),
3 => array(
'route' => 'news/list/tag',
'row' => array('tag' => 'myword'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/news/tag/myword'
),
4 => array(
'route' => 'search',
'row' => '',
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/search'
),
5 => array(
'route' => 'user/profile/view',
'row' => array('user_id' => 3, 'user_name' => 'john'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/user/john'
),
6 => array(
'route' => 'page/book/index',
'row' => array('chapter_id' => 2, 'chapter_sef' => 'my-book'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/page/my-book'
),
7 => array(
'route' => 'page/chapter/index',
'row' => array('chapter_id' => 2, 'chapter_sef' => 'my-chapter', 'book_sef' => 'my-book'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/page/my-book/my-chapter'
),
8 => array(
'route' => 'page/view',
'row' => array('page_id' => 3, 'page_sef' => 'my-page', 'chapter_id' => 2, 'chapter_sef' => 'my-chapter', 'book_sef' => 'my-book'),
'options' => 'full=1',
'_expected_' => 'https://localhost/e107/page/my-book/my-chapter/my-page'
),
// todo add more.
);
$e107 = $this->e107;
foreach($legacyTests as $index => $var)
{
if(empty($var['route']))
{
continue;
}
$result = $e107::url($var['route'], $var['row'], $var['options']);
$lresult = e107::getUrl()->create($var['route'], $var['row'], $var['options']);
if(empty($var['_expected_']))
{
echo $result . "\n";
echo $lresult . "\n\n";
continue;
}
$this->assertEquals($result, $lresult, "Legacy Test #" . $index . " -- e107::getUrl()->create('" . $var['route'] . "') didn't match e107::url('" . $var['route'] . "')");
$this->assertEquals($var['_expected_'], $result, 'Legacy URL index #' . $index . ' failed');
}
$this->setUrlConfig($oldConfig); // return config to previous state.
}
/**
* Save the url_config preference
* @param array $newConfig
*/
private function setUrlConfig($newConfig = array())
{
if(empty($newConfig))
{
return null;
}
$cfg = e107::getConfig();
foreach($newConfig as $k => $v)
{
$cfg->setPref('url_config/' . $k, $v);
}
$cfg->save(false, true);
/** @var eRouter $router */
$router = e107::getUrl()->router(); // e107::getSingleton('eRouter');
$rules = $router->getRuleSets();
if(empty($rules['news']) || empty($rules['page']))
{
$router->loadConfig(true);
}
}
/**
* @see https://github.com/e107inc/e107/issues/4054
*/
public function testUrlOptionQueryHasCompliantAmpersand()
{
$e107 = $this->e107;
$e107::getPlugin()->install('forum');
$url = $e107::url('forum', 'topic', [], array(
'query' => array(
'f' => 'post',
'id' => 123
),
));
$this->assertEquals(
e_PLUGIN_ABS . 'forum/forum_viewtopic.php?f=post&id=123',
$url, "Generated href does not match expectation"
);
}
public function testUrlOptionQueryUrlEncoded()
{
$e107 = $this->e107;
$e107::getPlugin()->install('forum');
$url = $e107::url('forum', 'post', [], array(
'query' => array(
"didn't" => '