public function testGetControlCurrencyList() { global $app_strings; $html = getControl('Opportunities', 'currency_id'); $focus = loadBean('Opportunities'); require_once 'modules/Opportunities/Opportunity.php'; $string = str_ireplace('</select>', '<option value="">' . $app_strings['LBL_NONE'] . '</option></select>', getCurrencyDropDown($focus, 'currency_id', '', 'EditView')); $this->assertContains($string, $html, "Failed to find string '{$string}' in '{$html}'"); $string = "<script>function CurrencyConvertAll() { return; }</script>"; $this->assertContains($string, $html, "Failed to find string '{$string}' in '{$html}'"); }
public function testgetCurrencyDropDown() { //test with view = Default / DetailView $this->assertEquals('US Dollars', getCurrencyDropDown($focus)); //test with view = EditView $expected = "<select name=\"currency_id\" id=\"currency_id_select\" onchange=\"CurrencyConvertAll(this.form);\"><option value=\"-99\" selected>US Dollars : \$</select><script>var ConversionRates = new Array(); \nvar CurrencySymbols = new Array(); \nvar lastRate = \"1\"; ConversionRates['-99'] = '1';\n CurrencySymbols['-99'] = '\$';\nvar currencyFields = [];\n\t\t\t\t\tfunction get_rate(id){\n\t\t\t\t\t\treturn ConversionRates[id];\n\t\t\t\t\t}\n\t\t\t\t\tfunction ConvertToDollar(amount, rate){\n\t\t\t\t\t\treturn amount / rate;\n\t\t\t\t\t}\n\t\t\t\t\tfunction ConvertFromDollar(amount, rate){\n\t\t\t\t\t\treturn amount * rate;\n\t\t\t\t\t}\n\t\t\t\t\tfunction ConvertRate(id,fields){\n\t\t\t\t\t\t\tfor(var i = 0; i < fields.length; i++){\n\t\t\t\t\t\t\t\tfields[i].value = toDecimal(ConvertFromDollar(toDecimal(ConvertToDollar(toDecimal(fields[i].value), lastRate)), ConversionRates[id]));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlastRate = ConversionRates[id];\n\t\t\t\t\t\t}\n\t\t\t\t\tfunction ConvertRateSingle(id,field){\n\t\t\t\t\t\tvar temp = field.innerHTML.substring(1, field.innerHTML.length);\n\t\t\t\t\t\tunformattedNumber = unformatNumber(temp, num_grp_sep, dec_sep);\n\t\t\t\t\t\t\n\t\t\t\t\t\tfield.innerHTML = CurrencySymbols[id] + formatNumber(toDecimal(ConvertFromDollar(ConvertToDollar(unformattedNumber, lastRate), ConversionRates[id])), num_grp_sep, dec_sep, 2, 2);\n\t\t\t\t\t\tlastRate = ConversionRates[id];\n\t\t\t\t\t}\n\t\t\t\t\tfunction CurrencyConvertAll(form){\n try {\n var id = form.currency_id.options[form.currency_id.selectedIndex].value;\n\t\t\t\t\t\tvar fields = new Array();\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor(i in currencyFields){\n\t\t\t\t\t\t\tvar field = currencyFields[i];\n\t\t\t\t\t\t\tif(typeof(form[field]) != 'undefined'){\n\t\t\t\t\t\t\t\tform[field].value = unformatNumber(form[field].value, num_grp_sep, dec_sep);\n\t\t\t\t\t\t\t\tfields.push(form[field]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tConvertRate(id, fields);\n\t\t\t\t\t\tfor(i in fields){\n\t\t\t\t\t\t\tfields[i].value = formatNumber(fields[i].value, num_grp_sep, dec_sep);\n\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t} catch (err) {\n // Do nothing, if we can't find the currency_id field we will just not attempt to convert currencies\n // This typically only happens in lead conversion and quick creates, where the currency_id field may be named somethnig else or hidden deep inside a sub-form.\n }\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t</script>"; $actual = getCurrencyDropDown($focus, 'currency_id', '', 'EditView'); $this->assertSame($expected, $actual); }