Make WordPress Core


Ignore:
Timestamp:
12/13/2018 10:41:47 PM (7 years ago)
Author:
desrosj
Message:

REST API: Introduce Autosaves controller and endpoint.

  • Adds WP_REST_Autosaves_Controller which extends WP_REST_Revisions_Controller.
  • Autosaves endpoint is registered for all post types except attachment because even post types without revisions enabled are expected to autosave.
  • Because setting the DOING_AUTOSAVE constant pollutes the test suite, autosaves tests are run last. We may want to improve upon this later.

Also, use a truly impossibly high number in User Controller tests. The number 100, (or 7777 in trunk), could be valid in certain test run configurations. The REST_TESTS_IMPOSSIBLY_HIGH_NUMBER constant is impossibly high for this very reason.

Finally, Skip Autosaves controller test for multisite. There's a PHP 5.2 edge case where paths calculated differently, possibly caused by differing version of PHPUnit.

Props adamsilverstein, aduth, azaozz, danielbachhuber, rmccue, danielbachhuber.

Merges [43767], [43768], [43769] to trunk.

See #45132, #45131.
Fixes #45128, #43316.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r44107 r44126  
    9090            '/wp/v2/posts/(?P<parent>[\\d]+)/revisions',
    9191            '/wp/v2/posts/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)',
     92            '/wp/v2/posts/(?P<parent>[\\d]+)/autosaves',
     93            '/wp/v2/posts/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)',
    9294            '/wp/v2/pages',
    9395            '/wp/v2/pages/(?P<id>[\\d]+)',
    9496            '/wp/v2/pages/(?P<parent>[\\d]+)/revisions',
    9597            '/wp/v2/pages/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)',
     98            '/wp/v2/pages/(?P<parent>[\\d]+)/autosaves',
     99            '/wp/v2/pages/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)',
    96100            '/wp/v2/media',
    97101            '/wp/v2/media/(?P<id>[\\d]+)',
     
    162166        $post_revision_id = $post_revisions[ count( $post_revisions ) - 1 ]->ID;
    163167
     168        // Create an autosave.
     169        wp_create_post_autosave(
     170            array(
     171                'post_ID'      => $post_id,
     172                'post_content' => 'Autosave post content.',
     173                'post_type'    => 'post',
     174            )
     175        );
     176
    164177        $page_id = $this->factory->post->create(
    165178            array(
     
    182195        $page_revisions   = array_values( wp_get_post_revisions( $page_id ) );
    183196        $page_revision_id = $page_revisions[ count( $page_revisions ) - 1 ]->ID;
     197
     198        // Create an autosave.
     199        wp_create_post_autosave(
     200            array(
     201                'post_ID'      => $page_id,
     202                'post_content' => 'Autosave page content.',
     203                'post_type'    => 'page',
     204            )
     205        );
    184206
    185207        $tag_id = $this->factory->tag->create(
     
    277299            ),
    278300            array(
     301                'route' => '/wp/v2/posts/' . $post_id . '/autosaves',
     302                'name'  => 'postAutosaves',
     303            ),
     304            array(
     305                'route' => '/wp/v2/posts/' . $post_id . '/autosaves/' . $post_revision_id,
     306                'name'  => 'autosave',
     307            ),
     308            array(
    279309                'route' => '/wp/v2/pages',
    280310                'name'  => 'PagesCollection',
     
    291321                'route' => '/wp/v2/pages/' . $page_id . '/revisions/' . $page_revision_id,
    292322                'name'  => 'pageRevision',
     323            ),
     324            array(
     325                'route' => '/wp/v2/pages/' . $page_id . '/autosaves',
     326                'name'  => 'pageAutosaves',
     327            ),
     328            array(
     329                'route' => '/wp/v2/pages/' . $page_id . '/autosaves/' . $page_revision_id,
     330                'name'  => 'pageAutosave',
    293331            ),
    294332            array(
Note: See TracChangeset for help on using the changeset viewer.