Making WordPress.org


Ignore:
Timestamp:
02/28/2018 03:27:07 AM (7 years ago)
Author:
dd32
Message:

API: Serve Happy: Update the API to return the final selection of fields.

Props flixos90.
Fixes #3474.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/core/serve-happy/1.0/tests/tests.php

    r6728 r6806  
    2525                [ 'php_version' => '5.3.2' ]
    2626            ],
    27             [
    28                 [
    29                     'php_version' => '7.0',
    30                     'ip_address' => '1.2.3.0'
    31                 ],
    32                 [
    33                     'php_version' => '7.0',
    34                     'ip_address' => '1.2.3.0'
    35                 ]
    36             ],
    3727        ];
    3828    }
     
    5545
    5646        // Assert that it's a successful response, and not an error.
    57         $this->assertArrayHasKey( 'status', $output );
     47        $this->assertArrayHasKey( 'recommended_version', $output );
     48        $this->assertArrayHasKey( 'is_supported', $output );
     49        $this->assertArrayHasKey( 'is_secure', $output );
     50        $this->assertArrayHasKey( 'is_acceptable', $output );
    5851    }
    5952
     
    9285                ]
    9386            ],
    94             [
    95                 [
    96                     'php_version' => '7.0',
    97                     'ip_address' => '1.2.3.4'
    98                 ],
    99                 [
    100                     'code'    => 'invalid_param',
    101                     'message' => 'Invalid parameter: ip_address',
    102                     'status'  => 400
    103                 ]
    104             ],
    10587        ];
    10688    }
     
    126108
    127109    function dataprovider_parse_request_valid() {
    128         return [
    129             // Testing Valid IP Address format
    130             [
    131                 [
    132                     'php_version' => RECOMMENDED_PHP,
    133                     'ip_address'  => '1.2.3.0',
    134                 ],
    135                 [ 'status' => 'ok' ]
    136             ],
    137             // Testing PHP version logic:
     110        // Test recommended PHP version is always returned.
     111        $data = [
    138112            [
    139113                [ 'php_version' => RECOMMENDED_PHP ],
    140                 [ 'status' => 'ok' ]
    141             ],
    142             [
    143                 [ 'php_version' => RECOMMENDED_PHP + 0.1 ],
    144                 [ 'status' => 'ok' ]
    145             ],
    146             [
    147                 [ 'php_version' => PHP_RECEIVING_SECURITY_UPDATES ],
    148                 [ 'status' => 'ok' ]
    149             ],
    150             [
    151                 [ 'php_version' => PHP_RECEIVING_SECURITY_UPDATES - 0.1 ],
    152                 [ 'status' => 'no_security_updates' ]
    153             ],
    154             [
    155                 [ 'php_version' => TRIGGER_PHP_VERSION - 0.1 ],
    156                 [ 'status' => 'out_of_date' ]
    157             ],
    158         ];
     114                [ 'recommended_version' => RECOMMENDED_PHP ]
     115            ],
     116            [
     117                [ 'php_version' => '5.2' ],
     118                [ 'recommended_version' => RECOMMENDED_PHP ]
     119            ],
     120        ];
     121
     122        // Test individual PHP versions.
     123        $flags = [
     124            'is_supported'  => 'SUPPORTED_PHP',
     125            'is_secure'     => 'SECURE_PHP',
     126            'is_acceptable' => 'ACCEPTABLE_PHP'
     127        ];
     128        foreach ( $flags as $flag => $constant_name ) {
     129            $data[] = [
     130                [ 'php_version' => constant( $constant_name ) ],
     131                [ $flag => true ]
     132            ];
     133            $data[] = [
     134                [ 'php_version' => constant( $constant_name ) + 0.1 ],
     135                [ $flag => true ]
     136            ];
     137            $data[] = [
     138                [ 'php_version' => constant( $constant_name ) - 0.1 ],
     139                [ $flag => false ]
     140            ];
     141        }
     142        return $data;
    159143    }
    160144
Note: See TracChangeset for help on using the changeset viewer.