<!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>[BuddyPress][9608] trunk: `bp_core_get_directory_page_ids()` should skip `bp_is_active()` check in save context.</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://buddypress.trac.wordpress.org/changeset/9608">9608</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/9608","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-03-10 15:23:36 +0000 (Tue, 10 Mar 2015)</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'>`bp_core_get_directory_page_ids()` should skip `bp_is_active()` check in save context.

In <a href="http://buddypress.trac.wordpress.org/changeset/9177">[9177]</a>, a `bp_is_active()` check was added to `bp_core_get_directory_page_ids()`
such that the function would not return page mappings for inactive components.
This change caused problems for custom components, as the `bp_is_active()`
check didn't always pass for components that didn't manually set themselves in
the active_components array. <a href="http://buddypress.trac.wordpress.org/changeset/9553">[9553]</a> and <a href="http://buddypress.trac.wordpress.org/changeset/9555">[9555]</a> addressed this problem by only
filtering out packaged components. See <a href="http://buddypress.trac.wordpress.org/ticket/6244">#6244</a>. But this fix was not truly
general, as it still resulted in the deletion of bp-pages entries related to
third-party deactivated components when saving the page mapping settings.

This changeset introduces a more general fix, by distinguishing between two
different use "contexts" of `bp_core_get_directory_page_ids()`:
* Read-only - When pulling up page IDs for display or for URI parsing, deactivated components should be ignored.
* Save - When modifying the bp-pages array stored in the database, we should be working with raw page data, including deactivated components.

The new `$status` parameter for `bp_core_get_directory_page_ids()` addresses
this distinction (possible values 'all' and 'active'). We then pass 'all' as
required in BP - namely, when modifying the bp-pages setting. This change
supercedes the fixes from <a href="http://buddypress.trac.wordpress.org/ticket/6244">#6244</a>.

Props dtc7240, boonebgorges.
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/6280">#6280</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcoreadminbpcoreadmincomponentsphp">trunk/src/bp-core/admin/bp-core-admin-components.php</a></li>
<li><a href="#trunksrcbpcorebpcorecachephp">trunk/src/bp-core/bp-core-cache.php</a></li>
<li><a href="#trunksrcbpcorebpcorefunctionsphp">trunk/src/bp-core/bp-core-functions.php</a></li>
<li><a href="#trunktestsphpunittestcasesadminfunctionsphp">trunk/tests/phpunit/testcases/admin/functions.php</a></li>
<li><a href="#trunktestsphpunittestcasescorefunctionsphp">trunk/tests/phpunit/testcases/core/functions.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestcasescorefunctionsbpCoreGetDirectoryPageIdsphp">trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpcoreadminbpcoreadmincomponentsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/admin/bp-core-admin-components.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/admin/bp-core-admin-components.php      2015-03-09 15:39:44 UTC (rev 9607)
+++ trunk/src/bp-core/admin/bp-core-admin-components.php        2015-03-10 15:23:36 UTC (rev 9608)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -309,9 +309,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $current_action = $_GET['action'];
</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">-        $current_components       = buddypress()->active_components;
-       $packaged_components      = array_flip( bp_core_get_packaged_component_ids() );
-       $custom_active_components = array_diff_key( $current_components, $packaged_components );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $current_components = buddypress()->active_components;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        switch ( $current_action ) {
</span><span class="cx" style="display: block; padding: 0 10px">                case 'retired' :
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -319,11 +317,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( array_keys( $retired_components ) as $retired_component ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( ! isset( $submitted[ $retired_component ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        unset( $current_components[ $retired_component ] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                                       // Make sure custom components does not contain a retired component
-                                       if ( isset( $custom_active_components[ $retired_component ] ) ) {
-                                               unset( $custom_active_components[ $retired_component ] );
-                                       }
</del><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">                        // fall through
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,8 +332,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        break;
</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">-        // Active components is the list of packaged and custom components
-       return array_merge( $components, $custom_active_components );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $components;
</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></span></pre></div>
<a id="trunksrcbpcorebpcorecachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-cache.php       2015-03-09 15:39:44 UTC (rev 9607)
+++ trunk/src/bp-core/bp-core-cache.php 2015-03-10 15:23:36 UTC (rev 9608)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,7 +69,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return;
</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">-        $page_ids = bp_core_get_directory_page_ids();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $page_ids = bp_core_get_directory_page_ids( 'all' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( ! in_array( $post_id, (array) $page_ids ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                return;
</span></span></pre></div>
<a id="trunksrcbpcorebpcorefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-functions.php   2015-03-09 15:39:44 UTC (rev 9607)
+++ trunk/src/bp-core/bp-core-functions.php     2015-03-10 15:23:36 UTC (rev 9608)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -418,10 +418,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since BuddyPress (1.5.0)
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $status 'active' to return only pages associated with active components, 'all' to return all saved
+ *                       pages. When running save routines, use 'all' to avoid removing data related to inactive
+ *                       components. Default: 'active'.
</ins><span class="cx" style="display: block; padding: 0 10px">  * @return array|string An array of page IDs, keyed by component names, or an
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *         empty string if the list is not found.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *                      empty string if the list is not found.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function bp_core_get_directory_page_ids() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function bp_core_get_directory_page_ids( $status = 'active' ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         $page_ids = bp_get_option( 'bp-pages' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Ensure that empty indexes are unset. Should only matter in edge cases
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -436,9 +439,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</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">-                        if ( ! bp_is_active( $component_name ) || 'trash' == get_post_status( $page_id ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Trashed pages should not appear in results.
+                       if ( 'trash' == get_post_status( $page_id ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 unset( $page_ids[ $component_name ] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       // Remove inactive component pages, if required.
+                       if ( 'active' === $status && ! bp_is_active( $component_name ) ) {
+                               unset( $page_ids[ $component_name ] );
+                       }
</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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -548,7 +558,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                switch_to_blog( bp_get_root_blog_id() );
</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">-        $pages = bp_core_get_directory_page_ids();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $pages = bp_core_get_directory_page_ids( 'all' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Delete any existing pages
</span><span class="cx" style="display: block; padding: 0 10px">        if ( 'delete' === $existing ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -639,7 +649,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return;
</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">-        $page_ids       = bp_core_get_directory_page_ids();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $page_ids       = bp_core_get_directory_page_ids( 'all' );
</ins><span class="cx" style="display: block; padding: 0 10px">         $component_name = array_search( $post_id, $page_ids );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( ! empty( $component_name ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -745,7 +755,7 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids( 'all' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         bp_core_update_directory_page_ids( $page_ids );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsphpunittestcasesadminfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/admin/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/admin/functions.php 2015-03-09 15:39:44 UTC (rev 9607)
+++ trunk/tests/phpunit/testcases/admin/functions.php   2015-03-10 15:23:36 UTC (rev 9608)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -144,13 +144,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_name'  => $bp->foo->slug,
</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">-                $page_ids = array_merge( $new_page_ids, (array) bp_core_get_directory_page_ids() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $page_ids = array_merge( $new_page_ids, (array) bp_core_get_directory_page_ids( 'all' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 bp_core_update_directory_page_ids( $page_ids );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $reset_active_components );
</span><span class="cx" style="display: block; padding: 0 10px">                bp_core_add_page_mappings( $bp->active_components );
</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->assertContains( $bp->foo->id, array_keys( bp_core_get_directory_page_ids() ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertContains( $bp->foo->id, array_keys( bp_core_get_directory_page_ids( 'all' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Reset buddypress() vars
</span><span class="cx" style="display: block; padding: 0 10px">                $bp->active_components = $reset_active_components;
</span></span></pre></div>
<a id="trunktestsphpunittestcasescorefunctionsbpCoreGetDirectoryPageIdsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php                                (rev 0)
+++ trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php  2015-03-10 15:23:36 UTC (rev 9608)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,288 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group core
+ * @covers ::bp_core_get_directory_page_ids
+ */
+class BP_Tests_Core_Functions_BpCoreGetDirectoryPageIds extends BP_UnitTestCase {
+       public function test_bp_core_get_directory_page_ids_on_directory_page_to_trash() {
+               $old_page_ids = bp_core_get_directory_page_ids();
+
+               // Grab the and remove the first page.
+               foreach ( $old_page_ids as $component => $page_id ) {
+                       $p = $page_id;
+                       unset( $old_page_ids[ $component ] );
+                       break;
+               }
+
+               // Move page to trash.
+               wp_delete_post( $p, false );
+
+               $new_page_ids = bp_core_get_directory_page_ids();
+
+               $this->assertEquals( $old_page_ids, $new_page_ids );
+       }
+
+       public function test_bp_core_get_directory_page_ids_on_directory_page_delete() {
+               $old_page_ids = bp_core_get_directory_page_ids();
+
+               // Grab the and remove the first page.
+               foreach ( $old_page_ids as $component => $page_id ) {
+                       $p = $page_id;
+                       unset( $old_page_ids[ $component ] );
+                       break;
+               }
+
+               // Force delete page.
+               wp_delete_post( $p, true );
+
+               $new_page_ids = bp_core_get_directory_page_ids();
+
+               $this->assertEquals( $old_page_ids, $new_page_ids );
+       }
+
+       public function test_bp_core_get_directory_page_ids_on_non_directory_page_delete() {
+               $old_page_ids = bp_core_get_directory_page_ids();
+
+               $p = $this->factory->post->create( array(
+                       'post_status' => 'publish',
+                       'post_type' => 'page',
+               ) );
+
+               // Force delete page.
+               wp_delete_post( $p, true );
+
+               $new_page_ids = bp_core_get_directory_page_ids();
+
+               $this->assertEquals( $old_page_ids, $new_page_ids );
+       }
+
+       public function test_bp_core_get_directory_page_ids_non_active_component() {
+               $old_page_ids = bp_core_get_directory_page_ids();
+               $bp = buddypress();
+
+               // Grab the and remove the first page.
+               foreach ( $old_page_ids as $component => $page_id ) {
+                       $p = $page_id;
+                       $c = $component;
+                       unset( $old_page_ids[ $component ] );
+                       break;
+               }
+
+               // Deactivate component.
+               unset( $bp->active_components[ $c ] );
+
+               $new_page_ids = bp_core_get_directory_page_ids();
+
+               // Restore components.
+               $bp->active_components[ $c ] = 1;
+
+               $this->assertEquals( $old_page_ids, $new_page_ids );
+       }
+
+       /**
+        * @ticket BP6280
+        */
+       public function test_inactive_components_should_not_be_removed_if_status_is_all() {
+               $old_page_ids = bp_core_get_directory_page_ids( 'all' );
+
+               $page_ids = $old_page_ids;
+               $page_ids['foo'] = 12345;
+
+               bp_core_update_directory_page_ids( $page_ids );
+               $found = bp_core_get_directory_page_ids( 'all' );
+
+               $this->assertEquals( 12345, $found['foo'] );
+       }
+
+       /**
+        * @ticket BP6280
+        */
+       public function test_inactive_components_should_be_removed_if_status_is_active() {
+               $old_page_ids = bp_core_get_directory_page_ids( 'all' );
+
+               $page_ids = $old_page_ids;
+               $page_ids['foo'] = 12345;
+
+               bp_core_update_directory_page_ids( $page_ids );
+               $found = bp_core_get_directory_page_ids( 'active' );
+
+               $this->assertFalse( isset( $found['foo'] ) );
+       }
+
+       /**
+        * @ticket BP6280
+        */
+       public function test_inactive_components_should_be_removed_if_status_is_unspecified() {
+               $old_page_ids = bp_core_get_directory_page_ids( 'all' );
+
+               $page_ids = $old_page_ids;
+               $page_ids['foo'] = 12345;
+
+               bp_core_update_directory_page_ids( $page_ids );
+               $found = bp_core_get_directory_page_ids( 'active' );
+
+               $this->assertFalse( isset( $found['foo'] ) );
+       }
+
+       public function test_bp_core_get_directory_page_ids_should_contain_register_and_activet_pages_when_registration_is_open() {
+               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               $ac = buddypress()->active_components;
+               bp_core_add_page_mappings( array_keys( $ac ) );
+
+               $page_ids = bp_core_get_directory_page_ids();
+               $page_names = array_keys( $page_ids );
+
+               $this->assertContains( 'register', $page_names );
+               $this->assertContains( 'activate', $page_names );
+
+               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+       }
+
+       public function test_bp_core_get_directory_page_ids_should_not_contain_register_and_activet_pages_when_registration_is_closed() {
+
+               // Make sure the pages exist, to verify they're filtered out.
+               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+               $ac = buddypress()->active_components;
+               bp_core_add_page_mappings( array_keys( $ac ) );
+               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               // Get page ids
+               $page_ids = bp_core_get_directory_page_ids();
+
+               // Need to delete these pages as previously created.
+               wp_delete_post( $page_ids['register'], true );
+               wp_delete_post( $page_ids['activate'], true );
+
+               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+               bp_core_add_page_mappings( array_keys( $ac ) );
+               $page_ids = bp_core_get_directory_page_ids();
+               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               $page_names = array_keys( $page_ids );
+
+               $this->assertNotContains( 'register', $page_names );
+               $this->assertNotContains( 'activate', $page_names );
+       }
+
+       public function test_bp_core_get_directory_pages_register_activate_page_created_signups_allowed() {
+               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               $ac = buddypress()->active_components;
+               bp_core_add_page_mappings( array_keys( $ac ) );
+               $directory_pages = bp_core_get_directory_pages();
+
+               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               $this->assertTrue( isset( $directory_pages->register ) );
+               $this->assertTrue( isset( $directory_pages->activate ) );
+
+               $r = get_post( $directory_pages->register->id );
+               $this->assertTrue( 'publish' == $r->post_status );
+
+               $a = get_post( $directory_pages->activate->id );
+               $this->assertTrue( 'publish' == $a->post_status );
+       }
+
+       public function test_bp_core_get_directory_pages_register_activate_page_notcreated_signups_allowed() {
+               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               $ac = buddypress()->active_components;
+               bp_core_add_page_mappings( array_keys( $ac ) );
+
+               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               $directory_pages = bp_core_get_directory_pages();
+
+               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               $this->assertFalse( isset( $directory_pages->register ) );
+               $this->assertFalse( isset( $directory_pages->activate ) );
+       }
+
+       public function test_bp_core_get_directory_pages_register_activate_page_created_signups_notallowed() {
+               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               $ac = buddypress()->active_components;
+               bp_core_add_page_mappings( array_keys( $ac ) );
+
+               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
+
+               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               $directory_pages = bp_core_get_directory_pages();
+
+               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               $this->assertTrue( isset( $directory_pages->register ) );
+               $this->assertTrue( isset( $directory_pages->activate ) );
+
+               $r = get_post( $directory_pages->register->id );
+               $this->assertTrue( 'publish' == $r->post_status );
+
+               $a = get_post( $directory_pages->activate->id );
+               $this->assertTrue( 'publish' == $a->post_status );
+       }
+
+       public function test_bp_core_get_directory_pages_register_activate_page_notcreated_signups_notallowed() {
+
+               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               $ac = buddypress()->active_components;
+               bp_core_add_page_mappings( array_keys( $ac ) );
+               $directory_pages = bp_core_get_directory_pages();
+
+               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
+
+               $this->assertFalse( isset( $directory_pages->register ) );
+               $this->assertFalse( isset( $directory_pages->activate ) );
+       }
+
+       public function test_bp_core_get_directory_pages_pages_settings_update() {
+               // Set the cache
+               $pages = bp_core_get_directory_pages();
+
+               // Mess with it but put it back
+               $v = bp_get_option( 'bp-pages' );
+               bp_update_option( 'bp-pages', 'foo' );
+
+               $this->assertFalse( wp_cache_get( 'directory_pages', 'bp' ) );
+
+               bp_update_option( 'bp-pages', $v );
+       }
+
+       public function test_bp_core_get_directory_pages_multisite_delete_post_with_same_bp_page_id() {
+               if ( ! is_multisite() ) {
+                       return;
+               }
+
+               $dir_pages = bp_core_get_directory_pages();
+
+               // create a blog
+               $u = $this->factory->user->create();
+               $b1 = $this->factory->blog->create( array( 'user_id' => $u ) );
+
+               // switch to blog and create some dummy posts until we reach a post ID that
+               // matches our BP activity page ID
+               switch_to_blog( $b1 );
+               $p = $this->factory->post->create();
+               while( $p <= $dir_pages->activity->id ) {
+                       $p = $this->factory->post->create();
+               }
+
+               // delete the post that matches the BP activity page ID on this sub-site
+               wp_delete_post( $dir_pages->activity->id, true );
+
+               // restore blog
+               restore_current_blog();
+
+               // refetch BP directory pages
+               $dir_pages = bp_core_get_directory_pages();
+
+               // Now verify that our BP activity page was not wiped out
+               $this->assertNotEmpty( $dir_pages->activity );
+       }
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestcasescorefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/core/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/core/functions.php  2015-03-09 15:39:44 UTC (rev 9607)
+++ trunk/tests/phpunit/testcases/core/functions.php    2015-03-10 15:23:36 UTC (rev 9608)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -452,278 +452,6 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @group bp_core_get_directory_page_ids
-        */
-       public function test_bp_core_get_directory_page_ids_on_directory_page_to_trash() {
-               $old_page_ids = bp_core_get_directory_page_ids();
-
-               // Grab the and remove the first page.
-               foreach ( $old_page_ids as $component => $page_id ) {
-                       $p = $page_id;
-                       unset( $old_page_ids[ $component ] );
-                       break;
-               }
-
-               // Move page to trash.
-               wp_delete_post( $p, false );
-
-               $new_page_ids = bp_core_get_directory_page_ids();
-
-               $this->assertEquals( $old_page_ids, $new_page_ids );
-       }
-
-       /**
-        * @group bp_core_get_directory_page_ids
-        */
-       public function test_bp_core_get_directory_page_ids_on_directory_page_delete() {
-               $old_page_ids = bp_core_get_directory_page_ids();
-
-               // Grab the and remove the first page.
-               foreach ( $old_page_ids as $component => $page_id ) {
-                       $p = $page_id;
-                       unset( $old_page_ids[ $component ] );
-                       break;
-               }
-
-               // Force delete page.
-               wp_delete_post( $p, true );
-
-               $new_page_ids = bp_core_get_directory_page_ids();
-
-               $this->assertEquals( $old_page_ids, $new_page_ids );
-       }
-
-       /**
-        * @group bp_core_get_directory_page_ids
-        */
-       public function test_bp_core_get_directory_page_ids_on_non_directory_page_delete() {
-               $old_page_ids = bp_core_get_directory_page_ids();
-
-               $p = $this->factory->post->create( array(
-                       'post_status' => 'publish',
-                       'post_type' => 'page',
-               ) );
-
-               // Force delete page.
-               wp_delete_post( $p, true );
-
-               $new_page_ids = bp_core_get_directory_page_ids();
-
-               $this->assertEquals( $old_page_ids, $new_page_ids );
-       }
-
-       /**
-        * @group bp_core_get_directory_page_ids
-        */
-       public function test_bp_core_get_directory_page_ids_non_active_component() {
-               $old_page_ids = bp_core_get_directory_page_ids();
-               $bp = buddypress();
-
-               // Grab the and remove the first page.
-               foreach ( $old_page_ids as $component => $page_id ) {
-                       $p = $page_id;
-                       $c = $component;
-                       unset( $old_page_ids[ $component ] );
-                       break;
-               }
-
-               // Deactivate component.
-               unset( $bp->active_components[ $c ] );
-
-               $new_page_ids = bp_core_get_directory_page_ids();
-
-               // Restore components.
-               $bp->active_components[ $c ] = 1;
-
-               $this->assertEquals( $old_page_ids, $new_page_ids );
-       }
-
-       /**
-        * @group bp_core_get_directory_page_ids
-        */
-       public function test_bp_core_get_directory_page_ids_should_contain_register_and_activet_pages_when_registration_is_open() {
-               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               $ac = buddypress()->active_components;
-               bp_core_add_page_mappings( array_keys( $ac ) );
-
-               $page_ids = bp_core_get_directory_page_ids();
-               $page_names = array_keys( $page_ids );
-
-               $this->assertContains( 'register', $page_names );
-               $this->assertContains( 'activate', $page_names );
-
-               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-       }
-
-       /**
-        * @group bp_core_get_directory_page_ids
-        */
-       public function test_bp_core_get_directory_page_ids_should_not_contain_register_and_activet_pages_when_registration_is_closed() {
-
-               // Make sure the pages exist, to verify they're filtered out.
-               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-               $ac = buddypress()->active_components;
-               bp_core_add_page_mappings( array_keys( $ac ) );
-               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               // Get page ids
-               $page_ids = bp_core_get_directory_page_ids();
-
-               // Need to delete these pages as previously created.
-               wp_delete_post( $page_ids['register'], true );
-               wp_delete_post( $page_ids['activate'], true );
-
-               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-               bp_core_add_page_mappings( array_keys( $ac ) );
-               $page_ids = bp_core_get_directory_page_ids();
-               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               $page_names = array_keys( $page_ids );
-
-               $this->assertNotContains( 'register', $page_names );
-               $this->assertNotContains( 'activate', $page_names );
-       }
-
-       /**
-        * @group bp_core_get_directory_pages
-        */
-       public function test_bp_core_get_directory_pages_register_activate_page_created_signups_allowed() {
-               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               $ac = buddypress()->active_components;
-               bp_core_add_page_mappings( array_keys( $ac ) );
-               $directory_pages = bp_core_get_directory_pages();
-
-               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               $this->assertTrue( isset( $directory_pages->register ) );
-               $this->assertTrue( isset( $directory_pages->activate ) );
-
-               $r = get_post( $directory_pages->register->id );
-               $this->assertTrue( 'publish' == $r->post_status );
-
-               $a = get_post( $directory_pages->activate->id );
-               $this->assertTrue( 'publish' == $a->post_status );
-       }
-
-       /**
-        * @group bp_core_get_directory_pages
-        */
-       public function test_bp_core_get_directory_pages_register_activate_page_notcreated_signups_allowed() {
-               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               $ac = buddypress()->active_components;
-               bp_core_add_page_mappings( array_keys( $ac ) );
-
-               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               $directory_pages = bp_core_get_directory_pages();
-
-               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               $this->assertFalse( isset( $directory_pages->register ) );
-               $this->assertFalse( isset( $directory_pages->activate ) );
-       }
-
-       /**
-        * @group bp_core_get_directory_pages
-        */
-       public function test_bp_core_get_directory_pages_register_activate_page_created_signups_notallowed() {
-               add_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               $ac = buddypress()->active_components;
-               bp_core_add_page_mappings( array_keys( $ac ) );
-
-               remove_filter( 'bp_get_signup_allowed', '__return_true', 999 );
-
-               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               $directory_pages = bp_core_get_directory_pages();
-
-               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               $this->assertTrue( isset( $directory_pages->register ) );
-               $this->assertTrue( isset( $directory_pages->activate ) );
-
-               $r = get_post( $directory_pages->register->id );
-               $this->assertTrue( 'publish' == $r->post_status );
-
-               $a = get_post( $directory_pages->activate->id );
-               $this->assertTrue( 'publish' == $a->post_status );
-       }
-
-       /**
-        * @group bp_core_get_directory_pages
-        */
-       public function test_bp_core_get_directory_pages_register_activate_page_notcreated_signups_notallowed() {
-
-               add_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               $ac = buddypress()->active_components;
-               bp_core_add_page_mappings( array_keys( $ac ) );
-               $directory_pages = bp_core_get_directory_pages();
-
-               remove_filter( 'bp_get_signup_allowed', '__return_false', 999 );
-
-               $this->assertFalse( isset( $directory_pages->register ) );
-               $this->assertFalse( isset( $directory_pages->activate ) );
-       }
-
-       /**
-        * @group bp_core_get_directory_pages
-        */
-       public function test_bp_core_get_directory_pages_pages_settings_update() {
-               // Set the cache
-               $pages = bp_core_get_directory_pages();
-
-               // Mess with it but put it back
-               $v = bp_get_option( 'bp-pages' );
-               bp_update_option( 'bp-pages', 'foo' );
-
-               $this->assertFalse( wp_cache_get( 'directory_pages', 'bp' ) );
-
-               bp_update_option( 'bp-pages', $v );
-       }
-
-       /**
-        * @group bp_core_get_directory_pages
-        */
-       public function test_bp_core_get_directory_pages_multisite_delete_post_with_same_bp_page_id() {
-               if ( ! is_multisite() ) {
-                       return;
-               }
-
-               $dir_pages = bp_core_get_directory_pages();
-
-               // create a blog
-               $u = $this->factory->user->create();
-               $b1 = $this->factory->blog->create( array( 'user_id' => $u ) );
-
-               // switch to blog and create some dummy posts until we reach a post ID that
-               // matches our BP activity page ID
-               switch_to_blog( $b1 );
-               $p = $this->factory->post->create();
-               while( $p <= $dir_pages->activity->id ) {
-                       $p = $this->factory->post->create();
-               }
-
-               // delete the post that matches the BP activity page ID on this sub-site
-               wp_delete_post( $dir_pages->activity->id, true );
-
-               // restore blog
-               restore_current_blog();
-
-               // refetch BP directory pages
-               $dir_pages = bp_core_get_directory_pages();
-
-               // Now verify that our BP activity page was not wiped out
-               $this->assertNotEmpty( $dir_pages->activity );
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * @group bp_core_get_root_options
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_bp_core_get_root_options_cache_invalidate() {
</span></span></pre>
</div>
</div>

</body>
</html>