<!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][7883] trunk: Add delete_all support for all _delete_meta() functions</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">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7883">7883</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-02-14 19:02:16 +0000 (Fri, 14 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add delete_all support for all _delete_meta() functions
The delete_all parameter allows you to delete all meta items matching the
specified meta_key, regardless of the associated object.
Because our meta delete functions also support the deletion of all metadata
associated with an object (by leaving out the meta_key param), a decision had
to be made regarding the behavior when _delete_meta() is called with delete_all
= true and meta_key = false. The most logical (and least destructive) strategy
was deemed to be: force delete_all to false when meta_key is also false. This
ensures that you don't accidentally wipe out all metadata for a component.
See <a href="http://buddypress.trac.wordpress.org/ticket/5400">#5400</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityfunctionsphp">trunk/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunkbpblogsbpblogsfunctionsphp">trunk/bp-blogs/bp-blogs-functions.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsfunctionsphp">trunk/bp-groups/bp-groups-functions.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilefunctionsphp">trunk/bp-xprofile/bp-xprofile-functions.php</a></li>
<li><a href="#trunkteststestcasesactivityfunctionsphp">trunk/tests/testcases/activity/functions.php</a></li>
<li><a href="#trunkteststestcasesblogsfunctionsphp">trunk/tests/testcases/blogs/functions.php</a></li>
<li><a href="#trunkteststestcasesgroupsfunctionsphp">trunk/tests/testcases/groups/functions.php</a></li>
<li><a href="#trunkteststestcasesxprofilefunctionsphp">trunk/tests/testcases/xprofile/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/bp-activity/bp-activity-functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -538,22 +538,24 @@
</span><span class="cx"> /**
</span><span class="cx"> * Delete a meta entry from the DB for an activity stream item.
</span><span class="cx"> *
</span><del>- * @since BuddyPress (1.2)
</del><ins>+ * @since BuddyPress (1.2.0)
</ins><span class="cx"> *
</span><span class="cx"> * @global object $wpdb WordPress database access object.
</span><span class="cx"> * @global object $bp BuddyPress global settings.
</span><del>- * @uses wp_cache_delete()
- * @uses is_wp_error()
</del><span class="cx"> *
</span><span class="cx"> * @param int $activity_id ID of the activity item whose metadata is being deleted.
</span><span class="cx"> * @param string $meta_key Optional. The key of the metadata being deleted. If
</span><del>- * omitted, all metadata associated with the activity
- * item will be deleted.
</del><ins>+ * omitted, all metadata associated with the activity
+ * item will be deleted.
</ins><span class="cx"> * @param string $meta_value Optional. If present, the metadata will only be
</span><del>- * deleted if the meta_value matches this parameter.
</del><ins>+ * deleted if the meta_value matches this parameter.
+ * @param bool $delete_all Optional. If true, delete matching metadata entries
+ * for all objects, ignoring the specified object_id. Otherwise,
+ * only delete matching metadata entries for the specified
+ * activity item. Default: false.
</ins><span class="cx"> * @return bool True on success, false on failure.
</span><span class="cx"> */
</span><del>-function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '' ) {
</del><ins>+function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
</ins><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx"> // Legacy - Return false if any of the above values are not set
</span><span class="lines">@@ -571,13 +573,16 @@
</span><span class="cx"> if ( empty( $meta_key ) ) {
</span><span class="cx"> $all_meta = bp_activity_get_meta( $activity_id );
</span><span class="cx"> $keys = ! empty( $all_meta ) ? wp_list_pluck( $all_meta, 'meta_key' ) : array();
</span><ins>+
+ // With no meta_key, ignore $delete_all
+ $delete_all = false;
</ins><span class="cx"> } else {
</span><span class="cx"> $keys = array( $meta_key );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> add_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx"> foreach ( $keys as $key ) {
</span><del>- $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value );
</del><ins>+ $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value, $delete_all );
</ins><span class="cx"> }
</span><span class="cx"> remove_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpblogsbpblogsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-blogs/bp-blogs-functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-blogs/bp-blogs-functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/bp-blogs/bp-blogs-functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -834,9 +834,13 @@
</span><span class="cx"> * omitted, all BP metadata associated with the blog will be deleted.
</span><span class="cx"> * @param string $meta_value Optional. If present, the metadata will only be
</span><span class="cx"> * deleted if the meta_value matches this parameter.
</span><ins>+ * @param bool $delete_all Optional. If true, delete matching metadata entries
+ * for all objects, ignoring the specified blog_id. Otherwise, only
+ * delete matching metadata entries for the specified blog.
+ * Default: false.
</ins><span class="cx"> * @return bool True on success, false on failure.
</span><span class="cx"> */
</span><del>-function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
</del><ins>+function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
</ins><span class="cx"> global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx"> // Legacy - return false if the $blog_id is empty
</span><span class="lines">@@ -850,6 +854,7 @@
</span><span class="cx"> // Legacy - if no meta_key is passed, delete all for the blog_id
</span><span class="cx"> if ( empty( $meta_key ) ) {
</span><span class="cx"> $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->blogmeta} WHERE blog_id = %d", $blog_id ) );
</span><ins>+ $delete_all = false;
</ins><span class="cx"> } else {
</span><span class="cx"> $keys = array( $meta_key );
</span><span class="cx"> }
</span><span class="lines">@@ -860,7 +865,7 @@
</span><span class="cx"> add_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx">
</span><span class="cx"> foreach ( $keys as $key ) {
</span><del>- $retval = delete_metadata( 'blog', $blog_id, $key, $meta_value );
</del><ins>+ $retval = delete_metadata( 'blog', $blog_id, $key, $meta_value, $delete_all );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> remove_filter( 'query', 'bp_filter_metaid_column_name' );
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/bp-groups/bp-groups-functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -965,9 +965,14 @@
</span><span class="cx"> * metadata entries with this value.
</span><span class="cx"> * @param bool $delete_all Optional. If true, delete matching metadata entries
</span><span class="cx"> * for all groups. Default: false.
</span><ins>+ * @param bool $delete_all Optional. If true, delete matching metadata entries
+ * for all objects, ignoring the specified group_id. Otherwise, only
+ * delete matching metadata entries for the specified group.
+ * Default: false.
</ins><span class="cx"> * @return bool True on success, false on failure.
</span><span class="cx"> */
</span><span class="cx"> function groups_delete_groupmeta( $group_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
</span><ins>+ global $wpdb;
</ins><span class="cx">
</span><span class="cx"> // Legacy - return false if non-int group ID
</span><span class="cx"> if ( ! is_numeric( $group_id ) ) {
</span><span class="lines">@@ -977,8 +982,22 @@
</span><span class="cx"> // Legacy - Sanitize keys
</span><span class="cx"> $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
</span><span class="cx">
</span><ins>+ // Legacy - if no meta_key is passed, delete all for the item
+ if ( empty( $meta_key ) ) {
+ $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$wpdb->groupmeta} WHERE group_id = %d", $group_id ) );
+
+ // With no meta_key, ignore $delete_all
+ $delete_all = false;
+ } else {
+ $keys = array( $meta_key );
+ }
+
</ins><span class="cx"> add_filter( 'query', 'bp_filter_metaid_column_name' );
</span><del>- $retval = delete_metadata( 'group', $group_id, $meta_key, $meta_value, $delete_all );
</del><ins>+
+ foreach ( $keys as $key ) {
+ $retval = delete_metadata( 'group', $group_id, $key, $meta_value, $delete_all );
+ }
+
</ins><span class="cx"> remove_filter( 'query', 'bp_filter_metaid_column_name' );
</span><span class="cx">
</span><span class="cx"> return $retval;
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofilefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/bp-xprofile/bp-xprofile-functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -538,9 +538,13 @@
</span><span class="cx"> * metadata for the object will be deleted.
</span><span class="cx"> * @param mixed $meta_value Optional. If provided, only metadata that matches
</span><span class="cx"> * the value will be permitted.
</span><ins>+ * @param bool $delete_all Optional. If true, delete matching metadata entries
+ * for all objects, ignoring the specified object_id. Otherwise, only
+ * delete matching metadata entries for the specified object.
+ * Default: false.
</ins><span class="cx"> * @return bool True on success, false on failure.
</span><span class="cx"> */
</span><del>-function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false ) {
</del><ins>+function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false, $delete_all = false ) {
</ins><span class="cx"> global $wpdb;
</span><span class="cx">
</span><span class="cx"> // Legacy - no empty object id
</span><span class="lines">@@ -558,6 +562,9 @@
</span><span class="cx"> $table_key = 'xprofile_' . $object_type . 'meta';
</span><span class="cx"> $table_name = $wpdb->{$table_key};
</span><span class="cx"> $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$table_name} WHERE object_type = %s AND object_id = %d", $object_type, $object_id ) );
</span><ins>+
+ // Force delete_all to false if deleting all for object
+ $delete_all = false;
</ins><span class="cx"> } else {
</span><span class="cx"> $keys = array( $meta_key );
</span><span class="cx"> }
</span><span class="lines">@@ -569,7 +576,7 @@
</span><span class="cx"> add_filter( 'query', 'bp_xprofile_filter_meta_query' );
</span><span class="cx">
</span><span class="cx"> foreach ( $keys as $key ) {
</span><del>- $retval = delete_metadata( 'xprofile_' . $object_type, $object_id, $key, $meta_value );
</del><ins>+ $retval = delete_metadata( 'xprofile_' . $object_type, $object_id, $key, $meta_value, $delete_all );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
</span></span></pre></div>
<a id="trunkteststestcasesactivityfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/activity/functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/activity/functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/tests/testcases/activity/functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -336,6 +336,46 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group activitymeta
</span><ins>+ * @group bp_activity_delete_meta
+ */
+ public function test_bp_activity_delete_meta_with_delete_all_but_no_meta_key() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ $a1 = $this->factory->activity->create();
+ $a2 = $this->factory->activity->create();
+ bp_activity_update_meta( $a1, 'foo', 'bar' );
+ bp_activity_update_meta( $a1, 'foo1', 'bar1' );
+ bp_activity_update_meta( $a2, 'foo', 'bar' );
+ bp_activity_update_meta( $a2, 'foo1', 'bar1' );
+
+ $this->assertTrue( bp_activity_delete_meta( $a1, '', '', true ) );
+ $this->assertEmpty( bp_activity_get_meta( $a1 ) );
+ $this->assertSame( 'bar', bp_activity_get_meta( $a2, 'foo' ) );
+ $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) );
+ }
+
+ /**
+ * @group activitymeta
+ * @group bp_activity_delete_meta
+ */
+ public function test_bp_activity_delete_meta_with_delete_all() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ $a1 = $this->factory->activity->create();
+ $a2 = $this->factory->activity->create();
+ bp_activity_update_meta( $a1, 'foo', 'bar' );
+ bp_activity_update_meta( $a1, 'foo1', 'bar1' );
+ bp_activity_update_meta( $a2, 'foo', 'bar' );
+ bp_activity_update_meta( $a2, 'foo1', 'bar1' );
+
+ $this->assertTrue( bp_activity_delete_meta( $a1, 'foo', '', true ) );
+ $this->assertEmpty( '', bp_activity_get_meta( $a1, 'foo' ) );
+ $this->assertEmpty( '', bp_activity_get_meta( $a2, 'foo' ) );
+ $this->assertSame( 'bar1', bp_activity_get_meta( $a1, 'foo1' ) );
+ $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) );
+ }
+ /**
+ * @group activitymeta
</ins><span class="cx"> * @group bp_activity_add_meta
</span><span class="cx"> */
</span><span class="cx"> public function test_bp_activity_add_meta_no_meta_key() {
</span></span></pre></div>
<a id="trunkteststestcasesblogsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/blogs/functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/blogs/functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/tests/testcases/blogs/functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -62,6 +62,43 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group blogmeta
</span><ins>+ * @group bp_blogs_delete_blogmeta
+ */
+ public function test_bp_blogs_delete_blogmeta_with_delete_all_but_no_meta_key() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
+ bp_blogs_add_blogmeta( 1, 'foo1', 'bar1' );
+ bp_blogs_add_blogmeta( 2, 'foo', 'bar' );
+ bp_blogs_add_blogmeta( 2, 'foo1', 'bar1' );
+
+ $this->assertTrue( bp_blogs_delete_blogmeta( 1, '', '', true ) );
+ $this->assertEmpty( bp_blogs_get_blogmeta( 1 ) );
+ $this->assertSame( 'bar', bp_blogs_get_blogmeta( 2, 'foo' ) );
+ $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) );
+ }
+
+ /**
+ * @group blogmeta
+ * @group bp_blogs_delete_blogmeta
+ */
+ public function test_bp_blogs_delete_blogmeta_with_delete_all() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
+ bp_blogs_add_blogmeta( 1, 'foo1', 'bar1' );
+ bp_blogs_add_blogmeta( 2, 'foo', 'bar' );
+ bp_blogs_add_blogmeta( 2, 'foo1', 'bar1' );
+
+ $this->assertTrue( bp_blogs_delete_blogmeta( 1, 'foo', '', true ) );
+ $this->assertEmpty( '', bp_blogs_get_blogmeta( 1, 'foo' ) );
+ $this->assertEmpty( '', bp_blogs_get_blogmeta( 2, 'foo' ) );
+ $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 1, 'foo1' ) );
+ $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) );
+ }
+
+ /**
+ * @group blogmeta
</ins><span class="cx"> * @group bp_blogs_get_blogmeta
</span><span class="cx"> */
</span><span class="cx"> public function test_bp_blogs_get_blogmeta_empty_blog_id() {
</span></span></pre></div>
<a id="trunkteststestcasesgroupsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/groups/functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/groups/functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/tests/testcases/groups/functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -436,6 +436,47 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group groupmeta
</span><ins>+ * @group groups_delete_groupmeta
+ */
+ public function test_groups_delete_groupmeta_with_delete_all_but_no_meta_key() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ $g1 = $this->factory->group->create();
+ $g2 = $this->factory->group->create();
+ groups_add_groupmeta( $g1, 'foo', 'bar' );
+ groups_add_groupmeta( $g1, 'foo1', 'bar1' );
+ groups_add_groupmeta( $g2, 'foo', 'bar' );
+ groups_add_groupmeta( $g2, 'foo1', 'bar1' );
+
+ $this->assertTrue( groups_delete_groupmeta( $g1, '', '', true ) );
+ $this->assertEmpty( groups_get_groupmeta( $g1 ) );
+ $this->assertSame( 'bar', groups_get_groupmeta( $g2, 'foo' ) );
+ $this->assertSame( 'bar1', groups_get_groupmeta( $g2, 'foo1' ) );
+ }
+
+ /**
+ * @group groupmeta
+ * @group groups_delete_groupmeta
+ */
+ public function test_groups_delete_groupmeta_with_delete_all() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ $g1 = $this->factory->group->create();
+ $g2 = $this->factory->group->create();
+ groups_add_groupmeta( $g1, 'foo', 'bar' );
+ groups_add_groupmeta( $g1, 'foo1', 'bar1' );
+ groups_add_groupmeta( $g2, 'foo', 'bar' );
+ groups_add_groupmeta( $g2, 'foo1', 'bar1' );
+
+ $this->assertTrue( groups_delete_groupmeta( $g1, 'foo', '', true ) );
+ $this->assertEmpty( '', groups_get_groupmeta( $g1, 'foo' ) );
+ $this->assertEmpty( '', groups_get_groupmeta( $g2, 'foo' ) );
+ $this->assertSame( 'bar1', groups_get_groupmeta( $g1, 'foo1' ) );
+ $this->assertSame( 'bar1', groups_get_groupmeta( $g2, 'foo1' ) );
+ }
+
+ /**
+ * @group groupmeta
</ins><span class="cx"> * @group groups_add_groupmeta
</span><span class="cx"> */
</span><span class="cx"> public function test_groups_add_groupmeta_no_meta_key() {
</span></span></pre></div>
<a id="trunkteststestcasesxprofilefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/xprofile/functions.php (7882 => 7883)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/xprofile/functions.php 2014-02-14 18:29:30 UTC (rev 7882)
+++ trunk/tests/testcases/xprofile/functions.php 2014-02-14 19:02:16 UTC (rev 7883)
</span><span class="lines">@@ -233,13 +233,53 @@
</span><span class="cx">
</span><span class="cx"> $this->assertTrue( bp_xprofile_delete_meta( $g, 'group' ) );
</span><span class="cx">
</span><del>- // These will fail because of a caching bug
</del><span class="cx"> $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
</span><span class="cx"> $this->assertEquals( '', bp_xprofile_get_meta( $g, 'group', 'foo2' ) );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * @group xprofilemeta
</span><ins>+ * @group bp_xprofile_delete_meta
+ */
+ public function test_bp_xprofile_delete_meta_with_delete_all_but_no_meta_key() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ $g1 = $this->factory->xprofile_group->create();
+ $g2 = $this->factory->xprofile_group->create();
+ bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
+ bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
+ bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' );
+ bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' );
+
+ $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', '', '', true ) );
+ $this->assertEmpty( bp_xprofile_get_meta( $g1, 'group' ) );
+ $this->assertSame( 'bar', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
+ $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
+ }
+
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_delete_meta
+ */
+ public function test_bp_xprofile_delete_meta_with_delete_all() {
+ // With no meta key, don't delete for all items - just delete
+ // all for a single item
+ $g1 = $this->factory->xprofile_group->create();
+ $g2 = $this->factory->xprofile_group->create();
+ bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
+ bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
+ bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' );
+ bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' );
+
+ $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', 'foo', '', true ) );
+ $this->assertEmpty( '', bp_xprofile_get_meta( $g1, 'group', 'foo' ) );
+ $this->assertEmpty( '', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
+ $this->assertSame( 'bar1', bp_xprofile_get_meta( $g1, 'group', 'foo1' ) );
+ $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
+ }
+
+ /**
+ * @group xprofilemeta
</ins><span class="cx"> * @group bp_xprofile_get_meta
</span><span class="cx"> */
</span><span class="cx"> public function test_bp_xprofile_get_meta_empty_object_id() {
</span></span></pre>
</div>
</div>
</body>
</html>