Skip to content

Commit

Permalink
Move CI back to latest WordPress version and bump minimum version to …
Browse files Browse the repository at this point in the history
…4.9.8 (WordPress#8454)

* Back to latest WordPress version

* Update WordPress is the requested version is 'latest'

* REST API: Remove polyfill for assign_terms visibility

* Framework: Bump WordPress compatibility to 4.9.8
  • Loading branch information
notnownikki authored and danielbachhuber committed Aug 7, 2018
1 parent 17852d6 commit 9c75e47
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 167 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,38 @@ branches:
jobs:
include:
- stage: test
env: WP_VERSION=4.9.7
env: WP_VERSION=latest
script:
- npm install || exit 1
- npm run ci || exit 1

- stage: test
env: WP_VERSION=4.9.7 DOCKER=true
env: WP_VERSION=latest DOCKER=true
script:
- ./bin/run-wp-unit-tests.sh

- stage: test
php: 5.6
env: WP_VERSION=4.9.7
env: WP_VERSION=latest
script:
- ./bin/run-wp-unit-tests.sh
if: branch = master and type != "pull_request"

- stage: test
php: 7.1
env: WP_VERSION=4.9.7 SWITCH_TO_PHP=5.3
env: WP_VERSION=latest SWITCH_TO_PHP=5.3
script:
- ./bin/run-wp-unit-tests.sh
if: branch = master and type != "pull_request"

- stage: test
php: 7.1
env: WP_VERSION=4.9.7 SWITCH_TO_PHP=5.2
env: WP_VERSION=latest SWITCH_TO_PHP=5.2
script:
- ./bin/run-wp-unit-tests.sh

- stage: test
env: WP_VERSION=4.9.7
env: WP_VERSION=latest
script:
- npm install || exit 1
- npm run build || exit 1
Expand Down
9 changes: 6 additions & 3 deletions bin/install-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set -e
CLI='cli'
CONTAINER='wordpress'
SITE_TITLE='Gutenberg Dev'
WP_VERSION=${WP_VERSION-latest}

# If we're installing/re-installing the test site, change the containers used.
if [ "$1" == '--e2e_tests' ]; then
Expand Down Expand Up @@ -50,9 +51,11 @@ echo -e $(status_message "Installing WordPress...")
# The `-u 33` flag tells Docker to run the command as a particular user and
# prevents permissions errors. See: https://github.com/WordPress/gutenberg/pull/8427#issuecomment-410232369
docker-compose run --rm -u 33 $CLI core install --title="$SITE_TITLE" --admin_user=admin --admin_password=password [email protected] --skip-email --url=http://localhost:$HOST_PORT >/dev/null
# Check for WordPress updates, just in case the WordPress image isn't up to date.
# (Disabled until https://github.com/WordPress/gutenberg/issues/8445 is fixed.)
# docker-compose run --rm -u 33 $CLI core update >/dev/null

if [ "$WP_VERSION" == "latest" ]; then
# Check for WordPress updates, to make sure we're running the very latest version.
docker-compose run --rm -u 33 $CLI core update >/dev/null
fi

# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it.
CURRENT_URL=$(docker-compose run -T --rm $CLI option get siteurl)
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.1'
services:

wordpress:
image: wordpress:4.9.7 # Pinned to version 4.9.7 until https://github.com/WordPress/gutenberg/issues/8445 is fixed.
image: wordpress
ports:
- 8888:80
environment:
Expand Down Expand Up @@ -41,7 +41,7 @@ services:
- .:/app

wordpress_e2e_tests:
image: wordpress:4.9.7 # Pinned to version 4.9.7 until https://github.com/WordPress/gutenberg/issues/8445 is fixed.
image: wordpress
ports:
- 8889:80
environment:
Expand Down
4 changes: 2 additions & 2 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function is_gutenberg_page() {
*/
function gutenberg_wordpress_version_notice() {
echo '<div class="error"><p>';
echo __( 'Gutenberg requires WordPress 4.9.6 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' );
echo __( 'Gutenberg requires WordPress 4.9.8 or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' );
echo '</p></div>';

deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
Expand Down Expand Up @@ -155,7 +155,7 @@ function gutenberg_pre_init() {
// Strip '-src' from the version string. Messes up version_compare().
$version = str_replace( '-src', '', $wp_version );

if ( version_compare( $version, '4.9.6', '<' ) ) {
if ( version_compare( $version, '4.9.8', '<' ) ) {
add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
return;
}
Expand Down
108 changes: 0 additions & 108 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,111 +604,3 @@ function gutenberg_filter_user_collection_parameters( $query_params ) {
return $query_params;
}
add_filter( 'rest_user_collection_params', 'gutenberg_filter_user_collection_parameters' );

/**
* Overload taxonomy and term permission handling to address our new necessary behavior.
*
* This is temporary code that will be removed once the Trac ticket lands in a release.
*
* @see https://core.trac.wordpress.org/ticket/44096
*
* @param WP_HTTP_Response $response Result to send to the client. Usually a WP_REST_Response.
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
* @param WP_REST_Request $request Request used to generate the response.
* @return $response
*/
function gutenberg_filter_request_after_callbacks( $response, $handler, $request ) {
$should_rerun_response = false;
if ( is_wp_error( $response ) ) {
// Handle GET /wp/v2/taxonomies?context=edit when user can assign_terms
// but not manage_terms.
if ( '/wp/v2/taxonomies' === $request->get_route()
&& is_array( $handler['permission_callback'] )
&& is_a( $handler['permission_callback'][0], 'WP_REST_Taxonomies_Controller' )
&& 'edit' === $request['context']
&& 'rest_cannot_view' === $response->get_error_code() ) {
if ( ! empty( $request['type'] ) ) {
$taxonomies = get_object_taxonomies( $request['type'], 'objects' );
} else {
$taxonomies = get_taxonomies( '', 'objects' );
}
foreach ( $taxonomies as $taxonomy ) {
if ( ! empty( $taxonomy->show_in_rest )
&& current_user_can( $taxonomy->cap->assign_terms ) ) {
$GLOBALS['Gutenberg_Temporary_Taxonomies_Controller'] = $handler['permission_callback'][0];

$handler['callback'] = 'gutenberg_taxonomies_controller_get_items';
$should_rerun_response = true;
break;
}
}
}
// Handle POST /wp/v2/tags (and non-hierarchical taxonomies) when user
// can assign_terms but not manage terms. Users should be able to create
// terms.
if ( 'rest_cannot_create' === $response->get_error_code()
&& is_array( $handler['permission_callback'] )
&& is_a( $handler['permission_callback'][0], 'WP_REST_Terms_Controller' ) ) {
$schema = $handler['permission_callback'][0]->get_item_schema();
$taxonomy = 'tag' === $schema['title'] ? 'post_tag' : $schema['title'];
$taxonomy_obj = get_taxonomy( $taxonomy );
if ( ! is_taxonomy_hierarchical( $taxonomy_obj->name )
&& current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
$should_rerun_response = true;
}
}
}
// Re-run the response generation if we've decided we need to.
if ( $should_rerun_response ) {
$callback = $handler['callback'];
// Filter defined in class-wp-rest-server.php.
$dispatch_result = apply_filters( 'rest_dispatch_request', null, $request, $request->get_route(), $handler );

// Allow plugins to halt the request via this filter.
if ( null !== $dispatch_result ) {
$response = $dispatch_result;
} else {
$response = call_user_func( $callback, $request );
}
}
return $response;
}
add_filter( 'rest_request_after_callbacks', 'gutenberg_filter_request_after_callbacks', 10, 3 );

/**
* Overloaded version of WP_REST_Taxonomies_Controller::get_items()
*
* This is temporary code that will be removed once the Trac ticket lands in a release.
*
* @see https://core.trac.wordpress.org/ticket/44096
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response Response object on success, or WP_Error object on failure.
*/
function gutenberg_taxonomies_controller_get_items( $request ) {
$controller = $GLOBALS['Gutenberg_Temporary_Taxonomies_Controller'];
// Retrieve the controller of registered collection query parameters.
$registered = $controller->get_collection_params();

if ( isset( $registered['type'] ) && ! empty( $request['type'] ) ) {
$taxonomies = get_object_taxonomies( $request['type'], 'objects' );
} else {
$taxonomies = get_taxonomies( '', 'objects' );
}
$data = array();
foreach ( $taxonomies as $tax_type => $value ) {
if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->assign_terms ) ) ) {
continue;
}
$tax = $controller->prepare_item_for_response( $value, $request );
$tax = $controller->prepare_response_for_collection( $tax );
$data[ $tax_type ] = $tax;
}

if ( empty( $data ) ) {
// Response should still be returned as a JSON object when it is empty.
$data = (object) $data;
}

return rest_ensure_response( $data );
}
64 changes: 18 additions & 46 deletions phpunit/class-gutenberg-rest-api-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,58 +41,30 @@ function tearDown() {
* Should return an extra visibility field on response when in edit context.
*/
function test_visibility_field() {
wp_set_current_user( $this->administrator );

$request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' );
$request->set_param( 'context', 'edit' );
$response = rest_do_request( $request );

$result = $response->get_data();

$this->assertTrue( isset( $result['visibility'] ) );
$this->assertInternalType( 'array', $result['visibility'] );
$this->assertArrayHasKey( 'public', $result['visibility'] );
$this->assertArrayHasKey( 'publicly_queryable', $result['visibility'] );
$this->assertArrayHasKey( 'show_ui', $result['visibility'] );
$this->assertArrayHasKey( 'show_admin_column', $result['visibility'] );
$this->assertArrayHasKey( 'show_in_nav_menus', $result['visibility'] );
$this->assertArrayHasKey( 'show_in_quick_edit', $result['visibility'] );
}

/**
* Should return an extra visibility field on response.
*/
function test_visibility_field_for_non_admin_roles() {
wp_set_current_user( $this->editor );

$request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' );
$request->set_param( 'context', 'edit' );
$response = rest_do_request( $request );

$result = $response->get_data();

$this->assertTrue( isset( $result['visibility'] ) );
$this->assertInternalType( 'array', $result['visibility'] );
$this->assertArrayHasKey( 'public', $result['visibility'] );
$this->assertArrayHasKey( 'publicly_queryable', $result['visibility'] );
$this->assertArrayHasKey( 'show_ui', $result['visibility'] );
$this->assertArrayHasKey( 'show_admin_column', $result['visibility'] );
$this->assertArrayHasKey( 'show_in_nav_menus', $result['visibility'] );
$this->assertArrayHasKey( 'show_in_quick_edit', $result['visibility'] );

/**
* See https://github.com/WordPress/gutenberg/issues/2545
*
* Until that is resolved authors will not be able to set taxonomies.
* This should definitely be resolved though.
*/
wp_set_current_user( $this->author );
$permitted_users = array(
$this->administrator,
$this->editor,
$this->author,
);

$response = rest_do_request( $request );
foreach ( $permitted_users as $user ) {
wp_set_current_user( $user );

$result = $response->get_data();
$response = rest_do_request( $request );
$result = $response->get_data();

$this->assertFalse( isset( $result['visibility'] ) );
$this->assertTrue( isset( $result['visibility'] ) );
$this->assertInternalType( 'array', $result['visibility'] );
$this->assertArrayHasKey( 'public', $result['visibility'] );
$this->assertArrayHasKey( 'publicly_queryable', $result['visibility'] );
$this->assertArrayHasKey( 'show_ui', $result['visibility'] );
$this->assertArrayHasKey( 'show_admin_column', $result['visibility'] );
$this->assertArrayHasKey( 'show_in_nav_menus', $result['visibility'] );
$this->assertArrayHasKey( 'show_in_quick_edit', $result['visibility'] );
}
}

/**
Expand Down

0 comments on commit 9c75e47

Please sign in to comment.