<!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][7862] trunk: Migrate xprofilemeta functions to the WP metadata API</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/7862">7862</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-02-13 03:50:39 +0000 (Thu, 13 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Migrate xprofilemeta functions to the WP metadata API
The case of XProfile metadata is complex, because xprofile groups, fields, and
data all store their metadata in a single table, differentiated by object_type.
This complication requires additional filters on WP's core metadata queries.
See <a href="http://buddypress.trac.wordpress.org/ticket/4551">#4551</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpxprofilebpxprofilefiltersphp">trunk/bp-xprofile/bp-xprofile-filters.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilefunctionsphp">trunk/bp-xprofile/bp-xprofile-functions.php</a></li>
<li><a href="#trunkbpxprofilebpxprofileloaderphp">trunk/bp-xprofile/bp-xprofile-loader.php</a></li>
<li><a href="#trunkteststestcasesxprofilefunctionsphp">trunk/tests/testcases/xprofile/functions.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkteststestcasesxprofilefiltersphp">trunk/tests/testcases/xprofile/filters.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpxprofilebpxprofilefiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-filters.php (7861 => 7862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-filters.php 2014-02-12 21:35:17 UTC (rev 7861)
+++ trunk/bp-xprofile/bp-xprofile-filters.php 2014-02-13 03:50:39 UTC (rev 7862)
</span><span class="lines">@@ -261,3 +261,99 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> add_filter( 'bp_user_query_populate_extras', 'bp_xprofile_filter_user_query_populate_extras', 2, 2 );
</span><ins>+
+/**
+ * Filter meta queries to modify for the xprofile data schema.
+ *
+ * @since BuddyPress (2.0.0)
+ *
+ * @access private Do not use.
+ *
+ * @param string $q SQL query.
+ * @return string
+ */
+function bp_xprofile_filter_meta_query( $q ) {
+ global $wpdb;
+
+ // Get the first word of the command
+ preg_match( '/^(\S+)/', $q, $first_word_matches );
+
+ if ( empty( $first_word_matches[0] ) ) {
+ return $q;
+ }
+
+ // Get the field type
+ preg_match( '/xprofile_(group|field|data)_id/', $q, $matches );
+
+ if ( empty( $matches[0] ) || empty( $matches[1] ) ) {
+ return $q;
+ }
+
+ switch ( $first_word_matches[0] ) {
+
+ /**
+ * SELECT:
+ * - replace 'xprofile_{fieldtype}_id' with 'object_id'
+ * - ensure that 'object_id' is aliased to 'xprofile_{fieldtype}_id',
+ * because update_meta_cache() needs the column name to parse
+ * the query results
+ * - append the 'object type' WHERE clause
+ */
+ case 'SELECT' :
+ $q = str_replace(
+ array(
+ $matches[0],
+ 'SELECT object_id',
+ 'WHERE ',
+ ),
+ array(
+ 'object_id',
+ 'SELECT object_id AS ' . $matches[0],
+ $wpdb->prepare( 'WHERE object_type = %s AND ', $matches[1] ),
+ ),
+ $q
+ );
+ break;
+
+ /**
+ * UPDATE and DELETE:
+ * - replace 'xprofile_{fieldtype}_id' with 'object_id'
+ * - append the 'object type' WHERE clause
+ */
+ case 'UPDATE' :
+ case 'DELETE' :
+ $q = str_replace(
+ array(
+ $matches[0],
+ 'WHERE ',
+ ),
+ array(
+ 'object_id',
+ $wpdb->prepare( 'WHERE object_type = %s AND ', $matches[1] ),
+ ),
+ $q
+ );
+ break;
+
+ /**
+ * UPDATE and DELETE:
+ * - replace 'xprofile_{fieldtype}_id' with 'object_id'
+ * - ensure that the object_type field gets filled in
+ */
+ case 'INSERT' :
+ $q = str_replace(
+ array(
+ '`' . $matches[0] . '`',
+ 'VALUES (',
+ ),
+ array(
+ '`object_type`,`object_id`',
+ $wpdb->prepare( "VALUES (%s,", $matches[1] ),
+ ),
+ $q
+ );
+ break;
+ }
+
+ return $q;
+}
</ins></span></pre></div>
<a id="trunkbpxprofilebpxprofilefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-functions.php (7861 => 7862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-functions.php 2014-02-12 21:35:17 UTC (rev 7861)
+++ trunk/bp-xprofile/bp-xprofile-functions.php 2014-02-13 03:50:39 UTC (rev 7862)
</span><span class="lines">@@ -529,121 +529,117 @@
</span><span class="cx">
</span><span class="cx"> /*** XProfile Meta ****************************************************/
</span><span class="cx">
</span><ins>+/**
+ * Delete a piece of xprofile metadata.
+ *
+ * @param int $object_id ID of the object the metadata belongs to.
+ * @param string $object_type Type of object. 'group', 'field', or 'data'.
+ * @param string $meta_key Key of the metadata being deleted. If omitted, all
+ * metadata for the object will be deleted.
+ * @param mixed $meta_value Optional. If provided, only metadata that matches
+ * the value will be permitted.
+ * @return bool True on success, false on failure.
+ */
</ins><span class="cx"> function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false ) {
</span><del>- global $wpdb, $bp;
</del><ins>+ global $wpdb;
</ins><span class="cx">
</span><del>- $object_id = (int) $object_id;
-
- if ( !$object_id )
</del><ins>+ // Legacy - no empty object id
+ if ( empty( $object_id ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( !isset( $object_type ) )
</del><ins>+ // Legacy - sanitize object type
+ if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) )
- return false;
-
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
-
- if ( is_array( $meta_value ) || is_object( $meta_value ) ) {
- $meta_value = serialize( $meta_value );
</del><ins>+ // Legacy - if no meta_key is passed, delete all for the item
+ if ( empty( $meta_key ) ) {
+ $table_key = 'xprofile_' . $object_type . 'meta';
+ $table_name = $wpdb->{$table_key};
+ $keys = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM {$table_name} WHERE object_type = %s AND object_id = %d", $object_type, $object_id ) );
+ } else {
+ $keys = array( $meta_key );
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ // Legacy - trim meta_value
</ins><span class="cx"> $meta_value = trim( $meta_value );
</span><span class="cx">
</span><del>- if ( empty( $meta_key ) ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_meta} WHERE object_id = %d AND object_type = %s", $object_id, $object_type ) );
- } elseif ( !empty( $meta_value ) ) {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_meta} WHERE object_id = %d AND object_type = %s AND meta_key = %s AND meta_value = %s", $object_id, $object_type, $meta_key, $meta_value ) );
- } else {
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_meta} WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key ) );
</del><ins>+ add_filter( 'query', 'bp_filter_metaid_column_name' );
+ add_filter( 'query', 'bp_xprofile_filter_meta_query' );
+
+ foreach ( $keys as $key ) {
+ $retval = delete_metadata( 'xprofile_' . $object_type, $object_id, $key, $meta_value );
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- // Delete the cached object
- wp_cache_delete( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp' );
</del><ins>+ remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
+ remove_filter( 'query', 'bp_filter_metaid_column_name' );
</ins><span class="cx">
</span><del>- return true;
</del><ins>+ return $retval;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Get a piece of xprofile metadata.
+ *
+ * @param int $object_id ID of the object the metadata belongs to.
+ * @param string $object_type Type of object. 'group', 'field', or 'data'.
+ * @param string $meta_key Key of the metadata being fetched. If omitted, all
+ * metadata for the object will be retrieved.
+ * @return mixed Meta value if found. False on failure.
+ */
</ins><span class="cx"> function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '') {
</span><del>- global $wpdb, $bp;
-
- $object_id = (int) $object_id;
-
- if ( !$object_id )
</del><ins>+ // Legacy - sanitize object type
+ if ( ! in_array( $object_type, array( 'group', 'field', 'data' ) ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( !isset( $object_type ) )
- return false;
</del><ins>+ add_filter( 'query', 'bp_filter_metaid_column_name' );
+ add_filter( 'query', 'bp_xprofile_filter_meta_query' );
+ $retval = get_metadata( 'xprofile_' . $object_type, $object_id, $meta_key, true );
+ remove_filter( 'query', 'bp_filter_metaid_column_name' );
+ remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
</ins><span class="cx">
</span><del>- if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) )
- return false;
-
- if ( !empty( $meta_key ) ) {
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
-
- if ( !$metas = wp_cache_get( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp' ) ) {
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->profile->table_name_meta} WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key ) );
- wp_cache_set( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $metas, 'bp' );
</del><ins>+ // Legacy - if no meta_key is provided, return just the located
+ // values (not a structured array)
+ if ( empty( $meta_key ) && ! empty( $retval ) ) {
+ $values = array();
+ foreach ( $retval as $v ) {
+ $values[] = array_pop( $v );
</ins><span class="cx"> }
</span><del>- } else {
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->profile->table_name_meta} WHERE object_id = %d AND object_type = %s", $object_id, $object_type ) );
- }
</del><span class="cx">
</span><del>- if ( empty( $metas ) ) {
- if ( empty( $meta_key ) ) {
- return array();
- } else {
- return '';
- }
</del><ins>+ $retval = $values;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- $metas = array_map( 'maybe_unserialize', (array) $metas );
-
- if ( 1 == count( $metas ) )
- return $metas[0];
- else
- return $metas;
</del><ins>+ return $retval;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Update a piece of xprofile metadata.
+ *
+ * @param int $object_id ID of the object the metadata belongs to.
+ * @param string $object_type Type of object. 'group', 'field', or 'data'.
+ * @param string $meta_key Key of the metadata being updated.
+ * @param mixed $meta_value Value of the metadata being updated.
+ * @return bool True on success, false on failure.
+ */
</ins><span class="cx"> function bp_xprofile_update_meta( $object_id, $object_type, $meta_key, $meta_value ) {
</span><del>- global $wpdb, $bp;
</del><span class="cx">
</span><del>- $object_id = (int) $object_id;
</del><ins>+ // Legacy - sanitize meta_key
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
</ins><span class="cx">
</span><del>- if ( empty( $object_id ) )
- return false;
</del><ins>+ add_filter( 'query', 'bp_filter_metaid_column_name' );
+ add_filter( 'query', 'bp_xprofile_filter_meta_query' );
+ $retval = update_metadata( 'xprofile_' . $object_type, $object_id, $meta_key, $meta_value );
+ remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
+ remove_filter( 'query', 'bp_filter_metaid_column_name' );
</ins><span class="cx">
</span><del>- if ( !isset( $object_type ) )
- return false;
-
- if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) )
- return false;
-
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
-
- if ( is_string( $meta_value ) ) {
- $meta_value = stripslashes( $meta_value );
</del><ins>+ // Legacy - if we fall through to add_metadata(), return true rather
+ // than the integer meta_id
+ if ( is_int( $retval ) ) {
+ $retval = (bool) $retval;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- $meta_value = maybe_serialize( $meta_value );
-
- if ( empty( $meta_value ) )
- return bp_xprofile_delete_meta( $object_id, $object_type, $meta_key );
-
- $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_meta} WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key ) );
-
- if ( empty( $cur ) )
- $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_meta} ( object_id, object_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )", $object_id, $object_type, $meta_key, $meta_value ) );
- else if ( $cur->meta_value != $meta_value )
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_meta} SET meta_value = %s WHERE object_id = %d AND object_type = %s AND meta_key = %s", $meta_value, $object_id, $object_type, $meta_key ) );
- else
- return false;
-
- // Update the cached object and recache
- wp_cache_set( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $meta_value, 'bp' );
-
- return true;
</del><ins>+ return $retval;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bp_xprofile_update_fieldgroup_meta( $field_group_id, $meta_key, $meta_value ) {
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofileloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-loader.php (7861 => 7862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-loader.php 2014-02-12 21:35:17 UTC (rev 7861)
+++ trunk/bp-xprofile/bp-xprofile-loader.php 2014-02-13 03:50:39 UTC (rev 7862)
</span><span class="lines">@@ -138,11 +138,18 @@
</span><span class="cx"> 'table_name_meta' => $bp->table_prefix . 'bp_xprofile_meta',
</span><span class="cx"> );
</span><span class="cx">
</span><ins>+ $meta_tables = array(
+ 'xprofile_group' => $bp->table_prefix . 'bp_xprofile_meta',
+ 'xprofile_field' => $bp->table_prefix . 'bp_xprofile_meta',
+ 'xprofile_data' => $bp->table_prefix . 'bp_xprofile_meta',
+ );
+
</ins><span class="cx"> $globals = array(
</span><span class="cx"> 'slug' => BP_XPROFILE_SLUG,
</span><span class="cx"> 'has_directory' => false,
</span><span class="cx"> 'notification_callback' => 'xprofile_format_notifications',
</span><del>- 'global_tables' => $global_tables
</del><ins>+ 'global_tables' => $global_tables,
+ 'meta_tables' => $meta_tables,
</ins><span class="cx"> );
</span><span class="cx">
</span><span class="cx"> parent::setup_globals( $globals );
</span></span></pre></div>
<a id="trunkteststestcasesxprofilefiltersphp"></a>
<div class="addfile"><h4>Added: trunk/tests/testcases/xprofile/filters.php (0 => 7862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/xprofile/filters.php (rev 0)
+++ trunk/tests/testcases/xprofile/filters.php 2014-02-13 03:50:39 UTC (rev 7862)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+<?php
+
+/**
+ * @group xprofile
+ */
+class BP_Tests_XProfile_Filters extends BP_UnitTestCase {
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_filter_meta_query
+ */
+ public function test_bp_xprofile_filter_meta_query_select() {
+ global $wpdb;
+
+ // update_meta_cache
+ $q = "SELECT xprofile_group_id, meta_key, meta_value FROM {$wpdb->xprofile_groupmeta} WHERE xprofile_group_id IN (1,2,3) ORDER BY xprofile_group_id ASC";
+ $this->assertSame( "SELECT object_id AS xprofile_group_id, meta_key, meta_value FROM {$wpdb->xprofile_groupmeta} WHERE object_type = 'group' AND object_id IN (1,2,3) ORDER BY object_id ASC", bp_xprofile_filter_meta_query( $q ) );
+
+ // add_metadata
+ $q = "SELECT COUNT(*) FROM {$wpdb->xprofile_groupmeta} WHERE meta_key = 'foo' AND xprofile_group_id = 5";
+ $this->assertSame( "SELECT COUNT(*) FROM {$wpdb->xprofile_groupmeta} WHERE object_type = 'group' AND meta_key = 'foo' AND object_id = 5", bp_xprofile_filter_meta_query( $q ) );
+
+ // delete_metadata
+ $q = "SELECT meta_id FROM {$wpdb->xprofile_groupmeta} WHERE meta_key = 'foo' AND xprofile_group_id = 5 AND meta_value = 'bar'";
+ $this->assertSame( "SELECT meta_id FROM {$wpdb->xprofile_groupmeta} WHERE object_type = 'group' AND meta_key = 'foo' AND object_id = 5 AND meta_value = 'bar'", bp_xprofile_filter_meta_query( $q ) );
+ }
+
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_filter_meta_query
+ */
+ public function test_bp_xprofile_filter_meta_query_insert() {
+ global $wpdb;
+ $q = "INSERT INTO `{$wpdb->xprofile_groupmeta}` (`xprofile_group_id`,`meta_key`,`meta_value`) VALUES (3,'foo','bar')";
+ $this->assertSame( "INSERT INTO `{$wpdb->xprofile_groupmeta}` (`object_type`,`object_id`,`meta_key`,`meta_value`) VALUES ('group',3,'foo','bar')", bp_xprofile_filter_meta_query( $q ) );
+ }
+
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_filter_meta_query
+ */
+ public function test_bp_xprofile_filter_meta_query_update() {
+ global $wpdb;
+
+ $q = "UPDATE `{$wpdb->xprofile_groupmeta}` SET meta_value = 'bar' WHERE xprofile_group_id = 3 AND meta_key = 'foo'";
+ $this->assertSame( "UPDATE `{$wpdb->xprofile_groupmeta}` SET meta_value = 'bar' WHERE object_type = 'group' AND object_id = 3 AND meta_key = 'foo'", bp_xprofile_filter_meta_query( $q ) );
+ }
+
+ /**
+ * @group xprofilemeta
+ * @group bp_xprofile_filter_meta_query
+ */
+ public function test_bp_xprofile_filter_meta_query_delete() {
+ global $wpdb;
+ $q = "DELETE FROM {$wpdb->xprofile_groupmeta} WHERE xprofile_group_id IN(1,2,3)";
+ $this->assertSame( "DELETE FROM {$wpdb->xprofile_groupmeta} WHERE object_type = 'group' AND object_id IN(1,2,3)", bp_xprofile_filter_meta_query( $q ) );
+ }
+}
</ins></span></pre></div>
<a id="trunkteststestcasesxprofilefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/tests/testcases/xprofile/functions.php (7861 => 7862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/tests/testcases/xprofile/functions.php 2014-02-12 21:35:17 UTC (rev 7861)
+++ trunk/tests/testcases/xprofile/functions.php 2014-02-13 03:50:39 UTC (rev 7862)
</span><span class="lines">@@ -234,8 +234,8 @@
</span><span class="cx"> $this->assertTrue( bp_xprofile_delete_meta( $g->id, 'group' ) );
</span><span class="cx">
</span><span class="cx"> // These will fail because of a caching bug
</span><del>- //$this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
- //$this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo2' ) );
</del><ins>+ $this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo' ) );
+ $this->assertEquals( '', bp_xprofile_get_meta( $g->id, 'group', 'foo2' ) );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>