Changeset 48883 for branches/5.5
- Timestamp:
- 08/27/2020 02:43:40 PM (4 years ago)
- Location:
- branches/5.5
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.5
-
branches/5.5/src/wp-includes/rest-api.php
r48828 r48883 1316 1316 */ 1317 1317 function rest_is_integer( $maybe_integer ) { 1318 return round( floatval( $maybe_integer ) ) === floatval( $maybe_integer );1318 return is_numeric( $maybe_integer ) && round( floatval( $maybe_integer ) ) === floatval( $maybe_integer ); 1319 1319 } 1320 1320 -
branches/5.5/tests/phpunit/tests/rest-api.php
r48555 r48883 1920 1920 1921 1921 /** 1922 * @ticket 51146 1923 * 1924 * @dataProvider _dp_rest_is_integer 1925 * 1926 * @param bool $expected Expected result of the check. 1927 * @param mixed $value The value to check. 1928 */ 1929 public function test_rest_is_integer( $expected, $value ) { 1930 $is_integer = rest_is_integer( $value ); 1931 1932 if ( $expected ) { 1933 $this->assertTrue( $is_integer ); 1934 } else { 1935 $this->assertFalse( $is_integer ); 1936 } 1937 } 1938 1939 public function _dp_rest_is_integer() { 1940 return array( 1941 array( 1942 true, 1943 1, 1944 ), 1945 array( 1946 true, 1947 '1', 1948 ), 1949 array( 1950 true, 1951 0, 1952 ), 1953 array( 1954 true, 1955 -1, 1956 ), 1957 array( 1958 true, 1959 '05', 1960 ), 1961 array( 1962 false, 1963 'garbage', 1964 ), 1965 array( 1966 false, 1967 5.5, 1968 ), 1969 array( 1970 false, 1971 '5.5', 1972 ), 1973 array( 1974 false, 1975 array(), 1976 ), 1977 array( 1978 false, 1979 true, 1980 ), 1981 ); 1982 } 1983 1984 /** 1922 1985 * @ticket 50300 1923 1986 * … … 2019 2082 array( 'array', 'string' ), 2020 2083 ), 2084 array( 2085 'string', 2086 'hello', 2087 array( 'integer', 'string' ), 2088 ), 2021 2089 ); 2022 2090 } -
branches/5.5/tests/phpunit/tests/rest-api/rest-schema-validation.php
r48365 r48883 1041 1041 $this->assertTrue( rest_validate_value_from_schema( $data, $schema ) ); 1042 1042 } 1043 1044 /** 1045 * @ticket 50300 1046 */ 1047 public function test_string_or_integer() { 1048 $schema = array( 1049 'type' => array( 'integer', 'string' ), 1050 ); 1051 1052 $this->assertTrue( rest_validate_value_from_schema( 'garbage', $schema ) ); 1053 $this->assertTrue( rest_validate_value_from_schema( 15, $schema ) ); 1054 $this->assertTrue( rest_validate_value_from_schema( '15', $schema ) ); 1055 $this->assertTrue( rest_validate_value_from_schema( '15.5', $schema ) ); 1056 $this->assertWPError( rest_validate_value_from_schema( 15.5, $schema ) ); 1057 } 1058 1043 1059 }
Note: See TracChangeset
for help on using the changeset viewer.