<!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>[10769] sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook: Handbooks, Init & Handbook: Improve multi-handbook support and configuration handling</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 { white-space: pre-line; 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/10769">10769</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/10769","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>coffee2code</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-03-05 00:21:47 +0000 (Fri, 05 Mar 2021)</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'>Handbooks, Init & Handbook: Improve multi-handbook support and configuration handling
Init:
* Introduce `'handbooks_config'` as filter for defining and configuring handbooks
* Deprecate `'handbook_post_types'` as filter for defining handbooks
* Store handbook objects as an associative array with post types as keys
* Discontinue explicitly memoizing handbook post types
* Introduce `get_handbooks_config()` to retrieve config for a particular handbook or all handbooks
Handbook:
* Change constructor to accept config array as optional arg
* Introduce `get_config()` as a getter to return handbook's config
* Start with 'label' and 'slug' as a config options</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookinchandbookphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincinitphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/init.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookphpunittestsinitphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/init.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookinchandbookphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.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/handbook/inc/handbook.php 2021-03-05 00:05:23 UTC (rev 10768)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php 2021-03-05 00:21:47 UTC (rev 10769)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,6 +15,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public $post_type = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The handbook's settings.
+ *
+ * @var array
+ */
+ public $settings = [];
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * The name of the setting for the handbook's name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @var string
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,6 +66,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns handbook default config.
+ *
+ * @return array
+ */
+ public static function get_default_handbook_config() {
+ /**
+ * Filters default handbook configuration array.
+ *
+ * @param string $slug The slug for the post type. Default is post type.
+ */
+ return (array) apply_filters( 'handbook_default_handbook_config', [
+ 'label' => '',
+ 'slug' => '',
+ ] );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Returns the handbook name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * If one isn't set via settings, one is generated.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -94,13 +118,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Constructor
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $type The post type for the handbook.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $config The config array for the handbook.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function __construct( $type ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function __construct( $type, $config = [] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->post_type = sanitize_title( $type );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->label = ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) );
- $this->label = apply_filters( 'handbook_label', $this->label, $this->post_type );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $config = $this->config = wp_parse_args( $config, self::get_default_handbook_config() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->label = apply_filters(
+ 'handbook_label',
+ $config['label'] ?: ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) ),
+ $this->post_type
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->setting_name = $this->post_type . '_name';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'user_has_cap', [ $this, 'grant_handbook_caps' ] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,6 +156,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns the configuration array for handbooks.
+ *
+ * @return array
+ */
+ public function get_config() {
+ return $this->config;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Adds 'Handbook Front Page' post state indicator for handbook landing pages.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string[] $post_states An array of post display states.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,8 +273,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Registers handbook post types.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function register_post_type() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'handbook' != $this->post_type ) {
- $slug = substr( $this->post_type, 0, -9 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $config = $this->get_config();
+
+ if ( ! empty( $config['slug'] ) ) {
+ $slug = $config['slug'];
+ } elseif ( 'handbook' !== $this->post_type ) {
+ $slug = str_replace( '-handbook', '', $this->post_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $slug = 'handbook';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincinitphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/init.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/handbook/inc/init.php 2021-03-05 00:05:23 UTC (rev 10768)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/init.php 2021-03-05 00:21:47 UTC (rev 10769)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8,7 +8,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class WPorg_Handbook_Init {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Array of WPorg_Handbook objects.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Asociative array of WPorg_Handbook objects.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -41,22 +41,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_post_types() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Filters the handbook post types for creating handbooks.
- *
- * @param array $handbooks Array of handbook post types. Default 'handbook'.
- */
- $post_types = (array) apply_filters( 'handbook_post_types', [ 'handbook' ] );
- return array_map(
- function( $pt ) {
- $pt = sanitize_title( $pt );
- return ( in_array( $pt, [ 'handbook', 'page' ] ) || false !== strpos( $pt, '-handbook' ) ) ? $pt : $pt . '-handbook';
- },
- $post_types
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return array_keys( self::$handbooks );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns the handbooks configurations.
+ *
+ * @param string $handbook Optional. A specific handbook to return config for.
+ * If none specified, then all are returned. Default ''.
+ * @return array|false If $handbook defined, then the config for that handbook
+ * if handbook exists, else false. If no $handbook specified,
+ * then an associative array of config for all handbooks,
+ * keyed by post type.
+ */
+ public static function get_handbooks_config( $handbook = '' ) {
+ $return = false;
+ $handbooks = self::get_handbook_objects();
+
+ // If no handbook specified, return configs for all handbooks.
+ if ( ! $handbook ) {
+ $return = [];
+ foreach ( $handbooks as $type => $handbook_obj ) {
+ $return[ $type ] = $handbook_obj->get_config();
+ }
+ }
+
+ return ( $handbook && ! empty( $handbooks[ $handbook ] ) && is_a( $handbooks[ $handbook ], 'WPorg_Handbook' ) )
+ ? $handbooks[ $handbook ]->get_config()
+ : $return;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Resets memoized and cached variables.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $delete_handbook_objects Optional. Delete associated handbook
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -76,11 +91,67 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Initializes handbooks.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function init() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $config = [];
+ $handbooks_config = [];
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires before handbooks have been initialized.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'before_handbooks_init' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the handbook post types for creating handbooks.
+ *
+ * @deprecated Use {@see 'handbooks_config'} instead.
+ *
+ * @param array $handbooks Array of handbook post types. Default empty
+ * array, which later will be interpreted to
+ * be 'handbook'.
+ */
+ $post_types = (array) apply_filters( 'handbook_post_types', [] );
+
+ foreach ( $post_types as $post_type ) {
+ $config[ $post_type ] = [];
+ }
+
+ /**
+ * Defines and configures all handbooks.
+ *
+ * @param array $config {
+ * Associative array of post types and their configuration options. The keys should actually be
+ * the post type base, hypenated and without appending '-handbook' (which will automatically get
+ * appended when the handbook post type is created, if the key isn't "handbook"). Default is 'handbook'.
+ *
+ * @type string $label The label for the handbook. Default is the
+ * post type slug converted to titlecase (e.g.
+ * plugin-handbok => "Plugin Handbook").
+ * @type string $slug The slug for the post type. Default is the
+ * post type.
+ * }
+ */
+ $config = (array) apply_filters( 'handbooks_config', $config );
+
+ // If no handbooks were configured, default to a basic handbook.
+ if ( ! $config ) {
+ $config = [ 'handbook' => [] ];
+ }
+
+ // Get default settings for a handbook.
+ $defaults = WPorg_Handbook::get_default_handbook_config();
+
+ // Determine each handbook's config.
+ foreach ( $config as $key => $value ) {
+ $key = sanitize_title( $key );
+ $post_type = ( 'handbook' === $key || false !== strpos( $key, '-handbook' ) ) ? $key : $key . '-handbook';
+
+ $handbooks_config[ $post_type ] = wp_parse_args( $value, $defaults );
+
+ // Set slug if not explicitly set.
+ if ( empty( $handbooks_config[ $post_type ]['slug'] ) ) {
+ $handbooks_config[ $post_type ]['slug'] = $key;
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_types = self::get_post_types();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Enable table of contents.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,8 +159,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Instantiate each of the handbooks.
</span><span class="cx" style="display: block; padding: 0 10px"> self::$handbooks = [];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $post_types as $type ) {
- self::$handbooks[] = new WPorg_Handbook( $type );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $handbooks_config as $type => $conf ) {
+ self::$handbooks[ $type ] = new WPorg_Handbook( $type, $conf );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Enable glossary.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookphpunittestsinitphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/init.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/handbook/phpunit/tests/init.php 2021-03-05 00:05:23 UTC (rev 10768)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/init.php 2021-03-05 00:21:47 UTC (rev 10769)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,6 +19,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> //
</span><span class="cx" style="display: block; padding: 0 10px"> //
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // DATA PROVIDERS
+ //
+ //
+
+
+ public static function get_default_config() {
+ return [
+ [ 'label', '' ],
+ [ 'manifest', '' ],
+ [ 'slug', '' ],
+ [ 'with_front', '' ],
+ ];
+ }
+
+
+ //
+ //
</ins><span class="cx" style="display: block; padding: 0 10px"> // TESTS
</span><span class="cx" style="display: block; padding: 0 10px"> //
</span><span class="cx" style="display: block; padding: 0 10px"> //
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -142,4 +159,72 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( wp_script_is( 'wporg-handbook', 'enqueued' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * get_handbooks_config()
+ */
+
+ /**
+ * @dataProvider get_default_config
+ */
+ public function test_get_handbooks_config_default( $key, $default ) {
+ $configs = WPorg_Handbook_Init::get_handbooks_config();
+ $this->assertArrayHasKey( 'handbook', $configs );
+ $this->assertEquals( 1, count( $configs ) );
+
+ $config = $configs['handbook'];
+
+ $this->assertArrayHasKey( $key, $config );
+ $value = $config[ $key ];
+
+ if ( 'slug' === $key ) {
+ $this->assertEquals( 'handbook', $value );
+ } elseif ( '' === $default ) {
+ $this->assertEmpty( $value );
+ } else {
+ $this->assertEquals( $default, $value );
+ }
+ }
+
+ public function test_get_handbooks_config_non_handbook() {
+ $this->assertEmpty( WPorg_Handbook_Init::get_handbooks_config( 'nonexistent-handbook' ) );
+ }
+
+ /**
+ * @dataProvider get_default_config
+ */
+ public function test_get_handbooks_config_specific_handbook_default( $key, $default ) {
+ $config = WPorg_Handbook_Init::get_handbooks_config( 'handbook' );
+
+ $this->assertArrayHasKey( $key, $config );
+ $value = $config[ $key ];
+
+ if ( 'slug' === $key ) {
+ $this->assertEquals( 'handbook', $value );
+ } elseif ( '' === $default ) {
+ $this->assertEmpty( $value );
+ } else {
+ $this->assertEquals( $default, $value );
+ }
+ }
+
+ /**
+ * @dataProvider get_default_config
+ */
+ public function test_get_handbooks_config_specific_custom_handbook( $key, $default ) {
+ reinit_handbooks( [ 'plugins' => [] ] );
+
+ $config = WPorg_Handbook_Init::get_handbooks_config( 'plugins-handbook' );
+
+ $this->assertArrayHasKey( $key, $config );
+ $value = $config[ $key ];
+
+ if ( 'slug' === $key ) {
+ $this->assertEquals( 'plugins', $value );
+ } elseif ( '' === $default ) {
+ $this->assertEmpty( $value );
+ } else {
+ $this->assertEquals( $default, $value );
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>