Changeset 54756
- Timestamp:
- 11/06/2022 03:54:34 PM (2 years ago)
- Location:
- trunk/tests/phpunit/tests/multisite
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r54402 r54756 414 414 415 415 /** 416 * Provide a counter to determine that hooks are firing when intended.417 */418 public function action_counter_cb() {419 global $test_action_counter;420 $test_action_counter++;421 }422 423 /**424 416 * Test cached data for a site that does not exist and then again after it exists. 425 417 * … … 466 458 467 459 public function test_update_blog_status_make_ham_blog_action() { 468 global $test_action_counter; 469 $test_action_counter = 0; 460 $test_action_counter = new MockAction(); 470 461 471 462 $blog_id = self::factory()->blog->create(); 472 463 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 473 464 474 add_action( 'make_ham_blog', array( $t his, 'action_counter_cb' ), 10);465 add_action( 'make_ham_blog', array( $test_action_counter, 'action' ) ); 475 466 update_blog_status( $blog_id, 'spam', 0 ); 476 467 $blog = get_site( $blog_id ); 477 468 478 469 $this->assertSame( '0', $blog->spam ); 479 $this->assertSame( 1, $test_action_counter );470 $this->assertSame( 1, $test_action_counter->get_call_count() ); 480 471 481 472 // The action should not fire if the status of 'spam' stays the same. … … 484 475 485 476 $this->assertSame( '0', $blog->spam ); 486 $this->assertSame( 1, $test_action_counter ); 487 488 remove_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 ); 477 $this->assertSame( 1, $test_action_counter->get_call_count() ); 489 478 } 490 479 … … 520 509 521 510 public function test_update_blog_status_make_spam_blog_action() { 522 global $test_action_counter; 523 $test_action_counter = 0; 511 $test_action_counter = new MockAction(); 524 512 525 513 $blog_id = self::factory()->blog->create(); 526 514 527 add_action( 'make_spam_blog', array( $t his, 'action_counter_cb' ), 10);515 add_action( 'make_spam_blog', array( $test_action_counter, 'action' ) ); 528 516 update_blog_status( $blog_id, 'spam', 1 ); 529 517 $blog = get_site( $blog_id ); 530 518 531 519 $this->assertSame( '1', $blog->spam ); 532 $this->assertSame( 1, $test_action_counter );520 $this->assertSame( 1, $test_action_counter->get_call_count() ); 533 521 534 522 // The action should not fire if the status of 'spam' stays the same. … … 537 525 538 526 $this->assertSame( '1', $blog->spam ); 539 $this->assertSame( 1, $test_action_counter ); 540 541 remove_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 ); 527 $this->assertSame( 1, $test_action_counter->get_call_count() ); 542 528 } 543 529 544 530 public function test_update_blog_status_archive_blog_action() { 545 global $test_action_counter; 546 $test_action_counter = 0; 531 $test_action_counter = new MockAction(); 547 532 548 533 $blog_id = self::factory()->blog->create(); 549 534 550 add_action( 'archive_blog', array( $t his, 'action_counter_cb' ), 10);535 add_action( 'archive_blog', array( $test_action_counter, 'action' ) ); 551 536 update_blog_status( $blog_id, 'archived', 1 ); 552 537 $blog = get_site( $blog_id ); 553 538 554 539 $this->assertSame( '1', $blog->archived ); 555 $this->assertSame( 1, $test_action_counter );540 $this->assertSame( 1, $test_action_counter->get_call_count() ); 556 541 557 542 // The action should not fire if the status of 'archived' stays the same. … … 560 545 561 546 $this->assertSame( '1', $blog->archived ); 562 $this->assertSame( 1, $test_action_counter ); 563 564 remove_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 ); 547 $this->assertSame( 1, $test_action_counter->get_call_count() ); 565 548 } 566 549 567 550 public function test_update_blog_status_unarchive_blog_action() { 568 global $test_action_counter; 569 $test_action_counter = 0; 551 $test_action_counter = new MockAction(); 570 552 571 553 $blog_id = self::factory()->blog->create(); 572 554 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 573 555 574 add_action( 'unarchive_blog', array( $t his, 'action_counter_cb' ), 10);556 add_action( 'unarchive_blog', array( $test_action_counter, 'action' ) ); 575 557 update_blog_status( $blog_id, 'archived', 0 ); 576 558 $blog = get_site( $blog_id ); 577 559 578 560 $this->assertSame( '0', $blog->archived ); 579 $this->assertSame( 1, $test_action_counter );561 $this->assertSame( 1, $test_action_counter->get_call_count() ); 580 562 581 563 // The action should not fire if the status of 'archived' stays the same. … … 583 565 $blog = get_site( $blog_id ); 584 566 $this->assertSame( '0', $blog->archived ); 585 $this->assertSame( 1, $test_action_counter ); 586 587 remove_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 ); 567 $this->assertSame( 1, $test_action_counter->get_call_count() ); 588 568 } 589 569 590 570 public function test_update_blog_status_make_delete_blog_action() { 591 global $test_action_counter; 592 $test_action_counter = 0; 571 $test_action_counter = new MockAction(); 593 572 594 573 $blog_id = self::factory()->blog->create(); 595 574 596 add_action( 'make_delete_blog', array( $t his, 'action_counter_cb' ), 10);575 add_action( 'make_delete_blog', array( $test_action_counter, 'action' ) ); 597 576 update_blog_status( $blog_id, 'deleted', 1 ); 598 577 $blog = get_site( $blog_id ); 599 578 600 579 $this->assertSame( '1', $blog->deleted ); 601 $this->assertSame( 1, $test_action_counter );580 $this->assertSame( 1, $test_action_counter->get_call_count() ); 602 581 603 582 // The action should not fire if the status of 'deleted' stays the same. … … 606 585 607 586 $this->assertSame( '1', $blog->deleted ); 608 $this->assertSame( 1, $test_action_counter ); 609 610 remove_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 ); 587 $this->assertSame( 1, $test_action_counter->get_call_count() ); 611 588 } 612 589 613 590 public function test_update_blog_status_make_undelete_blog_action() { 614 global $test_action_counter; 615 $test_action_counter = 0; 591 $test_action_counter = new MockAction(); 616 592 617 593 $blog_id = self::factory()->blog->create(); 618 594 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 619 595 620 add_action( 'make_undelete_blog', array( $t his, 'action_counter_cb' ), 10);596 add_action( 'make_undelete_blog', array( $test_action_counter, 'action' ) ); 621 597 update_blog_status( $blog_id, 'deleted', 0 ); 622 598 $blog = get_site( $blog_id ); 623 599 624 600 $this->assertSame( '0', $blog->deleted ); 625 $this->assertSame( 1, $test_action_counter );601 $this->assertSame( 1, $test_action_counter->get_call_count() ); 626 602 627 603 // The action should not fire if the status of 'deleted' stays the same. … … 630 606 631 607 $this->assertSame( '0', $blog->deleted ); 632 $this->assertSame( 1, $test_action_counter ); 633 634 remove_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 ); 608 $this->assertSame( 1, $test_action_counter->get_call_count() ); 635 609 } 636 610 637 611 public function test_update_blog_status_mature_blog_action() { 638 global $test_action_counter; 639 $test_action_counter = 0; 612 $test_action_counter = new MockAction(); 640 613 641 614 $blog_id = self::factory()->blog->create(); 642 615 643 add_action( 'mature_blog', array( $t his, 'action_counter_cb' ), 10);616 add_action( 'mature_blog', array( $test_action_counter, 'action' ) ); 644 617 update_blog_status( $blog_id, 'mature', 1 ); 645 618 $blog = get_site( $blog_id ); 646 619 647 620 $this->assertSame( '1', $blog->mature ); 648 $this->assertSame( 1, $test_action_counter );621 $this->assertSame( 1, $test_action_counter->get_call_count() ); 649 622 650 623 // The action should not fire if the status of 'mature' stays the same. … … 653 626 654 627 $this->assertSame( '1', $blog->mature ); 655 $this->assertSame( 1, $test_action_counter ); 656 657 remove_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 ); 628 $this->assertSame( 1, $test_action_counter->get_call_count() ); 658 629 } 659 630 660 631 public function test_update_blog_status_unmature_blog_action() { 661 global $test_action_counter; 662 $test_action_counter = 0; 632 $test_action_counter = new MockAction(); 663 633 664 634 $blog_id = self::factory()->blog->create(); 665 635 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 666 636 667 add_action( 'unmature_blog', array( $t his, 'action_counter_cb' ), 10);637 add_action( 'unmature_blog', array( $test_action_counter, 'action' ) ); 668 638 update_blog_status( $blog_id, 'mature', 0 ); 669 639 670 640 $blog = get_site( $blog_id ); 671 641 $this->assertSame( '0', $blog->mature ); 672 $this->assertSame( 1, $test_action_counter );642 $this->assertSame( 1, $test_action_counter->get_call_count() ); 673 643 674 644 // The action should not fire if the status of 'mature' stays the same. … … 677 647 678 648 $this->assertSame( '0', $blog->mature ); 679 $this->assertSame( 1, $test_action_counter ); 680 681 remove_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 ); 649 $this->assertSame( 1, $test_action_counter->get_call_count() ); 682 650 } 683 651 684 652 public function test_update_blog_status_update_blog_public_action() { 685 global $test_action_counter; 686 $test_action_counter = 0; 653 $test_action_counter = new MockAction(); 687 654 688 655 $blog_id = self::factory()->blog->create(); 689 656 690 add_action( 'update_blog_public', array( $t his, 'action_counter_cb' ), 10);657 add_action( 'update_blog_public', array( $test_action_counter, 'action' ) ); 691 658 update_blog_status( $blog_id, 'public', 0 ); 692 659 693 660 $blog = get_site( $blog_id ); 694 661 $this->assertSame( '0', $blog->public ); 695 $this->assertSame( 1, $test_action_counter );662 $this->assertSame( 1, $test_action_counter->get_call_count() ); 696 663 697 664 // The action should not fire if the status of 'mature' stays the same. … … 700 667 701 668 $this->assertSame( '0', $blog->public ); 702 $this->assertSame( 1, $test_action_counter ); 703 704 remove_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 ); 669 $this->assertSame( 1, $test_action_counter->get_call_count() ); 705 670 } 706 671 -
trunk/tests/phpunit/tests/multisite/updateBlogDetails.php
r52010 r54756 57 57 */ 58 58 public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) { 59 global $test_action_counter; 60 $test_action_counter = 0; 59 $test_action_counter = new MockAction(); 61 60 62 61 $blog_id = self::factory()->blog->create(); … … 67 66 } 68 67 69 add_action( $hook, array( $t his, 'action_counter_cb' ), 10);68 add_action( $hook, array( $test_action_counter, 'action' ) ); 70 69 71 70 update_blog_details( $blog_id, array( $flag => $flag_value ) ); … … 75 74 76 75 // The hook attached to this flag should have fired once during update_blog_details(). 77 $this->assertSame( 1, $test_action_counter );76 $this->assertSame( 1, $test_action_counter->get_call_count() ); 78 77 79 78 // Update the site to the exact same flag value for this flag. … … 81 80 82 81 // The hook attached to this flag should not have fired again. 83 $this->assertSame( 1, $test_action_counter ); 84 85 remove_action( $hook, array( $this, 'action_counter_cb' ), 10 ); 82 $this->assertSame( 1, $test_action_counter->get_call_count() ); 86 83 } 87 84 … … 97 94 array( 'mature', '0', 'unmature_blog' ), 98 95 ); 99 }100 101 /**102 * Provide a counter to determine that hooks are firing when intended.103 */104 public function action_counter_cb() {105 global $test_action_counter;106 $test_action_counter++;107 96 } 108 97
Note: See TracChangeset
for help on using the changeset viewer.