1--TEST-- 2numfmt_get/set_text_attribute() 3--SKIPIF-- 4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> 5--FILE-- 6<?php 7 8/* 9 * Get/set text attribute. 10 */ 11 12 13function ut_main() 14{ 15 // Array with data for testing 16 $long_str = str_repeat('blah', 100); 17 $attributes = array( 18 'POSITIVE_PREFIX' => array( NumberFormatter::POSITIVE_PREFIX, '_+_', 12345.1234 ), 19 'POSITIVE_SUFFIX' => array( NumberFormatter::POSITIVE_SUFFIX, '_+_', 12345.1234 ), 20 'NEGATIVE_PREFIX' => array( NumberFormatter::NEGATIVE_PREFIX, '_-_', -12345.1234 ), 21 'NEGATIVE_SUFFIX' => array( NumberFormatter::NEGATIVE_SUFFIX, '_-_', -12345.1234 ), 22 'PADDING_CHARACTER' => array( NumberFormatter::PADDING_CHARACTER, '^', 12345.1234 ), 23 'POSITIVE_PREFIX-2' => array( NumberFormatter::POSITIVE_PREFIX, $long_str, 12345.1234 ), 24// 'CURRENCY_CODE' => array( NumberFormatter::CURRENCY_CODE, '_C_', 12345.1234 ) 25// 'DEFAULT_RULESET' => array( NumberFormatter::DEFAULT_RULESET, '_DR_', 12345.1234 ), 26// 'PUBLIC_RULESETS' => array( NumberFormatter::PUBLIC_RULESETS, '_PR_', 12345.1234 ) 27 ); 28 29 $res_str = ''; 30 31 $fmt = ut_nfmt_create( "en_US", NumberFormatter::DECIMAL ); 32 33 foreach( $attributes as $attr_name => $data ) 34 { 35 list( $attr, $new_val, $test_number ) = $data; 36 $res_str .= "\nAttribute $attr_name\n"; 37 38 if( $attr == NumberFormatter::PADDING_CHARACTER ) 39 ut_nfmt_set_attribute( $fmt, NumberFormatter::FORMAT_WIDTH, 21 ); 40 41 // Get default attribute's value 42 $def_val = ut_nfmt_get_text_attribute( $fmt, $attr ); 43 if( $def_val === false ) 44 $res_str .= "get_text_attribute() error: " . ut_nfmt_get_error_message( $fmt ) . "\n"; 45 46 $res_str .= "Default value: [$def_val]\n"; 47 $res_str .= "Formatting number with default value: " . ut_nfmt_format( $fmt, $test_number ) . "\n"; 48 49 // Set new attribute's value and see if it works out. 50 $res_val = ut_nfmt_set_text_attribute( $fmt, $attr, $new_val ); 51 if( !$res_val ) 52 $res_str .= "set_text_attribute() error: " . ut_nfmt_get_error_message( $fmt ) . "\n"; 53 54 // Get attribute value back. 55 $new_val_check = ut_nfmt_get_text_attribute( $fmt, $attr ); 56 $res_str .= "New value: [$new_val_check]\n"; 57 $res_str .= "Formatting number with new value: " . ut_nfmt_format( $fmt, $test_number ) . "\n"; 58 59 // Check if the new value has been set. 60 if( $new_val !== $new_val_check ) 61 $res_str .= "ERROR: New $attr_name symbol value has not been set correctly.\n"; 62 63 // Restore attribute's value to default 64 ut_nfmt_set_text_attribute( $fmt, $attr, $def_val ); 65 66 if( $attr == NumberFormatter::PADDING_CHARACTER ) 67 ut_nfmt_set_attribute( $fmt, NumberFormatter::FORMAT_WIDTH, 0 ); 68 } 69 70 // 71 $fmt = ut_nfmt_create( "uk_UA", NumberFormatter::CURRENCY ); 72 $res_str .= sprintf( "\nCurrency ISO-code for locale 'uk_UA' is: %s\n", 73 ut_nfmt_get_text_attribute( $fmt, NumberFormatter::CURRENCY_CODE ) ); 74 75 return $res_str; 76} 77 78include_once( 'ut_common.inc' ); 79ut_run(); 80 81?> 82--EXPECT-- 83Attribute POSITIVE_PREFIX 84Default value: [] 85Formatting number with default value: 12,345.123 86New value: [_+_] 87Formatting number with new value: _+_12,345.123 88 89Attribute POSITIVE_SUFFIX 90Default value: [] 91Formatting number with default value: 12,345.123 92New value: [_+_] 93Formatting number with new value: 12,345.123_+_ 94 95Attribute NEGATIVE_PREFIX 96Default value: [-] 97Formatting number with default value: -12,345.123 98New value: [_-_] 99Formatting number with new value: _-_12,345.123 100 101Attribute NEGATIVE_SUFFIX 102Default value: [] 103Formatting number with default value: -12,345.123 104New value: [_-_] 105Formatting number with new value: -12,345.123_-_ 106 107Attribute PADDING_CHARACTER 108Default value: [*] 109Formatting number with default value: ***********12,345.123 110New value: [^] 111Formatting number with new value: ^^^^^^^^^^^12,345.123 112 113Attribute POSITIVE_PREFIX-2 114Default value: [] 115Formatting number with default value: 12,345.123 116New value: [blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah] 117Formatting number with new value: blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah12,345.123 118 119Currency ISO-code for locale 'uk_UA' is: UAH 120 121 122