WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/24/17 22:33:05 (3 months ago)
Author:
SergeyBiryukov
Message:

REST API: Add QUnit tests for wp-api.js and PHPUnit fixture generation.

Add QUnit tests: verify that wp-api loads correctly, verify that the expected base models and collections exist and can be instantiated, verify that collections contain the correct models, verify that expected helper functions are in place for each collection.

The QUnit tests rely on two fixture files: tests/qunit/fixtures/wp-api-generated.js contains the data response from each core endpoint and is generated by running the PHPUnit restapi-jsclient group. tests/qunit/fixtures/wp-api.js maps the generated data to endpoint routes, and overrides Backbone.ajax to mock the responses for the tests.

Add PHPUnit tests in tests/phpunit/tests/rest-api/rest-schema-setup.php. First, verify that the API returns the expected routes via server->get_routes(). Then, the test_build_wp_api_client_fixtures test goes thru each endpoint and requests it from the API, tests that it returns data, and builds up the data for the mocked QUnit tests, saving the final results to tests/qunit/fixtures/wp-api-generated.js.

Add a new grunt task restapi-jsclient which runs the phpunit side data generation and the qunit tests together.

Props jnylen0, welcher, adamsilverstein, netweb, ocean90, rachelbaker.
Merges [40058], [40061], [40065], [40066], [40077], and [40104] to the 4.7 branch.
Fixes #39264.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/tests/phpunit/tests/rest-api/rest-post-meta-fields.php

    r39437 r40116  
    1111  */ 
    1212class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase { 
     13    protected static $wp_meta_keys_saved; 
    1314    protected static $post_id; 
    1415 
    1516    public static function wpSetUpBeforeClass( $factory ) { 
     17        self::$wp_meta_keys_saved = $GLOBALS['wp_meta_keys']; 
    1618        self::$post_id = $factory->post->create(); 
    1719    } 
    1820 
    1921    public static function wpTearDownAfterClass() { 
     22        $GLOBALS['wp_meta_keys'] = self::$wp_meta_keys_saved; 
    2023        wp_delete_post( self::$post_id, true ); 
    2124    } 
Note: See TracChangeset for help on using the changeset viewer.