Skip to content

Commit 2863d7d

Browse files
authored
Merge pull request #109 from swissspidy/add/cloudfest
Support multiple PHP versions, improve display
2 parents 51eca15 + 2fe266f commit 2863d7d

8 files changed

+480
-74
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab

parts/result-set-all.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
use PTR\Display;
3+
4+
echo Display::get_display_css(); ?>
5+
6+
<table class="ptr-test-reporter-table alignwide">
7+
<thead>
8+
<tr>
9+
<th style="width:100px">Revision</th>
10+
<th style="width:100px">Passed</th>
11+
<th style="width:100px">Failed</th>
12+
<th style="width:100px">➡️</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<?php
17+
foreach ( $revisions as $revision ) :
18+
$rev_id = (int) ltrim( $revision->post_name, 'r' );
19+
20+
$num_passed = ptr_count_test_results( $revision->ID );
21+
$num_failed = ptr_count_test_results( $revision->ID, 'failed' );
22+
?>
23+
<tr>
24+
<td>
25+
<a
26+
href="<?php echo esc_url( sprintf( 'https://core.trac.wordpress.org/changeset/%d', $rev_id ) ); ?>"
27+
title="<?php echo esc_attr( apply_filters( 'the_title', $revision->post_title ) ); ?>">
28+
r<?php echo $rev_id; ?>
29+
</a>
30+
</td>
31+
32+
<td>
33+
<span class="ptr-status-badge ptr-status-badge-passed">
34+
<?php echo $num_passed; ?>
35+
</span>
36+
</td>
37+
<td>
38+
<span class="ptr-status-badge ptr-status-badge-failed">
39+
<?php echo $num_failed; ?>
40+
</span>
41+
</td>
42+
<td>
43+
<a href="<?php the_permalink( $revision->ID ); ?>">
44+
View
45+
</a>
46+
</td>
47+
</tr>
48+
<?php endforeach; ?>
49+
</tbody>
50+
</table>
Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,53 @@
11
<?php
22
use PTR\Display;
33

4-
echo Display::get_display_css(); ?>
4+
echo Display::get_display_css();
55

6-
<table>
6+
foreach ( $revisions as $revision ) :
7+
8+
$rev_id = (int) ltrim( $revision->post_name, 'r' );
9+
?>
10+
11+
<div class="ptr-test-reporter-single-revision">
12+
<a href="<?php echo esc_url( sprintf( 'https://core.trac.wordpress.org/changeset/%d', $rev_id ) ); ?>">
13+
r<?php echo $rev_id; ?>
14+
</a>: <?php echo esc_attr( apply_filters( 'the_title', $revision->post_title ) ); ?>
15+
</div>
16+
17+
<table class="ptr-test-reporter-table alignwide">
718
<thead>
819
<tr>
9-
<th style="width:100px">Revision</th>
10-
<th>Host</th>
11-
<th>PHP Version</th>
20+
<th style="width:100px">Status</th>
21+
<th style="width:150px">PHP Version</th>
1222
<th>Database Version</th>
1323
</tr>
1424
</thead>
1525
<tbody>
16-
<?php
17-
$total_cols = 5;
18-
foreach ( $revisions as $revision ) :
19-
$rev_id = (int) ltrim( $revision->post_name, 'r' );
20-
?>
21-
<tr>
22-
<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>
23-
</tr>
26+
2427
<?php
25-
$query_args = array(
28+
$query_args = array(
2629
'posts_per_page' => $posts_per_page,
30+
'author' => $post_author ?? null,
2731
'post_type' => 'result',
2832
'post_parent' => $revision->ID,
29-
'orderby' => 'post_title',
30-
'order' => 'ASC',
33+
'orderby' => [ 'author' => 'ASC', 'env_name_clause' => 'ASC' ],
34+
'meta_query' => array(
35+
'relation' => 'OR',
36+
'env_name_clause' => array(
37+
'key' => 'environment_name',
38+
'compare' => 'EXISTS',
39+
),
40+
array(
41+
'key' => 'environment_name',
42+
'compare' => 'NOT EXISTS',
43+
)
44+
),
3145
);
3246
$report_query = new WP_Query( $query_args );
3347
if ( ! empty( $report_query->posts ) ) :
48+
49+
$prev_author = null;
50+
3451
foreach ( $report_query->posts as $report ) :
3552
$status = 'Errored';
3653
$status_title = 'No results found for test.';
@@ -55,35 +72,42 @@
5572
'extra_attr' => 'style="vertical-align: middle;margin-right:5px;"',
5673
)
5774
);
58-
if ( ! empty( $user->user_url ) ) {
59-
$host .= '</a>';
60-
}
61-
if ( ! empty( $user->user_url ) ) {
62-
$host .= '<a target="_blank" rel="nofollow" href="' . esc_url( $user->user_url ) . '">';
63-
}
64-
$host .= $user->display_name;
75+
76+
$host .= Display::get_display_reporter_name( $report->post_author );
77+
6578
if ( ! empty( $user->user_url ) ) {
6679
$host .= '</a>';
6780
}
6881
}
6982
?>
83+
<?php if ( $prev_author !== $host ): ?>
84+
<tr>
85+
<td colspan="3">
86+
<?php echo wp_kses_post( $host ); ?>
87+
</td>
88+
</tr>
89+
90+
<?php endif; ?>
7091
<tr>
71-
<td><a href="<?php echo esc_url( get_permalink( $report->ID ) ); ?>" title="<?php echo esc_attr( $status_title ); ?>" class="<?php echo esc_attr( 'ptr-status-badge ptr-status-badge-' . strtolower( $status ) ); ?>"><?php echo esc_html( $status ); ?></a></td>
72-
<td><?php echo wp_kses_post( $host ); ?></td>
92+
<td>
93+
<a href="<?php echo esc_url( get_permalink( $report->ID ) ); ?>" title="<?php echo esc_attr( $status_title ); ?>" class="<?php echo esc_attr( 'ptr-status-badge ptr-status-badge-' . strtolower( $status ) ); ?>">
94+
<?php echo esc_html( $status ); ?>
95+
</a>
96+
</td>
7397
<td><?php echo esc_html( Display::get_display_php_version( $report->ID ) ); ?></td>
7498
<td><?php echo esc_html( Display::get_display_mysql_version( $report->ID ) ); ?></td>
7599
</tr>
76100
<?php
101+
$prev_author = $host;
77102
endforeach;
78103
else :
79104
?>
80105
<tr>
81-
<td></td>
82-
<td colspan="<?php echo (int) $total_cols - 1; ?>">
106+
<td colspan="3">
83107
No reports for changeset.
84108
</td>
85109
</tr>
86110
<?php endif; ?>
87-
<?php endforeach; ?>
88111
</tbody>
89112
</table>
113+
<?php endforeach;

parts/single-result.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
'extra_attr' => 'style="vertical-align: middle;margin-right:5px;"',
2525
)
2626
);
27-
if ( ! empty( $user->user_url ) ) {
28-
$host .= '</a>';
29-
}
30-
if ( ! empty( $user->user_url ) ) {
31-
$host .= '<a target="_blank" rel="nofollow" href="' . esc_url( $user->user_url ) . '">';
32-
}
3327
$host .= $user->display_name;
3428
if ( ! empty( $user->user_url ) ) {
3529
$host .= '</a>';
@@ -54,6 +48,25 @@
5448
<td><strong>Host</strong></td>
5549
<td><?php echo wp_kses_post( $host ); ?></td>
5650
</tr>
51+
<tr>
52+
<td><strong>Test Date</strong></td>
53+
<td>
54+
<?php the_date(); ?>
55+
<?php the_time(); ?>
56+
</td>
57+
</tr>
58+
<tr>
59+
<td><strong>Execution Time</strong></td>
60+
<td>
61+
<?php echo esc_html( Display::get_display_time( $report->ID ) ); ?>
62+
</td>
63+
</tr>
64+
<tr>
65+
<td><strong>Environment Name</strong></td>
66+
<td>
67+
<?php echo esc_html( Display::get_display_environment_name( $report->ID ) ); ?>
68+
</td>
69+
</tr>
5770
<tr>
5871
<td><strong>PHP Version</strong></td>
5972
<td><?php echo esc_html( Display::get_display_php_version( $report->ID ) ); ?></td>

phpunit-test-reporter.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
add_action( 'post_class', array( 'PTR\Display', 'filter_post_class' ) );
3030
add_action( 'the_content', array( 'PTR\Display', 'filter_the_content' ) );
3131
add_action( 'rest_api_init', array( 'PTR\RestAPI', 'register_routes' ) );
32-
3332
add_action( 'load-edit.php', 'ptr_load_edit_php' );
3433

3534
/**
@@ -93,3 +92,35 @@ function ptr_get_template_part( $template, $vars = array() ) {
9392
include $full_path;
9493
return ob_get_clean();
9594
}
95+
96+
/**
97+
* Counts the number of failing or passing test reports for a revision.
98+
*
99+
* @param int $revision_parent_id The current revision's post ID.
100+
* @param string $status The status term slug to count.
101+
*
102+
* @return int The number of reports for the given revision.
103+
*/
104+
function ptr_count_test_results( $revision_parent_id, $status = 'passed' ) {
105+
$report_query = new WP_Query(
106+
array(
107+
'post_type' => 'result',
108+
'post_parent' => $revision_parent_id,
109+
'fields' => 'ids',
110+
'posts_per_page' => 1,
111+
'tax_query' => array(
112+
array(
113+
'taxonomy' => 'report-result',
114+
'terms' => $status,
115+
'field' => 'slug',
116+
),
117+
)
118+
)
119+
);
120+
121+
if ( ! $report_query->have_posts() ) {
122+
return 0;
123+
}
124+
125+
return $report_query->found_posts;
126+
}

src/class-content-model.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,60 @@ public static function action_init_register_post_type() {
4242
),
4343
)
4444
);
45+
46+
register_taxonomy(
47+
'php-version',
48+
array( 'result' ),
49+
array(
50+
'labels' => array(
51+
'name' => __( 'PHP Versions', 'ptr' ),
52+
'singular_name' => __( 'PHP Version', 'ptr' ),
53+
),
54+
'hierarchical' => false,
55+
'public' => false,
56+
'show_ui' => true,
57+
'show_admin_column' => true,
58+
'show_in_nav_menus' => false,
59+
'show_tagcloud' => false,
60+
'show_in_rest' => true,
61+
)
62+
);
63+
64+
register_taxonomy(
65+
'db-version',
66+
array( 'result' ),
67+
array(
68+
'labels' => array(
69+
'name' => __( 'Database Versions', 'ptr' ),
70+
'singular_name' => __( 'Database Version', 'ptr' ),
71+
),
72+
'hierarchical' => false,
73+
'public' => false,
74+
'show_ui' => true,
75+
'show_admin_column' => true,
76+
'show_in_nav_menus' => false,
77+
'show_tagcloud' => false,
78+
'show_in_rest' => true,
79+
)
80+
);
81+
82+
register_taxonomy(
83+
'report-result',
84+
array( 'result' ),
85+
array(
86+
'labels' => array(
87+
'name' => __( 'Result Status', 'ptr' ),
88+
'singular_name' => __( 'Result Status', 'ptr' ),
89+
),
90+
'hierarchical' => false,
91+
'public' => false,
92+
'show_ui' => true,
93+
'show_admin_column' => true,
94+
'show_in_nav_menus' => false,
95+
'show_tagcloud' => false,
96+
'show_in_rest' => true,
97+
)
98+
);
4599
}
46100

47101
/**

0 commit comments

Comments
 (0)