From f8b04b64d485bd9e7b3b537339c6f3528db85c06 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 7 Apr 2022 13:11:56 -0700 Subject: [PATCH] Fixes #4751 - Form tabs issue. Test added. --- e107_handlers/form_handler.php | 54 ++++++++----- e107_handlers/theme_handler.php | 2 +- e107_tests/tests/unit/e_formTest.php | 113 +++++++++++++++++---------- 3 files changed, 105 insertions(+), 64 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 9d8a1bd6b..3ec6ac8ca 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -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 =' - "; } - + $text .= "

".$tp->toHTML(TPVLAN_61, true)."

diff --git a/e107_tests/tests/unit/e_formTest.php b/e107_tests/tests/unit/e_formTest.php index 560b27cc6..8e3c84ea9 100644 --- a/e107_tests/tests/unit/e_formTest.php +++ b/e107_tests/tests/unit/e_formTest.php @@ -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('', $result); - - } + public function testHelp() + { + $result = $this->_frm->help('my tip'); + $this->assertSame('', $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 = "