Skip to content

Commit

Permalink
Fix Local Build.
Browse files Browse the repository at this point in the history
Some changes to allow building and testing locally with the included
Makefile.

- Updates Docker image to `wordpress:5.3.2-php7.4`, along with
  the necessary package updates to accomodate it.

- Updates files for coding standards so that `phpcs` passes.

See: WordPress/issues/67
  • Loading branch information
getsource committed Mar 23, 2020
1 parent 076e8d4 commit 12ec925
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Start with the latest WordPress image.
FROM wordpress:4.7.3
FROM wordpress:5.3.2-php7.4

# Set up nodejs PPA
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash

# Install server dependencies.
RUN apt-get update && apt-get install -qq -y php5-mysql nodejs build-essential pkg-config libcairo2-dev libjpeg-dev libgif-dev git subversion mysql-client zip unzip vim libyaml-dev --fix-missing --no-install-recommends
RUN apt-get update && apt-get install -qq -y nodejs build-essential pkg-config libcairo2-dev libjpeg-dev libgif-dev git subversion default-mysql-client zip unzip vim libyaml-dev --fix-missing --no-install-recommends

COPY bin/install-wp-tests.sh /
RUN cat /install-wp-tests.sh | bash /dev/stdin wordpress root password mysql latest true
Expand All @@ -26,6 +26,6 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/
ENV PATH="/root/.composer/vendor/bin::${PATH}"

RUN composer global require "phpunit/phpunit=5.7.*"
RUN composer global require "squizlabs/php_codesniffer=2.9.*"
RUN composer global require "dealerdirect/phpcodesniffer-composer-installer"
RUN composer global require wp-coding-standards/wpcs
RUN phpcs --config-set installed_paths /root/.composer/vendor/wp-coding-standards/wpcs
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ shell:
docker-compose exec wordpress /bin/bash -c "cd /var/www/html/wp-content/plugins/wp-unit-test-reporter/; /bin/bash"

test:
docker-compose exec wordpress /bin/bash -c "cd /var/www/html/wp-content/plugins/wp-unit-test-reporter/; phpcs --standard=phpcs.ruleset.xml ./ && phpunit"
docker-compose exec wordpress /bin/bash -c "cd /var/www/html/wp-content/plugins/wp-unit-test-reporter/; phpcs --standard=phpcs.xml.dist ./ && phpunit"
12 changes: 8 additions & 4 deletions parts/result-set.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$total_cols = 5;
foreach ( $revisions as $revision ) :
$rev_id = (int) ltrim( $revision->post_name, 'r' );
?>
?>
<tr>
<th colspan="<?php echo (int) $total_cols; ?>"><a href="<?php echo esc_url( sprintf( 'https://core.trac.wordpress.org/changeset/%d', $rev_id ) ); ?>">r<?php echo (int) $rev_id; ?></a>: <?php echo wp_kses_post( apply_filters( 'the_title', $revision->post_title ) ); ?></th>
</tr>
Expand Down Expand Up @@ -47,7 +47,11 @@
$host .= '<a target="_blank" rel="nofollow" href="' . esc_url( $user->user_url ) . '">';
}
$host .= get_avatar(
$user->ID, 18, '', '', array(
$user->ID,
18,
'',
'',
array(
'extra_attr' => 'style="vertical-align: middle;margin-right:5px;"',
)
);
Expand All @@ -69,10 +73,10 @@
<td><?php echo esc_html( Display::get_display_php_version( $report->ID ) ); ?></td>
<td><?php echo esc_html( Display::get_display_mysql_version( $report->ID ) ); ?></td>
</tr>
<?php
<?php
endforeach;
else :
?>
?>
<tr>
<td></td>
<td colspan="<?php echo (int) $total_cols - 1; ?>">
Expand Down
10 changes: 7 additions & 3 deletions parts/single-result.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
$host .= '<a target="_blank" rel="nofollow" href="' . esc_url( $user->user_url ) . '">';
}
$host .= get_avatar(
$user->ID, 18, '', '', array(
$user->ID,
18,
'',
'',
array(
'extra_attr' => 'style="vertical-align: middle;margin-right:5px;"',
)
);
Expand All @@ -37,7 +41,7 @@
<?php
$parent = get_post( $report->post_parent );
if ( $parent ) :
?>
?>
<p><a href="<?php echo esc_url( get_permalink( $parent ) ); ?>">&larr; <?php echo esc_html( $parent->post_name ) . ': ' . apply_filters( 'the_title', get_the_title( $parent ) ); ?></a></p>
<?php endif; ?>

Expand Down Expand Up @@ -73,7 +77,7 @@
continue;
}
foreach ( $testsuite['testcases'] as $test_name => $testcase ) :
?>
?>
<p><strong><?php echo esc_html( $suite_name . '::' . $test_name ); ?></strong></p>
<pre><?php echo ! empty( $testcase['failure'] ) ? $testcase['failure'] : $testcase['error']; ?></pre>
<?php endforeach; ?>
Expand Down
4 changes: 3 additions & 1 deletion src/class-content-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public static function action_init_register_post_type() {
public static function action_init_register_role() {
if ( ! get_role( 'test-reporter' ) ) {
add_role(
'test-reporter', __( 'Test Reporter', 'ptr' ), array(
'test-reporter',
__( 'Test Reporter', 'ptr' ),
array(
'read' => true,
)
);
Expand Down
9 changes: 6 additions & 3 deletions src/class-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ public static function filter_the_content( $content ) {

if ( get_queried_object()->post_parent ) {
$content = ptr_get_template_part(
'single-result', array(
'single-result',
array(
'report' => get_queried_object(),
)
);
} else {
$content = ptr_get_template_part(
'result-set', array(
'result-set',
array(
'revisions' => array(
get_queried_object(),
),
Expand Down Expand Up @@ -118,7 +120,8 @@ public static function render_results( $atts ) {
$output .= self::get_reporter_avatars();
}
$output .= ptr_get_template_part(
'result-set', array(
'result-set',
array(
'revisions' => $rev_query->posts,
)
);
Expand Down
24 changes: 18 additions & 6 deletions src/class-restapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class RestAPI {
*/
public static function register_routes() {
register_rest_route(
'wp-unit-test-api/v1', 'results', array(
'wp-unit-test-api/v1',
'results',
array(
'methods' => 'POST',
'callback' => array( __CLASS__, 'add_results_callback' ),
'args' => array(
Expand Down Expand Up @@ -51,7 +53,9 @@ public static function validate_callback( $value, $request, $key ) {
case 'commit':
if ( ! is_numeric( $value ) ) {
return new WP_Error(
'rest_invalid', __( 'Value must be numeric.', 'ptr' ), array(
'rest_invalid',
__( 'Value must be numeric.', 'ptr' ),
array(
'status' => 400,
)
);
Expand All @@ -60,7 +64,9 @@ public static function validate_callback( $value, $request, $key ) {
case 'message':
if ( empty( $value ) || ! is_string( $value ) ) {
return new WP_Error(
'rest_invalid', __( 'Value must be a non-empty string.', 'ptr' ), array(
'rest_invalid',
__( 'Value must be a non-empty string.', 'ptr' ),
array(
'status' => 400,
)
);
Expand All @@ -70,15 +76,19 @@ public static function validate_callback( $value, $request, $key ) {
case 'results':
if ( null === json_decode( $value ) ) {
return new WP_Error(
'rest_invalid', __( 'Value must be encoded JSON.', 'ptr' ), array(
'rest_invalid',
__( 'Value must be encoded JSON.', 'ptr' ),
array(
'status' => 400,
)
);
}
return true;
}
return new WP_Error(
'rest_invalid', __( 'Invalid key specified.', 'ptr' ), array(
'rest_invalid',
__( 'Invalid key specified.', 'ptr' ),
array(
'status' => 400,
)
);
Expand All @@ -87,7 +97,9 @@ public static function validate_callback( $value, $request, $key ) {
public static function permission() {
if ( ! current_user_can( 'edit_results' ) ) {
return new WP_Error(
'rest_unauthorized', __( 'Sorry, you are not allowed to create results.', 'ptr' ), array(
'rest_unauthorized',
__( 'Sorry, you are not allowed to create results.', 'ptr' ),
array(
'status' => is_user_logged_in() ? 403 : 401,
)
);
Expand Down
9 changes: 6 additions & 3 deletions tests/test-restapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public function test_create_result_success() {
$this->assertEquals(
array(
'failures' => '5',
), $results
),
$results
);
}

Expand Down Expand Up @@ -182,7 +183,8 @@ public function test_update_result_success_update_existing() {
$this->assertEquals(
array(
'failures' => '1',
), $results
),
$results
);

// Make second request.
Expand All @@ -206,7 +208,8 @@ public function test_update_result_success_update_existing() {
$this->assertEquals(
array(
'failures' => '0',
), $results
),
$results
);
}

Expand Down

0 comments on commit 12ec925

Please sign in to comment.