mirror of
https://github.com/e107inc/e107.git
synced 2025-07-26 01:11:28 +02:00
Fixes #4751 - Form tabs issue. Test added.
This commit is contained in:
@@ -570,9 +570,13 @@ class e_form
|
||||
/**
|
||||
* Render Bootstrap Tabs
|
||||
*
|
||||
* @param $array
|
||||
* @param $options
|
||||
* @return string
|
||||
* @param array $array
|
||||
* @param array $options = [
|
||||
* 'active' => (string|int) - array key of the active tab.
|
||||
* 'fade' => (bool) - use fade effect or not.
|
||||
* 'class' => (string) - custom css class of the tab content container
|
||||
* ]
|
||||
* @return string html
|
||||
* @example
|
||||
* $array = array(
|
||||
* 'home' => array('caption' => 'Home', 'text' => 'some tab content' ),
|
||||
@@ -581,14 +585,23 @@ class e_form
|
||||
*/
|
||||
public function tabs($array, $options = array())
|
||||
{
|
||||
$initTab = varset($options['active'],false);
|
||||
$id = !empty($options['id']) ? 'id="'.$options['id'].'"' : '';
|
||||
$initTab = varset($options['active'], false);
|
||||
|
||||
if(is_numeric($initTab))
|
||||
{
|
||||
$initTab = 'tab-'.$initTab;
|
||||
}
|
||||
|
||||
$id = !empty($options['id']) ? 'id="'.$options['id'].'" ' : '';
|
||||
$toggle = ($this->_bootstrap > 3) ? 'data-bs-toggle="tab"' : 'data-toggle="tab"';
|
||||
|
||||
$text ='
|
||||
<!-- Nav tabs -->
|
||||
<ul '.$id.' class="nav nav-tabs">';
|
||||
<ul '.$id.'class="nav nav-tabs">';
|
||||
|
||||
$c = 0;
|
||||
|
||||
$act = $initTab;
|
||||
foreach($array as $key=>$tab)
|
||||
{
|
||||
|
||||
@@ -597,44 +610,43 @@ class e_form
|
||||
$key = 'tab-'.$key;
|
||||
}
|
||||
|
||||
if($c == 0 & $initTab == false)
|
||||
if($c === 0 && ($act === false))
|
||||
{
|
||||
$initTab = $key;
|
||||
$act = $key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$active = ($key ==$initTab) ? 'active"' : '';
|
||||
$text .= '<li class="nav-item '.$active.'"><a class="nav-link '.$active.'" href="#'.$key.'" data-toggle="tab" data-bs-toggle="tab">'.$tab['caption'].'</a></li>';
|
||||
$active = ($key == $act) ? ' active' : '';
|
||||
$text .= '<li class="nav-item'.$active.'"><a class="nav-link'.$active.'" href="#'.$key.'" '.$toggle.'>'.$tab['caption'].'</a></li>';
|
||||
$c++;
|
||||
}
|
||||
|
||||
$text .= '</ul>';
|
||||
|
||||
$initTab = varset($options['active'],false);
|
||||
$tabClass = varset($options['class'],null);
|
||||
$fade = !empty($options['fade']) ? ' fade' : '';
|
||||
$show = !empty($options['fade']) ? ($this->_bootstrap > 3 ? ' show' : ' in') : '';
|
||||
|
||||
$text .= '
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content '.$tabClass.'">';
|
||||
|
||||
$c=0;
|
||||
$act = $initTab;
|
||||
foreach($array as $key=>$tab)
|
||||
{
|
||||
|
||||
|
||||
if(is_numeric($key))
|
||||
{
|
||||
$key = 'tab-'.$key;
|
||||
}
|
||||
|
||||
if($c == 0 & $initTab == false)
|
||||
if($c == 0 && ($act === false))
|
||||
{
|
||||
$initTab = $key;
|
||||
$act = $key;
|
||||
}
|
||||
|
||||
$active = ($key == $initTab) ? ' active' : '';
|
||||
$text .= '<div class="tab-pane'.$active.'" id="'.$key.'">'.$tab['text'].'</div>';
|
||||
|
||||
$active = ($key == $act) ? $show.' active' : '';
|
||||
$text .= '<div class="tab-pane'.$fade.$active.'" id="'.$key.'" role="tabpanel">'.$tab['text'].'</div>';
|
||||
$c++;
|
||||
}
|
||||
|
||||
@@ -7679,7 +7691,7 @@ var_dump($select_options);*/
|
||||
|
||||
$query = isset($form['query']) ? $form['query'] : e_QUERY ;
|
||||
$url = (isset($form['url']) ? $this->tp->replaceConstants($form['url'], 'abs') : e_SELF).($query ? '?'.$query : '');
|
||||
$curTab = (string) varset($_GET['tab'], '0');
|
||||
$curTab = varset($_GET['tab'], false);
|
||||
|
||||
$text .= "
|
||||
<form method='post' action='".$url."' id='{$form['id']}-form' enctype='multipart/form-data' autocomplete='off' >
|
||||
@@ -7702,7 +7714,7 @@ var_dump($select_options);*/
|
||||
}
|
||||
|
||||
|
||||
$text .= $this->tabs($tabs);
|
||||
$text .= $this->tabs($tabs, ['active'=>$curTab]);
|
||||
}
|
||||
else // No Tabs Present
|
||||
{
|
||||
|
@@ -3245,7 +3245,7 @@ class themeHandler
|
||||
}
|
||||
$text .= "</ul>";
|
||||
}
|
||||
|
||||
|
||||
$text .= "
|
||||
|
||||
<p>".$tp->toHTML(TPVLAN_61, true)."</p>
|
||||
|
@@ -262,35 +262,34 @@ class e_formTest extends \Codeception\Test\Unit
|
||||
|
||||
}
|
||||
*/
|
||||
public function testGetCountry()
|
||||
{
|
||||
public function testGetCountry()
|
||||
{
|
||||
|
||||
$tests = array(
|
||||
array('value'=>'', 'expected'=>''),
|
||||
array('value'=>'au', 'expected'=>'Australia')
|
||||
);
|
||||
$tests = array(
|
||||
array('value'=>'', 'expected'=>''),
|
||||
array('value'=>'au', 'expected'=>'Australia')
|
||||
);
|
||||
|
||||
foreach($tests as $t)
|
||||
{
|
||||
$actual = $this->_frm->getCountry($t['value']);
|
||||
$this->assertEquals($t['expected'], $actual);
|
||||
}
|
||||
foreach($tests as $t)
|
||||
{
|
||||
$actual = $this->_frm->getCountry($t['value']);
|
||||
$this->assertEquals($t['expected'], $actual);
|
||||
}
|
||||
|
||||
// return array.
|
||||
$actual = $this->_frm->getCountry();
|
||||
$this->assertArrayHasKey('au',$actual);
|
||||
// return array.
|
||||
$actual = $this->_frm->getCountry();
|
||||
$this->assertArrayHasKey('au',$actual);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testHelp()
|
||||
{
|
||||
$result = $this->_frm->help('my tip');
|
||||
$this->assertSame('<i class="admin-ui-help-tip far fa-question-circle"><!-- --></i><div class="field-help" data-placement="left" style="display:none">my tip</div>', $result);
|
||||
|
||||
}
|
||||
public function testHelp()
|
||||
{
|
||||
$result = $this->_frm->help('my tip');
|
||||
$this->assertSame('<i class="admin-ui-help-tip far fa-question-circle"><!-- --></i><div class="field-help" data-placement="left" style="display:none">my tip</div>', $result);
|
||||
}
|
||||
/*
|
||||
public function testGetRequiredString()
|
||||
{
|
||||
@@ -306,32 +305,62 @@ class e_formTest extends \Codeception\Test\Unit
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testTabs()
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
public function testCarousel()
|
||||
{
|
||||
$slides = [
|
||||
1 => ['caption'=>'Slide 1', 'text'=>'slide 1'],
|
||||
2 => ['caption'=>'Slide 2', 'text' => 'slide 2'],
|
||||
3 => ['caption' => 'Slide 3', 'text'=> 'slide 3']
|
||||
];
|
||||
|
||||
$parms = ['default'=>12, 'indicators'=>false, 'navigation'=>false, 'wrap'=>true, 'interval'=>false, 'data'=>false];
|
||||
$result = $this->_frm->carousel('test-carousel', $slides, $parms);
|
||||
$expected = "<div id='test-carousel' class='carousel slide' data-ride='carousel' data-wrap='1' data-interval='0'>";
|
||||
$this->assertStringContainsString($expected, $result);
|
||||
public function testTabs()
|
||||
{
|
||||
$array = [
|
||||
0 => ['caption'=> 'Cap 0', 'text'=>'Text 0'],
|
||||
1 => ['caption'=> 'Cap 1', 'text'=>'Text 1'],
|
||||
];
|
||||
|
||||
// Test 1
|
||||
$opt = ['active'=>'1', 'fade'=>true];
|
||||
$result = $this->_frm->tabs($array,$opt);
|
||||
$this->assertStringContainsString('<a class="nav-link active" href="#tab-1"',$result, 'Test 1 Nav Failed'); // Nav
|
||||
$this->assertStringContainsString('<div class="tab-pane fade in active" id="tab-1"', $result, 'Test 1 Pane Failed'); // Pane
|
||||
|
||||
// Test 2.
|
||||
$opt = array();
|
||||
$result = $this->_frm->tabs($array,$opt);
|
||||
$this->assertStringContainsString('<a class="nav-link active" href="#tab-0"',$result, 'Test 2 Nav Failed'); // Nav
|
||||
$this->assertStringContainsString('<div class="tab-pane active" id="tab-0"', $result, 'Test 2 Pane Failed'); // Pane
|
||||
|
||||
// Test 3.
|
||||
$opt = ['active'=>'slide2'];
|
||||
$array = [
|
||||
'slide1' => ['caption'=> 'Cap 0', 'text'=>'Text 0'],
|
||||
'slide2' => ['caption'=> 'Cap 1', 'text'=>'Text 1'],
|
||||
];
|
||||
|
||||
$result = $this->_frm->tabs($array,$opt);
|
||||
$this->assertStringContainsString('<li class="nav-item active"><a class="nav-link active" href="#slide2"',$result, 'Test 3 Nav Failed'); // Nav
|
||||
$this->assertStringContainsString('<div class="tab-pane active" id="slide2"', $result, 'Test 3 Pane Failed'); // Pane
|
||||
|
||||
}
|
||||
|
||||
|
||||
$parms = ['default'=>12, 'indicators'=>false, 'navigation'=>false, 'wrap'=>false, 'interval'=>false, 'data'=>false];
|
||||
$result = $this->_frm->carousel('test-carousel', $slides, $parms);
|
||||
$expected = "<div id='test-carousel' class='carousel slide' data-ride='carousel' data-wrap='' data-interval='0'>";
|
||||
$this->assertStringContainsString($expected, $result);
|
||||
public function testCarousel()
|
||||
{
|
||||
$slides = [
|
||||
1 => ['caption'=>'Slide 1', 'text'=>'slide 1'],
|
||||
2 => ['caption'=>'Slide 2', 'text' => 'slide 2'],
|
||||
3 => ['caption' => 'Slide 3', 'text'=> 'slide 3']
|
||||
];
|
||||
|
||||
$parms = ['default'=>12, 'indicators'=>false, 'navigation'=>false, 'wrap'=>true, 'interval'=>false, 'data'=>false];
|
||||
$result = $this->_frm->carousel('test-carousel', $slides, $parms);
|
||||
$expected = "<div id='test-carousel' class='carousel slide' data-ride='carousel' data-wrap='1' data-interval='0'>";
|
||||
$this->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 = "<div id='test-carousel' class='carousel slide' data-ride='carousel' data-wrap='' data-interval='0'>";
|
||||
$this->assertStringContainsString($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
public function testUrl()
|
||||
{
|
||||
|
Reference in New Issue
Block a user