old_dictionary=$dictionary; $this->old_bean_list=$bean_list; $this->test_standart_field = new TestStandardField(); $this->test_standart_field->module='Accounts'; loadBean($this->test_standart_field->module); $this->test_field=get_widget('varchar'); $this->test_field->name='name'; $this->bean_name = get_valid_bean_name($this->test_standart_field->module); } public function tearDown() { global $dictionary, $bean_list; $dictionary=$this->old_dictionary; $bean_list=$this->old_bean_list; VardefManager::clearVardef('Accounts', 'Account'); VardefManager::refreshVardefs('Accounts', 'Account'); } /** * Test different combinations of the options * * @dataProvider providerUnifiedSearchOptions */ public function testIfUnifiedSearchEnabledByDefault(array $opt_common, array $opt_field, $assert) { $this->test_field->unified_search=false; $this->setOptions($opt_common, $opt_field); $this->test_standart_field->addFieldObject($this->test_field); $this->assertEquals($assert,(boolean)$this->test_field->unified_search, "\r\n" .'Assertion error: field->unified_search should be `'.($assert ? 'true' : 'false').'` with the following vardef options:' ."\r\nvardef[][unified_search_default_enabled] " .($opt_common['unified_search_default_enabled']===-1 ? 'is undefined' : ($opt_common['unified_search_default_enabled'] ? '= true' : '= false')) ."\r\nvardef[][unified_search] " .($opt_common['unified_search']===-1 ? 'is undefined' : ($opt_common['unified_search'] ? '= true' : '= false')) ."\r\nvardef[][fields][][unified_search] " .($opt_field['unified_search']===-1 ? 'is undefined' : ($opt_field['unified_search'] ? '= true' : '= false')) ."\r\n" ); } public function providerUnifiedSearchOptions() { return array( array( 'options_common'=>array( 'unified_search_default_enabled'=>1, 'unified_search'=>1, ), 'options_field'=>array( 'unified_search'=>1, ), 'assert'=>true, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>0, 'unified_search'=>1, ), 'options_field'=>array( 'unified_search'=>1, ), 'assert'=>false, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>0, 'unified_search'=>0, ), 'options_field'=>array( 'unified_search'=>1, ), 'assert'=>false, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>0, 'unified_search'=>0, ), 'options_field'=>array( 'unified_search'=>0, ), 'assert'=>false, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>0, 'unified_search'=>1, ), 'options_field'=>array( 'unified_search'=>0, ), 'assert'=>false, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>0, 'unified_search'=>0, ), 'options_field'=>array( 'unified_search'=>1, ), 'assert'=>false, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>1, 'unified_search'=>1, ), 'options_field'=>array( 'unified_search'=>-1, ), 'assert'=>true, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>1, 'unified_search'=>-1, ), 'options_field'=>array( 'unified_search'=>1, ), 'assert'=>false, ), array( 'options_common'=>array( 'unified_search_default_enabled'=>-1, 'unified_search'=>1, ), 'options_field'=>array( 'unified_search'=>1, ), 'assert'=>false, ), ); } private function setOptions(array $opt_common, array $opt_field) { global $dictionary; $dictionary=$this->old_dictionary; if(!empty($opt_common)) { foreach($opt_common as $k=>$v) { if($v===-1) { unset($dictionary[$this->bean_name][$k]); } else { $dictionary[$this->bean_name][$k]=$v; } } } if(!empty($opt_field)) { foreach($opt_field as $k=>$v) { if($v===-1) { unset($dictionary[$this->bean_name]['fields'][$this->test_field->name][$k]); } else { $dictionary[$this->bean_name]['fields'][$this->test_field->name][$k]=$v; } } } } } /* * inherits StandardField * some methods aren't used in the test */ class TestStandardField extends StandardField { function writeVardefExtension() { } function loadCustomDef() { $this->custom_def=array(); } }