<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[5805] sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter: phpunit-test-reporter: Initial commit</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/5805">5805</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/5805","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>danielbachhuber</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-08-16 00:19:05 +0000 (Wed, 16 Aug 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>phpunit-test-reporter: Initial commit
See <a href="http://meta.trac.wordpress.org/ticket/2981">#2981</a></pre>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterpartsresultsetphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/result-set.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterpartssingleresultphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/single-result.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterphpunittestreporterphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/phpunit-test-reporter.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterreadmetxt">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/readme.txt</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreportersrcclasscontentmodelphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-content-model.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreportersrcclassdisplayphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-display.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreportersrcclassrestapiphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-restapi.php</a></li>
</ul>
<h3>Property Changed</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporter">sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter 2017-08-16 00:02:59 UTC (rev 5804)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter 2017-08-16 00:19:05 UTC (rev 5805)
</ins><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporter"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnignore"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:ignore</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+Dockerfile
+Makefile
</ins><span class="cx" style="display: block; padding: 0 10px"> README.md
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+docker-compose.yml
+node_modules
</ins><span class="cx" style="display: block; padding: 0 10px"> Thumbs.db
</span><span class="cx" style="display: block; padding: 0 10px"> .DS_Store
</span><span class="cx" style="display: block; padding: 0 10px"> .git
</span><span class="cx" style="display: block; padding: 0 10px">## -13,7 +17,10 ##
</span><span class="cx" style="display: block; padding: 0 10px"> package.json
</span><span class="cx" style="display: block; padding: 0 10px"> README.md
</span><span class="cx" style="display: block; padding: 0 10px"> phpunit.xml
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+phpunit.xml.dist
+LICENSE
</ins><span class="cx" style="display: block; padding: 0 10px"> multisite.xml
</span><span class="cx" style="display: block; padding: 0 10px"> phpcs.ruleset.xml
</span><span class="cx" style="display: block; padding: 0 10px"> bin
</span><span class="cx" style="display: block; padding: 0 10px"> tests
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+swagger.yml
</ins><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterpartsresultsetphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/result-set.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/result-set.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/result-set.php 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,72 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+use PTR\Display;
+
+echo Display::get_display_css(); ?>
+
+<table>
+ <thead>
+ <tr>
+ <th style="width:100px">Revision</th>
+ <th style="width:100px">Status</th>
+ <th>Host</th>
+ <th>PHP Version</th>
+ <th>Database Version</th>
+ <th>Extensions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php
+ $total_cols = 6;
+ foreach ( $revisions as $revision ) :
+ $rev_id = (int) ltrim( $revision->post_name, 'r' );
+ ?>
+ <tr>
+ <th><a href="<?php echo esc_url( sprintf( 'https://core.trac.wordpress.org/changeset/%d', $rev_id ) ); ?>"><?php echo (int) $rev_id; ?></a></th>
+ <th colspan="<?php echo (int) $total_cols - 1; ?>"><?php echo wp_kses_post( apply_filters( 'the_title', $revision->post_title ) ); ?></th>
+ </tr>
+ <?php
+ $query_args = array(
+ 'posts_per_page' => 10,
+ 'post_type' => 'result',
+ 'post_parent' => $revision->ID,
+ 'orderby' => 'post_title',
+ 'order' => 'ASC',
+ );
+ $report_query = new WP_Query( $query_args );
+ if ( ! empty( $report_query->posts ) ) :
+ foreach ( $report_query->posts as $report ) :
+ $status = 'Errored';
+ $status_title = 'No results found for test.';
+ $results = get_post_meta( $report->ID, 'results', true );
+ if ( isset( $results['failures'] ) ) {
+ $status = 0 === (int) $results['failures'] && 0 === (int) $results['errors'] ? 'Passed' : 'Failed';
+ $status_title = (int) $results['tests'] . ' tests, ' . (int) $results['failures'] . ' failed, ' . (int) $results['errors'] . ' errors';
+ }
+ $host = 'Unknown';
+ $user = get_user_by( 'id', $report->post_author );
+ if ( $user ) {
+ $host = $user->display_name;
+ }
+ ?>
+ <tr>
+ <td></td>
+ <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>
+ <td><?php echo esc_html( $host ); ?></td>
+ <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>
+ <td><?php echo esc_html( Display::get_display_extensions( $report->ID ) ); ?></td>
+ </tr>
+ <?php
+ endforeach;
+ else :
+ ?>
+ <tr>
+ <td></td>
+ <td colspan="<?php echo (int) $total_cols - 1; ?>">
+ No reports for changeset.
+ </td>
+ </tr>
+ <?php endif; ?>
+ <?php endforeach; ?>
+ </tbody>
+</table>
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterpartssingleresultphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/single-result.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/single-result.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/parts/single-result.php 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,63 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+use PTR\Display;
+
+$status = 'Errored';
+$status_title = 'No results found for test.';
+$results = get_post_meta( $report->ID, 'results', true );
+if ( isset( $results['failures'] ) ) {
+ $status = 0 === (int) $results['failures'] && 0 === (int) $results['errors'] ? 'Passed' : 'Failed';
+ $status_title = (int) $results['tests'] . ' tests, ' . (int) $results['failures'] . ' failed, ' . (int) $results['errors'] . ' errors';
+}
+$host = 'Unknown';
+$user = get_user_by( 'id', $report->post_author );
+if ( $user ) {
+ $host = $user->display_name;
+} ?>
+
+<?php echo Display::get_display_css(); ?>
+
+<?php
+$parent = get_post( $report->post_parent );
+if ( $parent ) :
+?>
+<p><a href="<?php echo esc_url( get_permalink( $parent ) ); ?>">← <?php echo esc_html( $parent->post_name ) . ': ' . apply_filters( 'the_title', get_the_title( $parent ) ); ?></a></p>
+<?php endif; ?>
+
+<p><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></p>
+
+<h2>Environment</h2>
+
+<table>
+ <tr>
+ <td><strong>Host</strong></td>
+ <td><?php echo esc_html( $host ); ?></td>
+ </tr>
+ <tr>
+ <td><strong>PHP Version</strong></td>
+ <td><?php echo esc_html( Display::get_display_php_version( $report->ID ) ); ?></td>
+ </tr>
+ <tr>
+ <td><strong>Database Version</strong></td>
+ <td><?php echo esc_html( Display::get_display_mysql_version( $report->ID ) ); ?></td>
+ </tr>
+ <tr>
+ <td><strong>Extensions</strong></td>
+ <td><?php echo esc_html( Display::get_display_extensions( $report->ID ) ); ?></td>
+ </tr>
+</table>
+
+<?php if ( ! empty( $results['failures'] ) ) : ?>
+ <h2>Errors/Failures</h2>
+
+ <?php
+ foreach ( $results['testsuites'] as $suite_name => $testsuite ) :
+ if ( empty( $testsuite['failures'] ) && empty( $testsuite['errors'] ) ) {
+ 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; ?>
+ <?php endforeach; ?>
+<?php endif; ?>
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterphpunittestreporterphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/phpunit-test-reporter.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/phpunit-test-reporter.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/phpunit-test-reporter.php 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,53 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Plugin Name: PHPUnit Test Reporter
+ * Plugin URI: https://make.wordpress.org/hosting/phpunit-test-results/
+ * Description: Captures and displays test results from the PHPUnit Test Runner
+ * Author: WordPress Hosting Community
+ * Author URI: https://make.wordpress.org/hosting/
+ * Text Domain: ptr
+ * Domain Path: /languages
+ * Version: 0.1.0
+ * License: GPL v3
+ *
+ * @package PTR
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit; // Exit if accessed directly
+}
+
+require_once dirname( __FILE__ ) . '/src/class-content-model.php';
+require_once dirname( __FILE__ ) . '/src/class-restapi.php';
+require_once dirname( __FILE__ ) . '/src/class-display.php';
+
+add_action( 'init', array( 'PTR\Content_Model', 'action_init_register_post_type' ) );
+add_action( 'init', array( 'PTR\Content_Model', 'action_init_register_role' ) );
+add_action( 'init', array( 'PTR\Display', 'action_init_register_shortcode' ) );
+add_action( 'post_class', array( 'PTR\Display', 'filter_post_class' ) );
+add_action( 'the_content', array( 'PTR\Display', 'filter_the_content' ) );
+add_action( 'rest_api_init', array( 'PTR\RestAPI', 'register_routes' ) );
+
+/**
+ * Get a rendered template part
+ *
+ * @param string $template
+ * @param array $vars
+ * @return string
+ */
+function ptr_get_template_part( $template, $vars = array() ) {
+ $full_path = dirname( __FILE__ ) . '/parts/' . $template . '.php';
+
+ if ( ! file_exists( $full_path ) ) {
+ return '';
+ }
+
+ ob_start();
+ // @codingStandardsIgnoreStart
+ if ( ! empty( $vars ) ) {
+ extract( $vars );
+ }
+ // @codingStandardsIgnoreEnd
+ include $full_path;
+ return ob_get_clean();
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreporterreadmetxt"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/readme.txt</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/readme.txt (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/readme.txt 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,19 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+=== PHPUnit Test Reporter ===
+Contributors: octalmage, danielbachhuber
+Tags: phpunit
+Requires at least: 4.7
+Tested up to: 4.8
+Stable tag: 0.1.0
+License: GPLv3
+License URI: http://www.gnu.org/licenses/gpl-3.0.html
+
+Captures and displays test results from the PHPUnit Test Runner
+
+== Description ==
+
+Captures and displays test results from the PHPUnit Test Runner
+
+== Changelog ==
+
+= 0.1.0 (April 15th, 2017) =
+* Initial release.
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreportersrcclasscontentmodelphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-content-model.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-content-model.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-content-model.php 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,66 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace PTR;
+class Content_Model {
+
+ /**
+ * Create custom post type to store the directories we need to process.
+ *
+ * @since 1.0.0
+ * @return null
+ */
+ public static function action_init_register_post_type() {
+ register_post_type( 'result',
+ array(
+ 'labels' => array(
+ 'name' => __( 'Test Results', 'ptr' ),
+ 'singular_name' => __( 'Test Result', 'ptr' ),
+ ),
+ 'public' => true,
+ 'has_archive' => true,
+ 'show_in_rest' => true,
+ 'hierarchical' => true,
+ 'supports' => array(
+ 'title',
+ 'editor',
+ 'author',
+ 'custom-fields',
+ 'page-attributes',
+ ),
+ 'map_meta_cap' => true,
+ 'capabilities' => array(
+ 'edit_post' => 'edit_result',
+ 'edit_posts' => 'edit_results',
+ 'edit_others_posts' => 'edit_others_results',
+ 'publish_posts' => 'publish_results',
+ 'read_post' => 'read_result',
+ 'read_private_posts' => 'read_private_results',
+ 'delete_post' => 'delete_result',
+ ),
+ )
+ );
+ }
+
+ /**
+ * Create a custom role to manage ability to create results
+ */
+ public static function action_init_register_role() {
+ if ( ! get_role( 'test-reporter' ) ) {
+ add_role( 'test-reporter', __( 'Test Reporter', 'ptr' ), array(
+ 'read' => true,
+ ) );
+ }
+ $role = get_role( 'test-reporter' );
+ if ( $role ) {
+ $role->add_cap( 'edit_results' );
+ $role->add_cap( 'publish_results' );
+ }
+ $role = get_role( 'administrator' );
+ if ( $role ) {
+ $role->add_cap( 'edit_results' );
+ $role->add_cap( 'edit_others_results' );
+ $role->add_cap( 'publish_results' );
+ $role->add_cap( 'read_private_results' );
+ }
+ }
+
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreportersrcclassdisplayphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-display.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-display.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-display.php 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,230 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace PTR;
+
+use WP_Query;
+
+class Display {
+
+ /**
+ * Register the shortcode.
+ */
+ public static function action_init_register_shortcode() {
+ add_shortcode( 'ptr-results', array( __CLASS__, 'render_results' ) );
+ }
+
+ /**
+ * Filter post classes
+ */
+ public static function filter_post_class( $classes ) {
+ if ( is_singular( 'result' ) ) {
+ $classes[] = 'page';
+ }
+ return $classes;
+ }
+
+ /**
+ * Render the data for an individual result within the main content well
+ */
+ public static function filter_the_content( $content ) {
+ if ( ! is_singular( 'result' ) ) {
+ return $content;
+ }
+
+ if ( get_queried_object()->post_parent ) {
+ $content = ptr_get_template_part( 'single-result', array(
+ 'report' => get_queried_object(),
+ ) );
+ } else {
+ $content = ptr_get_template_part( 'result-set', array(
+ 'revisions' => array(
+ get_queried_object(),
+ ),
+ ) );
+ }
+
+ return $content;
+ }
+
+ /**
+ * Render the test results.
+ */
+ public static function render_results( $atts ) {
+
+ $output = '<h2>PHPUnit Test Results</h2>' . PHP_EOL . PHP_EOL;
+ $query_args = array(
+ 'posts_per_page' => 5,
+ 'post_type' => 'result',
+ 'post_parent' => 0,
+ 'orderby' => 'post_name',
+ 'order' => 'DESC',
+ );
+ $paged = get_query_var( 'paged' );
+ if ( $paged ) {
+ $query_args['paged'] = $paged;
+ }
+ $rev_query = new WP_Query( $query_args );
+ if ( empty( $rev_query->posts ) ) {
+ $output .= '<p>No revisions found</p>';
+ return $output;
+ }
+ $output .= self::get_display_css();
+ $output .= ptr_get_template_part( 'result-set', array(
+ 'revisions' => $rev_query->posts,
+ ) );
+ ob_start();
+ self::pagination( $rev_query );
+ $output .= ob_get_clean();
+ return $output;
+ }
+
+ /**
+ * Get the CSS needed for display
+ *
+ * @return string
+ */
+ public static function get_display_css() {
+ ob_start();
+ ?>
+ <style>
+ a.ptr-status-badge {
+ color: #FFF;
+ display: inline-block;
+ padding-left: 8px;
+ padding-right: 8px;
+ padding-top: 3px;
+ padding-bottom: 3px;
+ border-radius: 3px;
+ font-weight: normal;
+ }
+ a.ptr-status-badge-passed {
+ background-color: #39BC00;
+ }
+ a.ptr-status-badge-failed {
+ background-color: #CD543A;
+ }
+ a.ptr-status-badge-errored {
+ background-color: #909090;
+ }
+ .pagination-centered {
+ text-align: center;
+ }
+ .pagination-centered ul.pagination {
+ list-style-type: none;
+ }
+ .pagination-centered ul.pagination li {
+ display: inline-block;
+ }
+ .pagination-centered ul.pagination li a {
+ cursor: pointer;
+ }
+ </style>
+ <?php
+ return ob_get_clean();
+ }
+
+ /**
+ * Get the PHP version for display
+ *
+ * @param integer $report_id Report ID.
+ * @return string
+ */
+ public static function get_display_php_version( $report_id ) {
+ $php_version = 'Unknown';
+ $env = get_post_meta( $report_id, 'env', true );
+ if ( ! empty( $env['php_version'] ) ) {
+ $php_version = 'PHP ' . $env['php_version'];
+ }
+ return $php_version;
+ }
+
+ /**
+ * Get the database version for display
+ *
+ * @param integer $report_id Report ID.
+ * @return string
+ */
+ public static function get_display_mysql_version( $report_id ) {
+ $mysql_version = 'Unknown';
+ $env = get_post_meta( $report_id, 'env', true );
+ if ( ! empty( $env['mysql_version'] ) ) {
+ $bits = explode( ',', $env['mysql_version'] );
+ $mysql_version = $bits[0];
+ }
+ return $mysql_version;
+ }
+
+ /**
+ * Get the extensions list for display
+ *
+ * @param integer $report_id Report ID.
+ * @return string
+ */
+ public static function get_display_extensions( $report_id ) {
+ $extensions = array();
+ $env = get_post_meta( $report_id, 'env', true );
+ if ( ! empty( $env['php_modules'] ) ) {
+ foreach ( $env['php_modules'] as $module => $version ) {
+ if ( ! empty( $version ) ) {
+ $extensions[] = $module . ' (' . $version . ')';
+ }
+ }
+ }
+ if ( ! empty( $env['system_utils'] ) ) {
+ foreach ( $env['system_utils'] as $module => $version ) {
+ if ( ! empty( $version ) ) {
+ $extensions[] = $module . ' (' . $version . ')';
+ }
+ }
+ }
+ return implode( ', ', $extensions );
+ }
+
+ private static function pagination( $query ) {
+ $bignum = 999999999;
+ $base_link = str_replace( $bignum, '%#%', esc_url( get_pagenum_link( $bignum ) ) );
+ $max_num_pages = $query->max_num_pages;
+ $current_page = max( 1, $query->get( 'paged' ) );
+ $prev_page_label = '‹';
+ $next_page_label = '›';
+ $args = array(
+ 'base' => $base_link,
+ 'format' => '',
+ 'current' => $current_page,
+ 'total' => $max_num_pages,
+ 'prev_text' => $prev_page_label,
+ 'next_text' => $next_page_label,
+ 'type' => 'array',
+ 'end_size' => 1,
+ 'mid_size' => 2,
+ );
+
+ if ( $max_num_pages <= 1 ) {
+ return;
+ }
+
+ $pagination_links = paginate_links( $args );
+
+ if ( ! empty( $pagination_links ) ) {
+
+ if ( 1 === $current_page ) {
+ array_unshift( $pagination_links, '<span class="prev page-numbers">' . esc_html( $prev_page_label ) . '</span>' );
+ } elseif ( $current_page >= $max_num_pages ) {
+ array_push( $pagination_links, '<span class="next page-numbers">' . esc_html( $next_page_label ) . '</span>' );
+ }
+
+ echo '<nav class="pagination-centered">';
+
+ echo '<ul class="pagination">';
+ foreach ( $pagination_links as $paginated_link ) {
+ // $paginated_link contains arbitrary HTML
+ echo '<li>' . $paginated_link . '</li>';
+ }
+ echo '</ul>';
+
+ echo '</nav>';
+ }
+
+ }
+
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsphpunittestreportersrcclassrestapiphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-restapi.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-restapi.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-restapi.php 2017-08-16 00:19:05 UTC (rev 5805)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,156 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace PTR;
+
+use WP_Error;
+
+class RestAPI {
+
+ /**
+ * Register REST API routes.
+ *
+ * @action rest_api_init
+ */
+ public static function register_routes() {
+ register_rest_route(
+ 'wp-unit-test-api/v1', 'results', array(
+ 'methods' => 'POST',
+ 'callback' => array( __CLASS__, 'add_results_callback' ),
+ 'args' => array(
+ 'commit' => array(
+ 'required' => true,
+ 'description' => 'The SVN commit changeset number.',
+ 'type' => 'numeric',
+ 'validate_callback' => array( __CLASS__, 'validate_callback' ),
+ ),
+ 'results' => array(
+ 'required' => true,
+ 'description' => 'phpunit results in JSON format.',
+ 'type' => 'string',
+ 'validate_callback' => array( __CLASS__, 'validate_callback' ),
+ ),
+ 'message' => array(
+ 'required' => true,
+ 'description' => 'The SVN commit message.',
+ 'type' => 'string',
+ 'validate_callback' => array( __CLASS__, 'validate_callback' ),
+ ),
+ 'env' => array(
+ 'required' => true,
+ 'description' => 'JSON blob containing information about the environment.',
+ 'type' => 'string',
+ 'validate_callback' => array( __CLASS__, 'validate_callback' ),
+ ),
+ ),
+ 'permission_callback' => array( __CLASS__, 'permission' ),
+ )
+ );
+ }
+
+ public static function validate_callback( $value, $request, $key ) {
+ switch ( $key ) {
+ case 'commit':
+ if ( ! is_numeric( $value ) ) {
+ return new WP_Error( 'rest_invalid', __( 'Value must be numeric.', 'ptr' ), array(
+ 'status' => 400,
+ ) );
+ }
+ return true;
+ case 'message':
+ if ( empty( $value ) || ! is_string( $value ) ) {
+ return new WP_Error( 'rest_invalid', __( 'Value must be a non-empty string.', 'ptr' ), array(
+ 'status' => 400,
+ ) );
+ }
+ return true;
+ case 'env':
+ case 'results':
+ if ( null === json_decode( $value ) ) {
+ return new WP_Error( 'rest_invalid', __( 'Value must be encoded JSON.', 'ptr' ), array(
+ 'status' => 400,
+ ) );
+ }
+ return true;
+ }
+ return new WP_Error( 'rest_invalid', __( 'Invalid key specified.', 'ptr' ), array(
+ 'status' => 400,
+ ) );
+ }
+
+ 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(
+ 'status' => 403,
+ ) );
+ }
+ return true;
+ }
+
+ public static function add_results_callback( $data ) {
+ $parameters = $data->get_params();
+
+ $slug = 'r' . $parameters['commit'];
+ $post = get_page_by_path( $slug, 'OBJECT', 'result' );
+ if ( $post ) {
+ $parent_id = $post->ID;
+ } else {
+ $parent_id = wp_insert_post( array(
+ 'post_title' => $parameters['message'],
+ 'post_name' => $slug,
+ 'post_status' => 'publish',
+ 'post_type' => 'result',
+ ) );
+ }
+
+ $current_user = wp_get_current_user();
+
+ $args = array(
+ 'post_parent' => $parent_id,
+ 'post_type' => 'result',
+ 'numberposts' => 1,
+ 'author' => $current_user->ID,
+ );
+
+ // Check to see if the test result already exist.
+ $results = get_posts( $args );
+ if ( $results ) {
+ $post_id = $results[0]->ID;
+ } else {
+ $results = array(
+ 'post_title' => $current_user->user_login . ' - ' . $slug,
+ 'post_content' => '',
+ 'post_status' => 'publish',
+ 'post_author' => $current_user->ID,
+ 'post_type' => 'result',
+ 'post_parent' => $parent_id,
+ );
+
+ // Store the results.
+ $post_id = wp_insert_post( $results, true );
+ }
+
+ if ( is_wp_error( $post_id ) ) {
+ return $post_id;
+ }
+
+ $env = isset( $parameters['env'] ) ? json_decode( $parameters['env'], true ) : array();
+ $results = isset( $parameters['results'] ) ? json_decode( $parameters['results'], true ) : array();
+
+ update_post_meta( $post_id, 'env', $env );
+ update_post_meta( $post_id, 'results', $results );
+
+ // Create the response object.
+ $response = new \WP_REST_Response(
+ array(
+ 'id' => $post_id,
+ 'link' => get_permalink( $post_id ),
+ )
+ );
+
+ // Add a custom status code.
+ $response->set_status( 201 );
+
+ $response->header( 'Content-Type', 'application/json' );
+
+ return $response;
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>