array('title'=> "Text 001", 'type' => 'text', 'writeParms'=>array('size'=>'xlarge')), // 'text_002' etc.. add other configurations with type='text' in here. 'number_001' => array('title'=> "Number 001", 'type' => 'number', 'writeParms'=>array('min'=>0)), // 'number_002' => array('title'=> "Number 002", 'type' => 'number', 'inline'=>true, 'writeParms'=>array('min'=>0)), 'bool_001' => array('title'=> "Bool 001", 'type' => 'bool', 'writeParms'=>array('size'=>'xlarge')), // 'bool_002' => array('title'=> "Bool 002", 'type' => 'bool', 'inline'=>true, 'writeParms'=>array('size'=>'xlarge')), 'dropdown_001' => array('title'=>'Dropdown 001', 'type'=>'dropdown', 'tab'=>1, 'writeParms' => array('optArray'=>array('opt_value_1'=>'Label 1', 'opt_value_2'=>'Label 2')) ), 'dropdown_002' => array( 'title' => 'Dropdown 002', 'type' => 'dropdown', 'width' => 'auto', 'readonly' => false, 'filter' => true, 'thclass' => 'center', 'class' => 'center', 'writeParms' => array( 'empty' => 0, 'optArray' => array( 0 => "Option 0", 1 => "Option 1", 2 => "Option 2" ), ), 'readParms' => array( 'optArray' => array( 0 => "Option 0", 1 => "Option 1", 2 => "Option 2" ), ), 'tab' => 0, ), 'textarea_001' => array('title'=> "Textarea 001", 'type' => 'textarea', 'writeParms'=>array('size'=>'xlarge','rows'=> 5)), 'layout_001' => array ( 'title' => 'Layouts 001', 'type' => 'layouts', 'writeParms' => 'plugin=news&id=news_view&merge=1' ), // 'news', 'news_view', 'front' 'layout_002' => array ( 'title' => 'Layouts 002', 'type' => 'layouts', 'writeParms'=>array('plugin'=>'news', 'id'=>'news_view', 'area'=> 'front', 'merge'=>false)), // 'news', 'news_view', 'front' 'image_001' => array('title'=>"Image 001", 'type' => 'image', 'inline'=>false, 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60&legacyPath={e_FILE}downloadimages', 'readonly'=>TRUE, 'batch' => FALSE, 'filter'=>FALSE), 'image_002' => array('title'=>"Image 002", 'type' => 'image', 'inline'=>false, 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60&legacyPath={e_FILE}downloadimages', 'readonly'=>TRUE, 'batch' => FALSE, 'filter'=>FALSE), 'checkboxes_001' => array('title'=>'Checkboxes', 'type'=>'checkboxes', 'writeParms'=>array('optArray'=>array(1=>'Check Opt 1', 2=>'Check Opt 2', 3=>'Check Opt 3'))), 'country_001' => array('title'=>'Country', 'type'=>'country'), 'ip_001' => array('title'=>'IP', 'type'=>'ip', 'inline'=>false), 'templates_001' => array('title'=>'Templates', 'type'=>'templates', 'writeParms'=>array('plugin'=>'forum')), 'radio_001' => array('title'=>'Radio', 'type'=>'radio', 'writeParms'=>array('optArray'=>array(1=>'Radio Opt 1', 2=>'Radio Opt 2', 3=>'Radio Opt 3'))), 'tags_001' => array('title'=>'Tags', 'type'=>'tags'), 'bbarea_001' => array('title'=>'BBarea', 'type'=>'bbarea', 'inline'=>false), 'icon_001' => array('title'=>'Icon', 'type'=>'icon', 'inline'=>false), // 'media_001' => array('title'=>'Media', 'type'=>'media', 'inline'=>false), // 'file_001' => array('title'=>'File', 'type'=>'file', 'inline'=>false), //FIXME // 'files_001' => array('title'=>'File', 'type'=>'files', 'inline'=>false), //FIXME 'datestamp_001' => array('title'=>'Datestamp', 'type'=>'datestamp', 'inline'=>false), 'date_001' => array('title'=>'Date', 'type'=>'date'), 'userclass_001' => array('title'=>'Userclass', 'type'=>'userclass'), 'userclasses_001' => array('title'=>'Userclasses', 'type'=>'userclasses'), 'user_001' => array('title'=>'User', 'type'=>'user'), 'url_001' => array('title'=>'URL', 'type'=>'url', 'inline'=>false), 'email_001' => array('title'=>'Email', 'type'=>'email', 'inline'=>false), 'hidden_001' => array('title'=>'Hidden', 'type'=>'hidden', 'inline'=>false), // 'method_001' => array('title'=>'Method' , 'type'=>'method', 'inline'=>false), 'language_001' => array('title'=>'Language' , 'type'=>'language'), // 'lanlist_001' => array('title'=>'Lanlist' , 'type'=>'lanlist', 'inline'=>false), ); // simulated database/form values. protected $_values = array( 'text_001' => 'some text', 'number_001' => 555, 'number_002' => 444, 'bool_001' => 1, 'bool_002' => 1, 'dropdown_001' => 'opt_value_2', 'dropdown_002' => '1,2', 'textarea_001' => "the quick brown fox jumps over the lazy dog", 'layout_001' => 'default', 'layout_002' => 'default', 'image_001' => '{e_THEME}bootstrap3/images/e107_adminlogo.png', 'image_002' => 'butterfly.jpg', 'checkboxes_001' => '2,3', 'country_001' => 'au', 'ip_001' => '::1', 'templates_001' => 'mytemplate', 'radio_001' => 2, 'tags_001' => 'keyword1,keyword2,keyword3', 'bbarea_001' => '[html]bold[/html]', 'icon_001' => '{e_IMAGE}e107_icon_32.png', // 'media_001' => '', // TODO - saves as json format. 'file_001' => '{e_MEDIA_FILE}test.zip', // 'files_001' => '{e_MEDIA_FILE}test.zip', 'datestamp_001' => 1454367600, 'date_001' => '2018-08-23', 'userclass_001' => 0, 'userclasses_001' => '0,1', 'user_001' => 1, 'url_001' => 'https://e107.org', 'email_001' => 'me@email.com', 'hidden_001' => 'hidden-value', 'method_001' => 'custom-value', 'language_001' => 'fr', // 'lanlist_001' => 'German', ); protected function _before() { try { $this->_frm = $this->make('e_form'); $this->_frm->__construct(); } catch (Exception $e) { $this->assertTrue(false, "Couldn't load e_form object"); } $legacyDir = APP_PATH."/e107_files/downloadimages/"; $legacyFile = APP_PATH."/e107_files/downloadimages/butterfly.jpg"; if(!is_dir($legacyDir)) { mkdir($legacyDir, 0775, true); } if(!file_exists($legacyFile)) { copy(APP_PATH."/e107_plugins/gallery/images/butterfly.jpg", $legacyFile); } if(!file_exists($legacyFile)) { $this->assertTrue(false,"Couldn't copy legacy image 'butterfly.jpg' to e107_files folder"); } } protected function _after() { unlink(APP_PATH."/e107_files/downloadimages/butterfly.jpg"); } /* public function testAddWarning() { } public function testOpen() { } public function testClose() { } public function testCountry() { } public function testGetCountry() { } public function testGetRequiredString() { } public function testSetRequiredString() { } public function testTags() { } public function testTabs() { } public function testCarousel() { } public function testUrl() { } public function testText() { } public function testNumber() { } public function testEmail() { } public function testIconpreview() { } public function testIconpicker() { } public function testAvatarpicker() { } public function testImagepicker() { } public function testFilepicker() { }*/ public function testDatepicker() { date_default_timezone_set('UTC'); $time = strtotime('January 1st, 2018 1am'); $actual = $this->_frm->datepicker('date_field',$time,'type=datetime&format=MM, dd, yyyy hh:ii'); $expected = ""; $this->assertEquals($expected, $actual); // test timezone change... date_default_timezone_set('America/Los_Angeles'); $actual = $this->_frm->datepicker('date_field',$time,'type=datetime&format=MM, dd, yyyy hh:ii'); $expected = ""; $this->assertEquals($expected, $actual); } /* public function testUserlist() { } public function testUserpicker() { } public function testRate() { } public function testLike() { } public function testFile() { } public function testUpload() { } public function testPassword() { } public function testPagination() { } public function testProgressBar() { } public function testTextarea() { } public function testBbarea() { } public function testCheckbox() { } public function testCheckboxes() { } 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 = ""; $this->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); $this->assertEquals($expected,$actual); } /* public function testUserclass() { } public function testSearch() { } */ 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 = ""; $this->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 = ""; $this->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 = ""; $this->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 = ""; $this->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 = ""; $this->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 = ""; $this->assertEquals($expected, $actual); } /* public function testOption_multi() { } public function testOptgroup_close() { } public function testSelect_close() { } public function testHidden() { } public function testToken() { } public function testSubmit() { } public function testSubmit_image() { } public function testAdmin_trigger() { } public function testButton() { } public function testBreadcrumb() { } public function testInstantEditButton() { } public function testAdmin_button() { } public function testDefaultButtonClassExists() { } public function testGetDefaultButtonClassByAction() { } public function testGetNext() { } public function testGetCurrent() { } public function testResetTabindex() { } public function testGet_attributes() { } public function test_format_id() { } public function testName2id() { } 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/Los_Angeles'); $frm = $this->_frm; $expected = array( 'text_001' => 'some text', 'number_001' => 555, 'number_002' => "444", 'bool_001' => ADMIN_TRUE_ICON, 'bool_002' => "", 'dropdown_001' => 'Label 2', 'dropdown_002' => "", 'textarea_001' => "the quick brown fox jumps over the lazy dog", 'layout_001' => 'default', 'layout_002' => 'default', 'image_001' => "\"e107_adminlogo.png\"", 'image_002' => "\"butterfly.jpg\"", 'checkboxes_001' => 'Check Opt 2, Check Opt 3', 'country_001' => 'Australia', 'ip_001' => "::1", 'templates_001' => 'mytemplate', 'radio_001' => 'Radio Opt 2', 'tags_001' => 'keyword1, keyword2, keyword3', 'bbarea_001' => 'bold', 'icon_001' => "e107_icon_32.png", 'media_001' => '', // 'file_001' => '{e_MEDIA_FILE}test.zip', // 'files_001' => '{e_MEDIA_FILE}test.zip', 'datestamp_001' => '01 Feb 2016 : 15:00', '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', // '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); } $this->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); } $this->assertContains('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' => "\"e107_adminlogo.png\"", 'image_002' => "\"butterfly.jpg\"", 'checkboxes_001' => "
", 'country_001' => "", 'ip_001' => "", 'templates_001' => "", 'radio_001' => " ", //todo check tags_001 is correct. 'tags_001' => "", // 'bbarea_001' => 'bold', // 'icon_001' => "e107_icon_32.png", // 'media_001' => '', // 'file_001' => '{e_MEDIA_FILE}test.zip', // 'files_001' => '{e_MEDIA_FILE}test.zip', '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' => "", // 'lanlist_001' => 'German', // only works with multiple languages installed. ); foreach($this->_fields as $field=>$att) { $value = $this->_values[$field]; $result = $frm->renderElement($field, $value, $att); $result = str_replace("\n", "", $result); if(empty($expected[$field])) { continue; // echo $result; // echo "\n\n"; // $this->expectExceptionMessage('\$expected value for \$field not set in script'); // $this->expectExceptionMessage($result); } $this->assertEquals($expected[$field], $result); } } /* 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); $this->assertEquals($results[0], $results[1], "Generated tokens differ. Watch out for performance penalty!"); } }