| 385 | } |
| 386 | |
| 387 | /** |
| 388 | *@门票11302 |
| 389 | */ |
| 390 | 公共函数test_bulk_edit_if_categories_unchanged(){ |
| 391 | wp_set_current_user(自身::$admin_id); |
| 392 | |
| 393 | $post_ids=self::factory()->post->create_many(3); |
| 394 | |
| 395 | wp_set_post_categories($post_ids[0],数组(“test1”,“test2”); |
| 396 | wp_set_post_categories($post_ids[1],数组(“test2”,“test3”); |
| 397 | wp_set_post_categories($post_ids[2],数组('test1','test3')); |
| 398 | |
| 399 | $terms1=wp_get_post_categories($post_ids[0]); |
| 400 | $terms2=wp_get_post_categories($post_ids[1]); |
| 401 | $terms3=wp_get_post_categories($post_ids[2]); |
| 402 | |
| 403 | $unterminate_categories=array_merge($terms1、$terms2和$terms3); |
| 404 | |
| 405 | $request=数组( |
| 406 | “_状态”=>-1, |
| 407 | “帖子”=>$post_id, |
| 408 | “unterminate_post_category”=>$unterminite_categories, |
| 409 | ); |
| 410 | |
| 411 | bulk_edit_posts($request); |
| 412 | |
| 413 | $updated_terms1=wp_get_post_categories($post_ids[0]); |
| 414 | $updated_terms2=wp_get_post_categories($post_ids[1]); |
| 415 | $updated_terms3=wp_get_post_categories($post_ids[2]); |
| 416 | |
| 417 | $this->assertSame($terms1,$updated_terms1,‘Post 1应该有terms 1和2’); |
| 418 | $this->assertSame($terms2,$updated_terms2,‘Post 2应该有术语2和3。’); |
| 419 | $this->assertSame($terms3,$updated_terms3,‘Post 3应该有术语1和3’); |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | *@门票11302 |
| 424 | */ |
| 425 | 公共函数test_bulk_edit_if_some_categories_added(){ |
| 426 | wp_set_current_user(自身::$admin_id); |
| 427 | |
| 428 | $post_ids=self::factory()->post->create_many(3); |
| 429 | $term1=wp_create_category('test1'); |
| 430 | $term2=wp_create_category('test2'); |
| 431 | $term3=wp_create_category('test3'); |
| 432 | $term4=wp_create_category('test4'); |
| 433 | |
| 434 | wp_set_post_categories($post_ids[0],数组($term1,$term2)); |
| 435 | wp_set_post_categories($post_ids[1],数组($term2,$term3)); |
| 436 | wp_set_post_categories($post_ids[2],数组($term1,$term3)); |
| 437 | |
| 438 | $terms1=wp_get_post_categories($post_ids[0],数组(“字段”=>“ids”); |
| 439 | $terms2=wp_get_post_categories($post_ids[1],数组('fields'=>'ids')); |
| 440 | $terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids')); |
| 441 | //所有现有类别都是不确定的。 |
| 442 | $unterminate=数组唯一(数组合并($terms1、$terms2、$terms)); |
| 443 | //添加新类别。 |
| 444 | $categories[]=$term4; |
| 445 | |
| 446 | $request=数组( |
| 447 | “_状态”=>-1, |
| 448 | “帖子”=>$post_id, |
| 449 | “post_category”=>$categories, |
| 450 | “unterminate_post_category”=>$unterminete, |
| 451 | ); |
| 452 | |
| 453 | bulk_edit_posts($request); |
| 454 | |
| 455 | $updated_terms1=wp_get_post_categories($post_ids[0],数组(“字段”=>“id”); |
| 456 | $updated_terms2=wp_get_post_categories($post_ids[1],数组('fields'=>'ids')); |
| 457 | $updated_terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids')); |
| 458 | |
| 459 | //每个帖子的类别应与之前相同,并添加术语4。 |
| 460 | $this->assertSame(数组($term1、$term2、$term4),$updated_terms1,“帖子应该有词条1、2和4”); |
| 461 | $this->assertSame(数组($term2、$term3、$term4),$updated_terms2,‘帖子应该有术语2、3和4。’); |
| 462 | $this->assertSame(数组($term1、$term3、$term 4),$updated_terms3,“帖子应该有词条1、3和4。”); |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | *@门票11302 |
| 467 | */ |
| 468 | 公共函数test_bulk_edit_if_some_categories_removed(){ |
| 469 | wp_set_current_user(自身::$admin_id); |
| 470 | |
| 471 | $post_ids=self::factory()->post->create_many(3); |
| 472 | $term1=wp_create_category('test1'); |
| 473 | $term2=wp_create_category('test2'); |
| 474 | $term3=wp_create_category('test3'); |
| 475 | |
| 476 | wp_set_post_categories($post_ids[0],数组($term1,$term2)); |
| 477 | wp_set_post_categories($post_ids[1],数组($term2,$term3)); |
| 478 | wp_set_post_categories($post_ids[2],数组($term1,$term3)); |
| 479 | |
| 480 | $terms1=wp_get_post_categories($post_ids[0],数组(“字段”=>“ids”); |
| 481 | $terms2=wp_get_post_categories($post_ids[1],数组('fields'=>'ids')); |
| 482 | $terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids')); |
| 483 | |
| 484 | //第2和第3项处于不确定状态。 |
| 485 | $unterminate=数组($term2,$term3); |
| 486 | //从所选类别中删除术语1。 |
| 487 | $categories=数组唯一(array_merge($terms1、$terms2和$terms3)); |
| 488 | $remove_key=数组搜索($term1,$categories,true); |
| 489 | 取消设置($categories[$removekey]); |
| 490 | |
| 491 | $request=数组( |
| 492 | “_状态”=>-1, |
| 493 | “帖子”=>$post_id, |
| 494 | “post_category”=>$categories, |
| 495 | “unterminate_post_category”=>$unterminete, |
| 496 | ); |
| 497 | |
| 498 | bulk_edit_posts($request); |
| 499 | |
| 500 | $updated_terms1=wp_get_post_categories($post_ids[0],数组('fields'=>'ids')); |
| 501 | $updated_terms2=wp_get_post_categories($post_ids[1],数组(“字段”=>“id”)); |
| 502 | $updated_terms3=wp_get_post_categories($post_ids[2],数组('fields'=>'ids')); |
| 503 | |
| 504 | //帖子1应该只有术语2。 |
| 505 | $this->assertSame($updated_terms1,array($term2),“Post 1应该只有term 2”); |
| 506 | //岗位2应保持不变。 |
| 507 | $this->assertSame($terms2,$updated_terms2,‘Post 2 should be unchanged.’); |
| 508 | //帖子3应该只有术语3。 |
| 509 | $this->assertSame($updated_terms3,array($term3),‘Post 3应该只有term 3’); |