Пример #1
0
 public function testSaveNumericFields()
 {
     global $current_user;
     require_once 'modules/SavedSearch/SavedSearch.php';
     $focus = new SavedSearch();
     $focus->retrieve($this->saved_search_id);
     $_REQUEST = unserialize(base64_decode($focus->contents));
     $_REQUEST['start_range_amount_advanced'] = '$9,500.00';
     $_REQUEST['end_range_amount_advanced'] = '$49,500.00';
     $mockBean = new Bug42915MockOpportunity();
     $focus->handleSave('', false, '', $this->saved_search_id, $mockBean);
     //Now retrieve what we have saved and test
     $focus->retrieveSavedSearch($this->saved_search_id);
     $formatted_data = $focus->contents;
     $this->assertEquals(9500, $formatted_data['start_range_amount_advanced'], "Assert that value is unformatted value 9500");
     $this->assertEquals(49500, $formatted_data['end_range_amount_advanced'], "Assert that value is unformatted value 49500");
     $focus->populateRequest();
     $this->assertEquals('$9,500.00', $_REQUEST['start_range_amount_advanced'], "Assert that value is formatted value \$9,500.00");
     $this->assertEquals('$49,500.00', $_REQUEST['end_range_amount_advanced'], "Assert that value is formatted value \$49,500.00");
     $current_user->setPreference('num_grp_sep', '.');
     $current_user->setPreference('dec_sep', ',');
     $current_user->save();
     //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
     get_number_seperators(true);
     $focus = new SavedSearch();
     $focus->retrieveSavedSearch($this->saved_search_id);
     $focus->populateRequest();
     $this->assertEquals('$9.500,00', $_REQUEST['start_range_amount_advanced'], "Assert that value is formatted value \$9,500.00");
     $this->assertEquals('$49.500,00', $_REQUEST['end_range_amount_advanced'], "Assert that value is formatted value \$49,500.00");
     //Okay so now what happens if they don't specify currency or separator or decimal values?
     $_REQUEST['start_range_amount_advanced'] = '9500';
     $_REQUEST['end_range_amount_advanced'] = '49500';
     //Well then the populated values should be unformatted!
     $focus->handleSave('', false, '', $this->saved_search_id, $mockBean);
     $focus->retrieveSavedSearch($this->saved_search_id);
     $focus->populateRequest();
     $this->assertEquals(9500, $_REQUEST['start_range_amount_advanced'], "Assert that value is unformatted value 9500");
     $this->assertEquals(49500, $_REQUEST['end_range_amount_advanced'], "Assert that value is unformatted value 49500");
 }
Пример #2
0
 /**
  * This test captures the scenario for date_modified field where range search is not enabled
  */
 public function testSaveDateFields()
 {
     require_once 'modules/SavedSearch/SavedSearch.php';
     $focus = new SavedSearch();
     $focus->retrieve($this->saved_search_id);
     $_REQUEST = unserialize(base64_decode($focus->contents));
     unset($_REQUEST['start_range_date_modified_advanced']);
     unset($_REQUEST['end_range_date_modified_advanced']);
     unset($_REQUEST['range_date_modified_advanced']);
     $_REQUEST['date_modified_advanced'] = '07/03/2009';
     //Special date :)
     $mockBean = new Bug42377MockOpportunity();
     $focus->handleSave('', false, '', $this->saved_search_id, $mockBean);
     //Now retrieve what we have saved and test
     $focus = new SavedSearch();
     $focus->retrieve($this->saved_search_id);
     $formatted_data = unserialize(base64_decode($focus->contents));
     $this->assertEquals($formatted_data['date_modified_advanced'], '2009-07-03', "Assert that value is in db format ('2009-07-03')");
     //Now test that when we populate the search form, we bring it back to user's date format
     $focus->retrieveSavedSearch($this->saved_search_id);
     $focus->populateRequest();
     $this->assertEquals($_REQUEST['date_modified_advanced'], '07/03/2009', "Assert that dates in db format were converted back to user's date preference");
     //Take this a step further, assume date format now changes, will date be populated correctly?
     global $current_user;
     $current_user->setPreference('datef', 'd/m/Y', 0, 'global');
     $current_user->save();
     //Now test that when we populate the search form, we bring it back to user's date format
     $focus->retrieveSavedSearch($this->saved_search_id);
     $focus->populateRequest();
     $this->assertEquals($_REQUEST['date_modified_advanced'], '03/07/2009', "Assert that dates in db format were converted back to user's date preference");
 }
Пример #3
0
 public function testpopulateRequest()
 {
     $savedSearch = new SavedSearch();
     $savedSearch->contents = array('search_module' => 'Accounts', 'description' => 'test text', 'test_content' => 'some content', 'advanced' => true);
     $savedSearch->populateRequest();
     //verify thhat Request parameters are set
     $this->assertEquals('Accounts', $_REQUEST['search_module']);
     $this->assertEquals('test text', $_REQUEST['description']);
     $this->assertEquals('some content', $_REQUEST['test_content']);
 }