";
self::assertStringContainsString($expected, $result);
$parms = ['default'=>12, 'indicators'=>false, 'navigation'=>false, 'wrap'=>false, 'interval'=>false, 'data'=>false];
$result = $this->_frm->carousel('test-carousel', $slides, $parms);
$expected = "
";
self::assertStringContainsString($expected, $result);
}
/*
public function testUrl()
{
}
*/
public function testText()
{
$result = $this->_frm->renderElement('crazy"key', "crazy'value", ['type' => 'text']);
self::assertEquals(
"
",
$result
);
}
public function testTextBadNormalizationSource()
{
$result = $this->_frm->renderElement('crazy"key', "crazy'value", ['type' => 'text']);
self::assertEquals(
"
",
$result
);
}
/*
public function testNumber()
{
}
public function testEmail()
{
}
public function testIconpreview()
{
}
public function testIconpicker()
{
}
public function testAvatarpicker()
{
}
public function testImagepicker()
{
}
public function testFilepicker()
{
}*/
public function testDatepicker()
{
$prevTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
$time = strtotime('January 1st, 2023 1am');
$actual = $this->_frm->datepicker('date_field',$time,'type=datetime&format=MM, dd, yyyy hh:ii');
$expected = "
";
self::assertEquals($expected, $actual);
// test timezone change...
date_default_timezone_set('America/Phoenix');
$actual = $this->_frm->datepicker('date_field',$time,'type=datetime&format=MM, dd, yyyy hh:ii');
$expected = "
";
self::assertEquals($expected, $actual);
date_default_timezone_set($prevTimeZone);
}
public function testUserlist()
{
$list = $this->_frm->userlist('name');
self::assertStringContainsString("
",$list);
}
/*
public function testUserpicker()
{
}
public function testRate()
{
}
public function testLike()
{
}
public function testFile()
{
}
public function testUpload()
{
}
public function testPassword()
{
}
public function testPagination()
{
}
*/
public function testProgressBar()
{
$tests = array(
0 => array('value' => '10/20', 'expected' => 'width: 50%'),
1 => array('value' => '4/5', 'expected' => 'width: 80%'),
2 => array('value' => '150/300', 'expected' => 'width: 50%'),
3 => array('value' => '30%', 'expected' => 'width: 30%'),
4 => array('value' => '30.4%', 'expected' => 'width: 30%'),
5 => array('value' => '30.5%', 'expected' => 'width: 31%'),
6 => array('value' => '0/0', 'expected' => 'width: 0%'),
);
foreach($tests as $var)
{
$result = $this->_frm->progressBar('progress', $var['value']);
self::assertStringContainsString($var['expected'],$result);
}
}
/*
public function testTextarea()
{
}
public function testBbarea()
{
}
*/
public function testCheckbox()
{
$result = $this->_frm->checkbox('name', 2, 2);
$expected = "
";
self::assertEquals($expected,$result);
}
public function testCheckboxes()
{
$opts = array(
1 => "one",
2 => "two",
3 => "three"
);
$result = $this->_frm->checkboxes('name', $opts, array(2=>'two'));
$expected = "
";
self::assertEquals($expected,$result);
$result = $this->_frm->checkboxes('name', $opts, 2, array('useKeyValues'=> 1));
$expected = "
";
self::assertEquals($expected,$result);
$result = $this->_frm->checkboxes('name', $opts, 'two', array('useLabelValues'=> 1));
$expected= "
";
self::assertEquals($expected,$result);
}
/*
public function testCheckbox_label()
{
}
public function testCheckbox_switch()
{
}
public function testCheckbox_toggle()
{
}
public function testUc_checkbox()
{
}
public function test_uc_checkbox_cb()
{
}
public function testUc_label()
{
}
public function testRadio()
{
}
public function testRadio_switch()
{
}
public function testFlipswitch()
{
}
public function testLabel()
{
}
public function testHelp()
{
}
public function testSelect_open()
{
}
public function testSelectbox()
{
}
*/
public function testSelect()
{
$this->_frm->__construct(true);
$options = array('optDisabled'=>array('opt_2'));
$selected = 'opt_3';
$opt_array = array('opt_1'=>"Option 1", 'opt_2'=>"Option 2", 'opt_3'=>"Option 3");
$actual = $this->_frm->select('name', $opt_array, $selected, $options);
$actual = str_replace("\n", "", $actual);
$expected = "
";
self::assertEquals($expected,$actual);
// test group opt-array.
$opt_array = array(
'GROUP 1' => array ('opt_1'=>"Option 1", 'opt_2'=>"Option 2", 'opt_3'=>"Option 3"),
'GROUP 2' => array ('opt_4'=>"Option 4", 'opt_5'=>"Option 5", 'opt_6'=>"Option 6"),
);
$actual = $this->_frm->select('name', $opt_array, $selected, $options);
$expected = "
";
$actual = str_replace(array("\n", "\r"), "", $actual);
$expected = str_replace(array("\n", "\r"), "", $expected);
self::assertSame($expected,$actual);
// Important - Test backward compatibility with selected value as string/integer combination, plus null default option.
$selected = '3';
$opt_array = array(1=>"Option 1", 2=>"Option 2", 3=>"Option 3");
$actual = $this->_frm->select('name', $opt_array, $selected,null,true);
$actual = str_replace("\n", "", $actual);
$expected = "
";
self::assertSame($expected,$actual);
}
/*
public function testUserclass()
{
}
public function testSearch()
{
}
*/
public function testUcSelect()
{
// 'nobody,public,main,admin,classes,matchclass,member, no-excludes'; // 255, 0, 250, 254,
$tests = array(
0 => array('value' => '', 'default'=>null, 'options'=>'nobody,public,main,admin,member,no-excludes', 'expected' => "value='255' selected"),
1 => array('value' => 0, 'default'=>null, 'options'=>'nobody,public,main,admin,member,no-excludes', 'expected' => "value='0' selected"),
2 => array('value' => '0', 'default'=>null, 'options'=>'nobody,public,main,admin,member,no-excludes', 'expected' => "value='0' selected"),
3 => array('value' => null, 'default'=>null, 'options'=>'nobody,public,main,admin,member,no-excludes', 'expected' => "value='255' selected"),
4 => array('value' => null, 'default'=>254, 'options'=>'nobody,public,main,admin,member,no-excludes', 'expected' => "value='254' selected"),
5 => array('value' => '', 'default'=>254, 'options'=>'nobody,public,main,admin,member,no-excludes', 'expected' => "value='254' selected"),
);
foreach($tests as $var)
{
$result = $this->_frm->uc_select('uc', $var['value'], $var['options'], array('default'=>$var['default']));
self::assertStringContainsString($var['expected'],$result);
}
}
public function testUc_select_single_numeric()
{
$uc_options = 'admin';
$select_options = array('multiple' => false);
$opt_options = array();
$actual = $this->_frm->uc_select('uc', 254, $uc_options, $select_options, $opt_options);
$expected = "
";
self::assertEquals($expected, $actual);
}
public function testUc_select_single_string()
{
$uc_options = 'admin';
$select_options = array('multiple' => false);
$opt_options = array();
$actual = $this->_frm->uc_select('uc', 'Admin', $uc_options, $select_options, $opt_options);
$expected = "
";
self::assertEquals($expected, $actual);
}
public function testUc_select_multi_numeric()
{
$uc_options = 'member,admin';
$select_options = array('multiple' => true);
$opt_options = array();
$actual = $this->_frm->uc_select('uc', '254,253', $uc_options, $select_options, $opt_options);
$expected = "
";
self::assertEquals($expected, $actual);
}
public function testUc_select_multi_string()
{
$uc_options = 'member,admin';
$select_options = array('multiple' => true);
$opt_options = array();
$actual = $this->_frm->uc_select('uc', 'Admin,Members', $uc_options, $select_options, $opt_options);
$expected = "
";
self::assertEquals($expected, $actual);
}
public function testUc_select_multi_mixed()
{
$uc_options = 'member,admin';
$select_options = array('multiple' => true);
$opt_options = array();
$actual = $this->_frm->uc_select('uc', 'Admin,253', $uc_options, $select_options, $opt_options);
$expected = "
";
self::assertEquals($expected, $actual);
}
/*
public function test_uc_select_cb()
{
}
public function testOptgroup_open()
{
}
*/
public function testOption()
{
$options = array('disabled'=>true);
$actual = $this->_frm->option('name','value', '', $options);
$expected = "
";
self::assertEquals($expected, $actual);
$tests = ['true'=>'True', 'false'=>'False', 'legacy'=>'Legacy'];
foreach($tests as $k=>$v)
{
$expected = "
";
$result = $this->_frm->option($v,$k);
self::assertSame($expected, $result);
}
}
public function testOption_multi()
{
$tests = array(
0 => array(
'optArray' => array ( 2 => 'Category 1', 3 => 'Category 2', 1 => 'Misc', ),
'value' => '3',
'expected' => "
",
),
1 => array(
'optArray' => array ( 'noindex' => 'NoIndex', 'nofollow' => 'NoFollow', 'noarchive' => 'NoArchive', 'noimageindex' => 'NoImageIndex', ),
'value' => array ( 0 => 'noarchive', 1 => 'noimageindex', ),
'expected' => "
",
),
2 => array(
'optArray' => array ( 'noindex' => 'NoIndex', 'nofollow' => 'NoFollow', 'noarchive' => 'NoArchive', 'noimageindex' => 'NoImageIndex', ),
'value' => '',
'expected' => "
",
),
3 => array(
'optArray' => array ( 'default' => 'Default', 'nav' => 'Nav', ),
'value' => 'default',
'expected' => "
",
),
4 => array(
'optArray' => array ( 0 => 'Default Area', 1 => 'Default Area - Title', 4 => 'Default Area - Title/Summary', 2 => 'Sidebar - Othernews', 3 => 'Sidebar - Othernews 2', 5 => 'Carousel', 6 => 'News Grid Menu', ),
'value' => array ( 0 => '1', 1 => '4', ),
'expected' => "
",
),
5 => array(
'optArray' => array ( 0 => 'Default Area', 1 => 'Default Area - Title', 4 => 'Default Area - Title/Summary', 2 => 'Sidebar - Othernews', 3 => 'Sidebar - Othernews 2', 5 => 'Carousel', 6 => 'News Grid Menu', ),
'value' => array ( 0 => ''),
'expected' => "
",
'options' => array('empty'=>'0')
),
6 => array(
'optArray' => array ( 0 => 'Default Area', 1 => 'Default Area - Title', 4 => 'Default Area - Title/Summary', 2 => 'Sidebar - Othernews', 3 => 'Sidebar - Othernews 2', 5 => 'Carousel', 6 => 'News Grid Menu', ),
'value' => '',
'expected' => "
",
'options' => array('empty'=>'0')
),
7 => array(
'optArray' => array ( 0 => 'Default Area', 1 => 'Default Area - Title', 4 => 'Default Area - Title/Summary', 2 => 'Sidebar - Othernews', 3 => 'Sidebar - Othernews 2', 5 => 'Carousel', 6 => 'News Grid Menu', ),
'value' => array ( 0 => ''),
'expected' => "
",
'options' => array('empty'=>'1')
),
8 => array(
'optArray' => array ( 0 => 'Default Area', 1 => 'Default Area - Title', 4 => 'Default Area - Title/Summary', 2 => 'Sidebar - Othernews', 3 => 'Sidebar - Othernews 2', 5 => 'Carousel', 6 => 'News Grid Menu', ),
'value' => '',
'expected' => "
",
'options' => array('empty'=>'1')
),
);
foreach($tests as $index => $row)
{
$actual = $this->_frm->option_multi($row['optArray'],$row['value'], varset($row['options'], []));
$actual = str_replace("\n", '', $actual);
self::assertSame($row['expected'], $actual, 'Test #'.$index.' failed');
}
}
/*
public function testOptgroup_close()
{
}
public function testSelect_close()
{
}
*/
public function testHidden()
{
$result = $this->_frm->hidden('name','on',['id'=>'my-field']);
self::assertSame("
", $result);
}
/*
public function testToken()
{
}
public function testSubmit()
{
}
public function testSubmit_image()
{
}
public function testAdmin_trigger()
{
}
*/
public function testButton()
{
$tests = array(
0 => array(
'name' => 'form_button',
'value' => 'go',
'action' => 'button',
'label' => '',
'options' => array('class' => 'btn-primary custom-class', 'data-my-value' => '1323')
),
1 => array(
'name' => 'form_update',
'value' => '1',
'action' => 'update',
'label' => '',
'options' => array('class' => 'btn-custom', 'data-my-value' => '365')
),
2 => array(
'name' => 'form_noaction',
'value' => 'go',
'action' => null,
'label' => '',
'options' => array( 'data-my-value' => '365')
),
3 => array(
'name' => 'form_checkall',
'value' => 1,
'action' => 'checkall',
'label' => 'Check All',
'options' => array( 'data-my-value' => '365')
),
4 => array(
'name' => 'form_submit',
'value' => 'My Label',
'action' => '',
'label' => '',
'options' => array('loading'=>false)
),
);
$expected = array (
0 => "
",
1 => "
",
2 => "
",
3 => "
",
4 => "
",
);
// $ret = [];
foreach($tests as $index => $var)
{
$result = $this->_frm->button($var['name'], $var['value'], $var['action'], $var['label'], $var['options']);
self::assertSame($expected[$index],$result, "Mismatch on #".$index);
// $ret[] = $result;
}
// var_export($ret);
}
/*
public function testBreadcrumb()
{
}
public function testInstantEditButton()
{
}
*/
public function testAdmin_button()
{
$result = $this->_frm->admin_button('update_id', "Update", 'update');
$expected = "
";
self::assertSame($expected, $result);
}
/*
public function testDefaultButtonClassExists()
{
}
public function testGetDefaultButtonClassByAction()
{
}
public function testGetNext()
{
}
public function testGetCurrent()
{
}
public function testResetTabindex()
{
}
*/
public function testGet_attributes()
{
$options = array(
'class' => 'myclass',
'id' => 'custom-id',
'readonly' => true,
'data-something' => 'custom-att'
);
$actual = $this->_frm->get_attributes($options);
$expected = " class='myclass' id='custom-id' readonly='readonly' data-something='custom-att'";
self::assertSame($expected, $actual);
}
/**
* @link https://github.com/e107inc/e107/issues/4572
*/
public function testGet_attributesOther()
{
$options = array(
'size' => '300px',
'other' => 'v-bind:class="{ active: isActive }"',
);
$actual = $this->_frm->get_attributes($options);
$expected = ' size=\'300px\' v-bind:class="{ active: isActive }"';
self::assertSame($expected, $actual);
}
/*
public function test_format_id()
{
}
*/
public function testName2id()
{
$text = "Something?hello=there and test";
$expected = 'something-hello-there-and-test';
$result = $this->_frm->name2id($text);
self::assertEquals($expected, $result);
// Test with diacritics
$text = "Façade, Jalapeño, Frappé";
$expected = 'facade-jalapeno-frappe';
$result = $this->_frm->name2id($text);
self::assertEquals($expected, $result);
}
/*
public function testFormat_options()
{
}
public function test_default_options()
{
}
public function testColumnSelector()
{
}
public function testColGroup()
{
}
public function testThead()
{
}
public function testRenderHooks()
{
}
public function testRenderRelated()
{
}
public function testRenderTableRow()
{
}
public function testRenderInline()
{
}
*/
public function testRenderValue()
{
date_default_timezone_set('America/Phoenix');
$frm = $this->_frm;
$expected = array(
'text_001' => 'some text',
'number_001' => 555,
'number_002' => "
444",
'bool_001' => constant('ADMIN_TRUE_ICON'),
'bool_002' => "
✓",
'dropdown_001' => 'Label 2',
'dropdown_002' => "Option 2",
'textarea_001' => "the quick brown fox jumps over the lazy dog",
'layout_001' => 'default',
'layout_002' => 'default',
'image_001' => "

",
'image_002' => "

",
'checkboxes_001' => 'Check Opt 2, Check Opt 3',
'country_001' => 'Australia',
'country_002' => '',
'ip_001' => "
::1",
'templates_001' => 'mytemplate',
'radio_001' => 'Radio Opt 2',
'tags_001' => 'keyword1, keyword2, keyword3',
'bbarea_001' => '
bold',
'icon_001' => "

",
'file_001' => '
{e_MEDIA_FILE}test.zip',
'files_001' => '
- {e_MEDIA_FILE}test.zip
',
'datestamp_001' => '03 Nov 2023 : 14:47',
'date_001' => '2018-08-23',
'userclass_001' => 'Everyone (public)',
'userclasses_001' => 'Everyone (public)
PRIVATEMENU',
'user_001' => 'e107',
'url_001' => "
https://e107.org",
'email_001' => "
me@email.com",
'hidden_001' => '',
// 'method_001' => 'custom-value',
'language_001' => 'French',
'userclass_002' => 'Everyone (public)',
'media_001' => '',
'dropdown_003' => '',
'dropdown_004' => '',
// 'lanlist_001' => 'German', // only works with multiple languages installed.
);
//Check Opt 2, Check Opt 3
foreach($this->_fields as $field=>$att)
{
$value = $this->_values[$field];
$result = $frm->renderValue($field, $value, $att);
/* echo "-- ".$field."-- \n";
print_r($result);
echo "\n\n";*/
if(!isset($expected[$field]))
{
$this->expectExceptionMessage('\$expected value for '.$field.' not set in script');
$this->expectExceptionMessage($result);
}
self::assertEquals($expected[$field], $result, 'Mismatch on '.$field);
}
}
public function testRenderValueInline()
{
foreach($this->_fields as $field=>$att)
{
if(isset($this->_fields[$field]['inline']))
{
continue;
}
$this->_fields[$field]['inline'] = true;
}
foreach($this->_fields as $field=>$att)
{
if($att['inline'] !== true)
{
continue;
}
$value = $this->_values[$field];
$result = $this->_frm->renderValue($field, $value, $att, 23);
if(!isset($this->_values[$field]))
{
$this->expectExceptionMessage('\$expected value for \$field not set in script');
// $this->expectExceptionMessage($result);
}
self::assertStringContainsString('data-token',$result,$field." doesn't contain 'data-token'");
}
}
public function testRenderElement()
{
$frm = $this->_frm;
$frm->__construct(true);
date_default_timezone_set('America/Phoenix');
$expected = array(
'text_001' => "
",
'number_001' => "
",
'number_002' => "
",
'bool_001' => "
",
'bool_002' => "
",
'dropdown_001' => "
",
'dropdown_002' => "
",
'textarea_001' => "
",
'layout_001' => "
",
'layout_002' => "
",
'image_001' => "

",
'image_002' => "

",
'checkboxes_001' => "
",
// 'country_001' => "
",
'ip_001' => "
",
'templates_001' => "
",
'radio_001' => "
",
//todo check tags_001 is correct.
'tags_001' => "
",
// 'bbarea_001' => '
bold',
// 'icon_001' => "

",
'file_001' => "
{e_MEDIA_FILE}test.zip",
'files_001' => "
- {e_MEDIA_FILE}test.zip
- Choose a file
- Choose a file
- Choose a file
- Choose a file
",
'datestamp_001' => "
",
'date_001' => "
",
'userclass_001' => "
",
'userclasses_001' => "
",
//todo check user_001 is correct
'user_001' => "
",
'url_001' => "
",
'email_001' => "
",
'hidden_001' => "
",
// 'method_001' => 'custom-value',
// 'language_001' => "
",
'media_001' => "
",
// Test Dropdown Multiple.
'dropdown_003' => "
",
'dropdown_004' => "
",
// 'lanlist_001' => 'German', // only works with multiple languages installed.
);
foreach($this->_fields as $field=>$att)
{
if(!isset($expected[$field]))
{
continue;
// echo $result;
// echo "\n\n";
// $this->expectExceptionMessage('\$expected value for \$field not set in script');
// $this->expectExceptionMessage($result);
}
$value = $this->_values[$field];
$result = $frm->renderElement($field, $value, $att);
$result = str_replace(array("\n", "\r"), "", $result);
// ignore tabindex.
$result = preg_replace("/tabindex='[0-9]*'/", '', $result);
$expect = preg_replace("/tabindex='[0-9]*'/", '', $expected[$field]);
self::assertEquals($expect, $result, 'Field: '.$field);
}
}
public function testRenderElementDropdown()
{
$result = $this->_frm->renderElement('dropdown_004', '', $this->_fields['dropdown_004']);
$result = str_replace(array("\n", "\r"), "", $result);
$expected = "
";
self::assertSame($expected, $result);
}
public function testRenderValueUserclassesInline()
{
$field = array('title'=>'Userclasses', 'type'=>'userclasses', 'inline'=>true);
$result = $this->_frm->renderValue('uc', 252, $field,999);
$result = str_replace(array("\n", "\r"), "", $result);
$tags = e107::getParser()->getTags($result,'a');
self::assertNotEmpty($tags['a'][0]);
$expected = array (
'class' => 'e-tip e-editable editable-click ',
'data-placement' => 'bottom',
'data-value' => ',252',
'data-name' => 'uc',
'data-source' => '[{"value":0,"text":"Everyone (public)"},{"value":252,"text":"Guests"},{"value":255,"text":"No One (inactive)"},{"value":253,"text":"Members"},{"value":254,"text":"Admin"},{"value":250,"text":"Main Admin"},{"value":249,"text":"Admins and Mods"},{"value":2,"text":"CONTACT PEOPLE"},{"value":248,"text":"Forum Moderators"},{"value":1,"text":"PRIVATEMENU"},{"value":3,"text":"NEWSLETTER"}]',
'title' => 'Edit Userclasses',
'data-type' => 'checklist',
'data-pk' => '999',
'href' => '#',
);
foreach($expected as $k=>$value)
{
self::assertSame($value, $tags['a'][0][$k], "Failed '$k' is not the same");
}
self::assertNotEmpty($tags['a'][0]['data-token']);
self::assertNotEmpty($tags['a'][0]['data-url']);
}
/*
public function testRenderListForm()
{
}
public function testRenderGridForm()
{
}
public function testRenderCreateForm()
{
}
public function testRenderCreateFieldset()
{
}
public function testRenderCreateButtonsBar()
{
}
public function testRenderForm()
{
}
public function testRenderFieldset()
{
}
public function testRenderValueTrigger()
{
}
public function testRenderElementTrigger()
{
}*/
public function testInlineTokenGeneratedOnlyOnce()
{
$class = new \ReflectionClass('e_form');
$method = $class->getMethod('inlineToken');
$method->setAccessible(true);
$results = [];
$results[] = $method->invoke($this->_frm);
$results[] = $method->invoke($this->_frm);
self::assertEquals($results[0], $results[1],
"Generated tokens differ. Watch out for performance penalty!");
}
public function testRenderLink()
{
$tests = array(
0 => array(
'value' => 'Some text',
'parms' => array('link'=>'myurl.php', 'target'=>'blank'),
'expected' => "
Some text"
),
1 => array(
'value' => 'Some text',
'parms' => array('link'=>'myurl.php?id=[id]', 'target'=>'modal'),
'expected' => "
Some text"
),
2 => array(
'value' => 'Some text',
'parms' => array('link'=>'url_001', 'target'=>'blank'),
'expected' => "
Some text"
),
3 => array(
'value' => 'Some text',
'parms' => array('link'=>'myurl.php?country=[country_001]', 'target'=>'dialog'),
'expected' => "
Some text"
),
/* 4 => array(
'value' => 'Some text',
'parms' => array('url'=>'rss', 'title'=>'Click Here'),
'expected' => "
Some text"
)*/
);
try
{
/** @var e_admin_model $model */
$model = $this->make('e_admin_model');
}
catch (Exception $e)
{
self::fail("Couldn't load e_admin_model object");
}
$model->setData($this->_values);
$model->setData('rss_url', 'rss-sefurl');
$model->setData('rss_topicid', '5');
e107::setRegistry('core/adminUI/currentListModel', $model);
e107::setRegistry('core/adminUI/currentPlugin', 'rss_menu');
foreach($tests as $t)
{
$result = $this->_frm->renderLink($t['value'], $t['parms'], 3);
self::assertEquals($t['expected'],$result);
}
}
/**
* Loads snipper from e107_themes/bootstrap/snippets/form_checkbox.html
*//*
public function testSnippet()
{
$this->_frm->_snippets = true;
$result = $this->_frm->checkbox('myname', 3, true, ['readonly'=>true]);
$expected = "
";
self::assertSame($expected, $result);
$this->_frm->_snippets = false;
}*/
}