setPreference('dec_sep', ','); $current_user->setPreference('num_grp_sep', '.'); $current_user->setPreference('default_currency_significant_digits', 3); SugarTestHelper::setUp('app_list_strings'); SugarTestHelper::setUp('beanFiles'); SugarTestHelper::setUp('beanList'); parent::setUp(); $this->lm = new LayoutManager(); $this->lm->setAttribute('reporter', new stdClass()); $this->currency_51568 = new Currency(); $this->currency_51568->symbol = 'TT'; $this->currency_51568->conversion_rate = 0.5; $this->currency_51568->save(false); $this->currency_system = new Currency(); $this->currency_system->retrieve(-99); $this->backupSymbol = $this->currency_system->symbol; $this->currency_system->symbol = '¥'; $this->currency_system->save(false); $sugar_config['default_currency_symbol'] = '¥'; get_number_seperators(true); } /** * @group 51568 */ public function testFieldCurrencyPlainWithLayoutDef() { $data = array( 'currency_id' => $this->currency_51568->id, 'currency_symbol' => $this->currency_51568->symbol ); $result = $this->getResults($data); $this->assertEquals('TT100.500,000', $result); } /** * @group 51568 */ public function testFieldCurrencyPlainWithCurrencyField() { $data = array( 'fields' => array( '51568table_some_field_currency' => $this->currency_51568->id) ); $result = $this->getResults($data); $this->assertEquals('TT100.500,000', $result); } /** * @group 51568 */ public function testFieldCurrencyPlainWithAnotherCurrencyField() { $data = array( 'fields' => array( '51568TABLE_SOME_FIELD_CURRENCY' => $this->currency_51568->id) ); $result = $this->getResults($data); $this->assertEquals('TT100.500,000', $result); } /** * @group 51568 */ public function testFieldCurrencyPlainWithSystemCurrencyField() { $data = array( 'name' => 'some_field_usdoll', 'column_key' => 'self::some_field_usdoll', 'fields' => array( '51568TABLE_SOME_FIELD_USDOLL' => 100500 ) ); $result = $this->getResults($data); $this->assertEquals('¥100.500,000', $result); } /** * @group 51568 */ public function testFieldCurrencyPlainWithWrongCurrency() { $data = array( 'currency_id' => '-51568', 'currency_symbol' => '£' ); $result = $this->getResults($data); $this->assertEquals('¥100.500,000', $result); } protected function getResults($layout_def_addon) { $layout_def = array( 'column_key' => 'self::some_field', 'fields' => array( '51568TABLE_SOME_FIELD' => 100500, ), 'name' => 'some_field', 'table_key' => 'self', 'table_alias' => '51568table', 'type' => 'currency' ); foreach($layout_def_addon as $k => $v) { if(is_array($v)) { $layout_def = array_merge_recursive($layout_def, array($k => $v)); } else { $layout_def[$k] = $v; } } $sf = $this->getMock('SugarWidgetFieldCurrency', array('getTruncatedColumnAlias'), array(&$this->lm)); $sf->expects($this->any()) ->method('getTruncatedColumnAlias') ->will($this->returnArgument(0)); return $sf->displayListPlain($layout_def); } public function tearDown() { global $sugar_config; $this->currency_system->symbol = $this->backupSymbol; $this->currency_system->save(false); $sugar_config['default_currency_symbol'] = $this->backupSymbol; $this->currency_51568->mark_deleted($this->currency_51568->id); SugarTestHelper::tearDown(); get_number_seperators(true); } }