mirror of
https://github.com/e107inc/e107.git
synced 2025-08-16 03:24:20 +02:00
Tests for SEF URLs. Search page fix.
This commit is contained in:
@@ -27,7 +27,6 @@ class e107Test extends \Codeception\Test\Unit
|
||||
$this->fail("Couldn't load e107 object");
|
||||
}
|
||||
|
||||
// var_dump($this->e107);
|
||||
}
|
||||
|
||||
public function testGetInstance()
|
||||
@@ -50,6 +49,8 @@ class e107Test extends \Codeception\Test\Unit
|
||||
|
||||
$this->assertEquals('000000test', $res->site_path);
|
||||
|
||||
$this->assertEquals('/', e_HTTP);
|
||||
|
||||
}
|
||||
|
||||
public function testRenderLayout()
|
||||
@@ -887,14 +888,293 @@ class e107Test extends \Codeception\Test\Unit
|
||||
$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 testUrl()
|
||||
{
|
||||
|
||||
$obj = $this->e107;
|
||||
|
||||
$result = $obj::url('news', 'index', array(), array('mode' => 'full'));
|
||||
$tests = array(
|
||||
0 => array(
|
||||
'plugin' => 'news',
|
||||
'key' => 'index',
|
||||
'row' => '',
|
||||
'options' => ['mode' => 'full'],
|
||||
'_expected_' => 'https://localhost/e107/news'
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
$tests = array();
|
||||
|
||||
$all = e107::getAddonConfig('e_url');
|
||||
foreach($all as $plugin=>$var)
|
||||
{
|
||||
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;
|
||||
}
|
||||
$this->assertEquals($var['_expected_'], $result);
|
||||
// $this->assertEquals("https://localhost/e107/news", $result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* /*
|
||||
* 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);
|
||||
}
|
||||
|
||||
$this->assertEquals("https://localhost/e107/news", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -858,11 +858,217 @@ while($row = $sql->fetch())
|
||||
|
||||
public function testGetAllowedAttributes()
|
||||
{
|
||||
$expected = array (
|
||||
'default' =>
|
||||
array (
|
||||
0 => 'id',
|
||||
1 => 'style',
|
||||
2 => 'class',
|
||||
3 => 'title',
|
||||
4 => 'lang',
|
||||
5 => 'accesskey',
|
||||
),
|
||||
'img' =>
|
||||
array (
|
||||
0 => 'src',
|
||||
1 => 'alt',
|
||||
2 => 'width',
|
||||
3 => 'height',
|
||||
4 => 'id',
|
||||
5 => 'style',
|
||||
6 => 'class',
|
||||
7 => 'title',
|
||||
8 => 'lang',
|
||||
9 => 'accesskey',
|
||||
),
|
||||
'a' =>
|
||||
array (
|
||||
0 => 'href',
|
||||
1 => 'target',
|
||||
2 => 'rel',
|
||||
3 => 'id',
|
||||
4 => 'style',
|
||||
5 => 'class',
|
||||
6 => 'title',
|
||||
7 => 'lang',
|
||||
8 => 'accesskey',
|
||||
),
|
||||
'script' =>
|
||||
array (
|
||||
0 => 'type',
|
||||
1 => 'src',
|
||||
2 => 'language',
|
||||
3 => 'async',
|
||||
4 => 'id',
|
||||
5 => 'style',
|
||||
6 => 'class',
|
||||
7 => 'title',
|
||||
8 => 'lang',
|
||||
9 => 'accesskey',
|
||||
),
|
||||
'iframe' =>
|
||||
array (
|
||||
0 => 'src',
|
||||
1 => 'frameborder',
|
||||
2 => 'width',
|
||||
3 => 'height',
|
||||
4 => 'id',
|
||||
5 => 'style',
|
||||
6 => 'class',
|
||||
7 => 'title',
|
||||
8 => 'lang',
|
||||
9 => 'accesskey',
|
||||
),
|
||||
'input' =>
|
||||
array (
|
||||
0 => 'type',
|
||||
1 => 'name',
|
||||
2 => 'value',
|
||||
3 => 'id',
|
||||
4 => 'style',
|
||||
5 => 'class',
|
||||
6 => 'title',
|
||||
7 => 'lang',
|
||||
8 => 'accesskey',
|
||||
),
|
||||
'form' =>
|
||||
array (
|
||||
0 => 'action',
|
||||
1 => 'method',
|
||||
2 => 'target',
|
||||
3 => 'id',
|
||||
4 => 'style',
|
||||
5 => 'class',
|
||||
6 => 'title',
|
||||
7 => 'lang',
|
||||
8 => 'accesskey',
|
||||
),
|
||||
'audio' =>
|
||||
array (
|
||||
0 => 'src',
|
||||
1 => 'controls',
|
||||
2 => 'autoplay',
|
||||
3 => 'loop',
|
||||
4 => 'muted',
|
||||
5 => 'preload',
|
||||
6 => 'id',
|
||||
7 => 'style',
|
||||
8 => 'class',
|
||||
9 => 'title',
|
||||
10 => 'lang',
|
||||
11 => 'accesskey',
|
||||
),
|
||||
'video' =>
|
||||
array (
|
||||
0 => 'autoplay',
|
||||
1 => 'controls',
|
||||
2 => 'height',
|
||||
3 => 'loop',
|
||||
4 => 'muted',
|
||||
5 => 'poster',
|
||||
6 => 'preload',
|
||||
7 => 'src',
|
||||
8 => 'width',
|
||||
9 => 'id',
|
||||
10 => 'style',
|
||||
11 => 'class',
|
||||
12 => 'title',
|
||||
13 => 'lang',
|
||||
14 => 'accesskey',
|
||||
),
|
||||
'td' =>
|
||||
array (
|
||||
0 => 'colspan',
|
||||
1 => 'rowspan',
|
||||
2 => 'id',
|
||||
3 => 'style',
|
||||
4 => 'class',
|
||||
5 => 'title',
|
||||
6 => 'lang',
|
||||
7 => 'accesskey',
|
||||
),
|
||||
'th' =>
|
||||
array (
|
||||
0 => 'colspan',
|
||||
1 => 'rowspan',
|
||||
2 => 'id',
|
||||
3 => 'style',
|
||||
4 => 'class',
|
||||
5 => 'title',
|
||||
6 => 'lang',
|
||||
7 => 'accesskey',
|
||||
),
|
||||
'col' =>
|
||||
array (
|
||||
0 => 'span',
|
||||
1 => 'id',
|
||||
2 => 'style',
|
||||
3 => 'class',
|
||||
4 => 'title',
|
||||
5 => 'lang',
|
||||
6 => 'accesskey',
|
||||
),
|
||||
'embed' =>
|
||||
array (
|
||||
0 => 'src',
|
||||
1 => 'wmode',
|
||||
2 => 'type',
|
||||
3 => 'width',
|
||||
4 => 'height',
|
||||
5 => 'id',
|
||||
6 => 'style',
|
||||
7 => 'class',
|
||||
8 => 'title',
|
||||
9 => 'lang',
|
||||
10 => 'accesskey',
|
||||
),
|
||||
'x-bbcode' =>
|
||||
array (
|
||||
0 => 'alt',
|
||||
1 => 'id',
|
||||
2 => 'style',
|
||||
3 => 'class',
|
||||
4 => 'title',
|
||||
5 => 'lang',
|
||||
6 => 'accesskey',
|
||||
),
|
||||
'label' =>
|
||||
array (
|
||||
0 => 'for',
|
||||
1 => 'id',
|
||||
2 => 'style',
|
||||
3 => 'class',
|
||||
4 => 'title',
|
||||
5 => 'lang',
|
||||
6 => 'accesskey',
|
||||
),
|
||||
'source' =>
|
||||
array (
|
||||
0 => 'media',
|
||||
1 => 'sizes',
|
||||
2 => 'src',
|
||||
3 => 'srcset',
|
||||
4 => 'type',
|
||||
5 => 'id',
|
||||
6 => 'style',
|
||||
7 => 'class',
|
||||
8 => 'title',
|
||||
9 => 'lang',
|
||||
10 => 'accesskey',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$result = $this->tp->getAllowedAttributes();
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$true = is_array($result) && in_array('style',$result['img']);
|
||||
|
||||
$this->assertTrue($true);
|
||||
// var_export($result);
|
||||
// $true = is_array($result) && in_array('style',$result['img']);
|
||||
|
||||
// $this->assertTrue($true);
|
||||
}
|
||||
/*
|
||||
public function testSetScriptTags()
|
||||
|
@@ -1471,11 +1471,6 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
|
||||
// echo "\n".$shortcode."\n";
|
||||
$result = $tp->parseTemplate($shortcode,true);
|
||||
|
||||
if($name === 'search')
|
||||
{
|
||||
echo $result."\n\n";
|
||||
}
|
||||
|
||||
if(isset($parms[$name]) && $name !== 'user_extended')
|
||||
{
|
||||
$this->assertNotEmpty($result, $shortcode." returned nothing!");
|
||||
|
Reference in New Issue
Block a user