| | 1209 | |
| | 1210 | /** |
| | 1211 | * @ticket BP8568 |
| | 1212 | */ |
| | 1213 | public function test_xprofile_sync_wp_profile_signup_with_wp_first_and_last_name_fields() { |
| | 1214 | add_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1215 | |
| | 1216 | $u = self::factory()->user->create_and_get( |
| | 1217 | array( |
| | 1218 | 'user_login' => 'foobar', |
| | 1219 | 'user_email' => 'foo@bar.email', |
| | 1220 | ) |
| | 1221 | ); |
| | 1222 | |
| | 1223 | $field_fn = self::factory()->xprofile_field->create( |
| | 1224 | array( |
| | 1225 | 'field_group_id' => 1, |
| | 1226 | 'type' => 'wp-textbox', |
| | 1227 | 'name' => 'WP First Name', |
| | 1228 | ) |
| | 1229 | ); |
| | 1230 | |
| | 1231 | // Set the WP User Key. |
| | 1232 | bp_xprofile_update_meta( $field_fn, 'field', 'wp_user_key', 'first_name' ); |
| | 1233 | |
| | 1234 | $field_ln = self::factory()->xprofile_field->create( |
| | 1235 | array( |
| | 1236 | 'field_group_id' => 1, |
| | 1237 | 'type' => 'wp-textbox', |
| | 1238 | 'name' => 'WP Last Name', |
| | 1239 | ) |
| | 1240 | ); |
| | 1241 | |
| | 1242 | // Set the WP User Key. |
| | 1243 | bp_xprofile_update_meta( $field_ln, 'field', 'wp_user_key', 'last_name' ); |
| | 1244 | |
| | 1245 | $field_n = bp_xprofile_fullname_field_id(); |
| | 1246 | $usermeta = array( |
| | 1247 | 'field_' . $field_n => 'foobar', |
| | 1248 | 'field_' . $field_fn => 'Foo', |
| | 1249 | 'field_' . $field_ln => 'Bar', |
| | 1250 | 'profile_field_ids' => $field_n . ',' . $field_fn . ',' . $field_ln, |
| | 1251 | ); |
| | 1252 | |
| | 1253 | remove_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1254 | |
| | 1255 | // simulates do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta ); |
| | 1256 | xprofile_sync_wp_profile( $u->ID, $u->user_login, $u->user_pass, $u->user_email, $usermeta ); |
| | 1257 | |
| | 1258 | $updated_u = get_user_by( 'id', $u->ID ); |
| | 1259 | |
| | 1260 | $this->assertEquals( 'Foo', $updated_u->first_name ); |
| | 1261 | $this->assertEquals( 'Bar', $updated_u->last_name ); |
| | 1262 | } |
| | 1263 | |
| | 1264 | /** |
| | 1265 | * @ticket BP8568 |
| | 1266 | */ |
| | 1267 | public function test_xprofile_sync_wp_profile_signup_without_wp_first_and_last_name_fields() { |
| | 1268 | add_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1269 | |
| | 1270 | $u = self::factory()->user->create_and_get( |
| | 1271 | array( |
| | 1272 | 'user_login' => 'foobar', |
| | 1273 | 'user_email' => 'foo@bar.email', |
| | 1274 | ) |
| | 1275 | ); |
| | 1276 | |
| | 1277 | $field_n = bp_xprofile_fullname_field_id(); |
| | 1278 | $usermeta = array( |
| | 1279 | 'field_' . $field_n => 'foobar', |
| | 1280 | 'profile_field_ids' => $field_n, |
| | 1281 | ); |
| | 1282 | |
| | 1283 | remove_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1284 | |
| | 1285 | // simulates do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta ); |
| | 1286 | xprofile_sync_wp_profile( $u->ID, $u->user_login, $u->user_pass, $u->user_email, $usermeta ); |
| | 1287 | |
| | 1288 | $updated_u = get_user_by( 'id', $u->ID ); |
| | 1289 | |
| | 1290 | $this->assertEquals( 'foobar', $updated_u->first_name ); |
| | 1291 | $this->assertEquals( '', $updated_u->last_name ); |
| | 1292 | } |
| | 1293 | |
| | 1294 | /** |
| | 1295 | * @ticket BP8568 |
| | 1296 | */ |
| | 1297 | public function test_xprofile_sync_wp_profile_activate_signup_with_wp_first_and_last_name_fields() { |
| | 1298 | add_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1299 | |
| | 1300 | $u = self::factory()->user->create_and_get( |
| | 1301 | array( |
| | 1302 | 'user_login' => 'barfoo', |
| | 1303 | 'user_email' => 'bar@foo.email', |
| | 1304 | ) |
| | 1305 | ); |
| | 1306 | |
| | 1307 | $field_fn = self::factory()->xprofile_field->create( |
| | 1308 | array( |
| | 1309 | 'field_group_id' => 1, |
| | 1310 | 'type' => 'wp-textbox', |
| | 1311 | 'name' => 'WP First Name', |
| | 1312 | ) |
| | 1313 | ); |
| | 1314 | |
| | 1315 | // Set the WP User Key. |
| | 1316 | bp_xprofile_update_meta( $field_fn, 'field', 'wp_user_key', 'first_name' ); |
| | 1317 | |
| | 1318 | $field_ln = self::factory()->xprofile_field->create( |
| | 1319 | array( |
| | 1320 | 'field_group_id' => 1, |
| | 1321 | 'type' => 'wp-textbox', |
| | 1322 | 'name' => 'WP Last Name', |
| | 1323 | ) |
| | 1324 | ); |
| | 1325 | |
| | 1326 | // Set the WP User Key. |
| | 1327 | bp_xprofile_update_meta( $field_ln, 'field', 'wp_user_key', 'last_name' ); |
| | 1328 | |
| | 1329 | $field_n = bp_xprofile_fullname_field_id(); |
| | 1330 | |
| | 1331 | $user = array( |
| | 1332 | 'user_id' => $u->ID, |
| | 1333 | 'password' => $u->user_pass, |
| | 1334 | 'meta' => array( |
| | 1335 | 'field_' . $field_n => 'barfoo', |
| | 1336 | 'field_' . $field_fn => 'Bar', |
| | 1337 | 'field_' . $field_ln => 'Foo', |
| | 1338 | 'profile_field_ids' => $field_n . ',' . $field_fn . ',' . $field_ln, |
| | 1339 | ), |
| | 1340 | ); |
| | 1341 | |
| | 1342 | remove_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1343 | |
| | 1344 | // simulates do_action( 'bp_core_activated_user', $user_id, $key, $user ); |
| | 1345 | xprofile_sync_wp_profile( $u->ID, 'randomkey', $user ); |
| | 1346 | |
| | 1347 | $updated_u = get_user_by( 'id', $u->ID ); |
| | 1348 | |
| | 1349 | $this->assertEquals( 'Bar', $updated_u->first_name ); |
| | 1350 | $this->assertEquals( 'Foo', $updated_u->last_name ); |
| | 1351 | } |
| | 1352 | |
| | 1353 | /** |
| | 1354 | * @ticket BP8568 |
| | 1355 | */ |
| | 1356 | public function test_xprofile_sync_wp_profile_activate_signup_without_wp_first_and_last_name_fields() { |
| | 1357 | add_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1358 | |
| | 1359 | $u = self::factory()->user->create_and_get( |
| | 1360 | array( |
| | 1361 | 'user_login' => 'barfoo', |
| | 1362 | 'user_email' => 'bar@foo.email', |
| | 1363 | ) |
| | 1364 | ); |
| | 1365 | |
| | 1366 | $field_n = bp_xprofile_fullname_field_id(); |
| | 1367 | |
| | 1368 | $user = array( |
| | 1369 | 'user_id' => $u->ID, |
| | 1370 | 'password' => $u->user_pass, |
| | 1371 | 'meta' => array( |
| | 1372 | 'field_' . $field_n => 'barfoo', |
| | 1373 | 'profile_field_ids' => $field_n, |
| | 1374 | ), |
| | 1375 | ); |
| | 1376 | |
| | 1377 | remove_filter( 'bp_disable_profile_sync', '__return_true' ); |
| | 1378 | |
| | 1379 | // simulates do_action( 'bp_core_activated_user', $user_id, $key, $user ); |
| | 1380 | xprofile_sync_wp_profile( $u->ID, 'randomkey', $user ); |
| | 1381 | |
| | 1382 | $updated_u = get_user_by( 'id', $u->ID ); |
| | 1383 | |
| | 1384 | $this->assertEquals( 'barfoo', $updated_u->first_name ); |
| | 1385 | $this->assertEquals( '', $updated_u->last_name ); |
| | 1386 | } |