diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 59ea807de..f940ae414 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -920,6 +920,7 @@ class news_admin_ui extends e_admin_ui $this->fields['news_category']['writeParms']['size'] = 'xlarge'; $this->fields['news_render_type']['writeParms']['optArray'] = $this->news_renderTypes; // array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2","Featurebox"); $this->fields['news_render_type']['writeParms']['multiple'] = 1; + $this->fields['news_render_type']['writeParms']['empty'] = '0'; $this->fields['news_meta_robots']['writeParms']['optArray'] = e107::getSingleton('eResponse')->getRobotTypes(); $this->fields['news_meta_robots']['writeParms']['title'] = e107::getSingleton('eResponse')->getRobotDescriptions(); diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 59e4d4e42..14cd84971 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -3488,9 +3488,15 @@ var_dump($select_options);*/ $opts = $options; - if($selected === array(0=>'')) // quick fix. @see github issue #4609 + if(isset($options['empty']) && (empty($selected) || $selected === array(0=>''))) { - $selected = 0; + $selected = $options['empty']; + } + + + if($selected === array(0=>'') ) // quick fix. @see github issue #4609 + { + // $selected = 0; } foreach ((array) $option_array as $value => $label) @@ -6746,7 +6752,7 @@ var_dump($select_options);*/ $eloptions['multiple'] = true; } unset($parms['__options']); - if(!empty($eloptions['multiple']) && !is_array($value) && !empty($value)) + if(!empty($eloptions['multiple']) && !is_array($value)) { $value = explode(',', $value); } diff --git a/e107_tests/tests/unit/e_formTest.php b/e107_tests/tests/unit/e_formTest.php index 68f707c00..560b27cc6 100644 --- a/e107_tests/tests/unit/e_formTest.php +++ b/e107_tests/tests/unit/e_formTest.php @@ -96,7 +96,7 @@ class e_formTest extends \Codeception\Test\Unit 'media_001' => array('title'=>'Media', 'type'=>'media', 'data'=>'json', 'inline'=>false), - 'dropdown_003' => array ( 'title' => 'Location', 'type' => 'dropdown', 'data' => 'safestr', 'tab' => 2, 'inline' => false, 'readParms' => array ( 'type' => 'checkboxes', ), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch' => true, 'filter' => true, 'table' => 'news', 'alias' => 'n.news_render_type', 'field' => 'news_render_type', '__tableField' => 'n.news_render_type', '__tableFrom' => '`#news`.news_render_type AS n.news_render_type', 'writeParms' => 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', ), 'multiple' => 1, ), ), + 'dropdown_003' => array ( 'title' => 'Location', 'type' => 'dropdown', 'data' => 'safestr', 'tab' => 2, 'inline' => false, 'readParms' => array ( 'type' => 'checkboxes', ), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch' => true, 'filter' => true, 'table' => 'news', 'alias' => 'n.news_render_type', 'field' => 'news_render_type', '__tableField' => 'n.news_render_type', '__tableFrom' => '`#news`.news_render_type AS n.news_render_type', 'writeParms' => 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', ), 'multiple' => 1, 'empty'=>'0' ), ), 'dropdown_004' => array ( 'title' => 'Robots', 'type' => 'dropdown', 'data' => 'safestr', 'tab' => 1, 'inline' => false, 'readParms' => array ( 'type' => 'checkboxes', ), 'writeParms' => array ( 'multiple' => 1, 'optArray' => array ( 'noindex' => 'NoIndex', 'nofollow' => 'NoFollow', 'noarchive' => 'NoArchive', 'noimageindex' => 'NoImageIndex', ), 'title' => array ( 'noindex' => 'Prevent search engines from indexing this item.', 'nofollow' => 'Prevent search engines from following links in this item.', 'noarchive' => 'Prevent cached copies of this item from appearing in search results.', 'noimageindex' => 'Prevent search engines from indexing images of this item.', ), ), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch' => true, 'filter' => true, 'table' => 'news', 'alias' => 'n.news_meta_robots', 'field' => 'news_meta_robots', '__tableField' => 'n.news_meta_robots', '__tableFrom' => '`#news`.news_meta_robots AS n.news_meta_robots', ) , @@ -756,35 +756,64 @@ class e_formTest extends \Codeception\Test\Unit { $tests = array( 0 => array( - 'options' => array ( 2 => 'Category 1', 3 => 'Category 2', 1 => 'Misc', ), + 'optArray' => array ( 2 => 'Category 1', 3 => 'Category 2', 1 => 'Misc', ), 'value' => '3', 'expected' => "", ), 1 => array( - 'options' => array ( 'noindex' => 'NoIndex', 'nofollow' => 'NoFollow', 'noarchive' => 'NoArchive', 'noimageindex' => 'NoImageIndex', ), + 'optArray' => array ( 'noindex' => 'NoIndex', 'nofollow' => 'NoFollow', 'noarchive' => 'NoArchive', 'noimageindex' => 'NoImageIndex', ), 'value' => array ( 0 => 'noarchive', 1 => 'noimageindex', ), 'expected' => "", ), 2 => array( - 'options' => array ( 'default' => 'Default', 'nav' => 'Nav', ), + 'optArray' => array ( 'noindex' => 'NoIndex', 'nofollow' => 'NoFollow', 'noarchive' => 'NoArchive', 'noimageindex' => 'NoImageIndex', ), + 'value' => '', + 'expected' => "", + + ), + + 3 => array( + 'optArray' => array ( 'default' => 'Default', 'nav' => 'Nav', ), 'value' => 'default', 'expected' => "", ), - 3 => array( - 'options' => 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', ), + 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' => "", ), - 4 => array( - 'options' => 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', ), + 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') ), @@ -792,7 +821,7 @@ class e_formTest extends \Codeception\Test\Unit foreach($tests as $index => $row) { - $actual = $this->_frm->option_multi($row['options'],$row['value']); + $actual = $this->_frm->option_multi($row['optArray'],$row['value'], varset($row['options'], [])); $actual = str_replace("\n", '', $actual); $this->assertSame($row['expected'], $actual, 'Test #'.$index.' failed'); } @@ -1234,6 +1263,19 @@ class e_formTest extends \Codeception\Test\Unit } + + public function testRenderElementDropdown() + { + + + $result = $this->_frm->renderElement('dropdown_004', '', $this->_fields['dropdown_004']); + + $result = str_replace(array("\n", "\r"), "", $result); + + $expected = ""; + + $this->assertSame($expected, $result); + } /* public function testRenderListForm() {