Make WordPress Core

Changeset 40058


Ignore:
Timestamp:
02/14/2017 04:22:32 AM (8 years ago)
Author:
adamsilverstein
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.
Fixes #39264.

Location:
trunk
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r39195 r40058  
    440440                cmd: 'phpunit',
    441441                args: ['-c', 'phpunit.xml.dist', '--group', 'external-http']
     442            },
     443            'restapi-jsclient': {
     444                cmd: 'phpunit',
     445                args: ['-c', 'phpunit.xml.dist', '--group', 'restapi-jsclient']
    442446            }
    443447        },
     
    671675        'jshint:core',
    672676        'jshint:media'
     677    ] );
     678
     679    grunt.registerTask( 'restapi-jsclient', [
     680        'phpunit:restapi-jsclient',
     681        'qunit'
    673682    ] );
    674683
  • trunk/tests/qunit/index.html

    r39928 r40058  
    1616                    'url': '\/wp-admin\/admin-ajax.php'
    1717                }
     18            };
     19        </script>
     20        <script>
     21            var wpApiSettings = {
     22                'root': 'http://localhost/wp-json/'
    1823            };
    1924        </script>
     
    3540            <script src="fixtures/customize-menus.js"></script>
    3641            <script src="fixtures/customize-widgets.js"></script>
     42            <script src="fixtures/wp-api-generated.js"></script>
     43            <script src="fixtures/wp-api.js"></script>
    3744        </div>
    3845        <p><a href="editor">TinyMCE tests</a></p>
     
    4451        <script src="../../src/wp-includes/js/shortcode.js"></script>
    4552        <script src="../../src/wp-admin/js/customize-controls.js"></script>
     53        <script src="../../src/wp-includes/js/wp-api.js"></script>
    4654
    4755        <script type='text/javascript' src='../../src/wp-includes/js/jquery/ui/core.js'></script>
     
    6270        <script src="wp-admin/js/customize-header.js"></script>
    6371        <script src="wp-includes/js/shortcode.js"></script>
     72        <script src="wp-includes/js/wp-api.js"></script>
    6473        <script src="wp-admin/js/customize-controls.js"></script>
    6574        <script src="wp-admin/js/customize-controls-utils.js"></script>
Note: See TracChangeset for help on using the changeset viewer.