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