Changeset 30785
- Timestamp:
- 12/08/2014 02:14:21 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r30784 r30785 572 572 } 573 573 574 /** 575 * Updating a field returns the sme value that was passed. 576 */ 574 577 function test_update_blog_status() { 575 global $test_action_counter; 576 577 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 578 $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 579 $this->assertInternalType( 'int', $blog_id ); 580 581 $test_action_counter = 0; 582 $count = 1; 583 584 add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 585 $result = update_blog_status( $blog_id, 'spam', 0 ); 578 $result = update_blog_status( 1, 'spam', 0 ); 586 579 $this->assertEquals( 0, $result ); 587 $blog = get_blog_details( $blog_id ); 580 } 581 582 /** 583 * Updating an invalid field returns the same value that was passed. 584 */ 585 function test_update_blog_status_invalid_status() { 586 $result = update_blog_status( 1, 'doesnotexist', 'invalid' ); 587 $this->assertEquals( 'invalid', $result ); 588 } 589 590 function test_update_blog_status_make_ham_blog_action() { 591 global $test_action_counter; 592 $test_action_counter = 0; 593 594 $blog_id = $this->factory->blog->create(); 595 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 596 597 add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); 598 update_blog_status( $blog_id, 'spam', 0 ); 599 $blog = get_blog_details( $blog_id ); 600 588 601 $this->assertEquals( '0', $blog->spam ); 589 $this->assertEquals( $count, $test_action_counter ); 590 591 // Same again 592 $count++; 593 $result = update_blog_status( $blog_id, 'spam', 0 ); 594 $this->assertEquals( 0, $result ); 595 $blog = get_blog_details( $blog_id ); 602 $this->assertEquals( 1, $test_action_counter ); 603 604 // The action should fire if the status of 'spam' stays the same. 605 update_blog_status( $blog_id, 'spam', 0 ); 606 $blog = get_blog_details( $blog_id ); 607 596 608 $this->assertEquals( '0', $blog->spam ); 597 $this->assertEquals( $count, $test_action_counter ); 598 remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 599 600 $count++; 601 add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 602 $result = update_blog_status( $blog_id, 'spam', 1 ); 603 $this->assertEquals( 1, $result ); 604 $blog = get_blog_details( $blog_id ); 609 $this->assertEquals( 2, $test_action_counter ); 610 611 remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); 612 } 613 614 function test_update_blog_status_make_spam_blog_action() { 615 global $test_action_counter; 616 $test_action_counter = 0; 617 618 $blog_id = $this->factory->blog->create(); 619 620 add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); 621 update_blog_status( $blog_id, 'spam', 1 ); 622 $blog = get_blog_details( $blog_id ); 623 605 624 $this->assertEquals( '1', $blog->spam ); 606 $this->assertEquals( $count, $test_action_counter ); 607 608 // Same again 609 $count++; 610 $result = update_blog_status( $blog_id, 'spam', 1 ); 611 $this->assertEquals( 1, $result ); 612 $blog = get_blog_details( $blog_id ); 625 $this->assertEquals( 1, $test_action_counter ); 626 627 // The action should fire if the status of 'spam' stays the same. 628 update_blog_status( $blog_id, 'spam', 1 ); 629 $blog = get_blog_details( $blog_id ); 630 613 631 $this->assertEquals( '1', $blog->spam ); 614 $this->assertEquals( $count, $test_action_counter ); 615 remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 616 617 add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 618 $count++; 619 $result = update_blog_status( $blog_id, 'archived', 1 ); 620 $this->assertEquals( 1, $result ); 621 $blog = get_blog_details( $blog_id ); 632 $this->assertEquals( 2, $test_action_counter ); 633 634 remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); 635 } 636 637 function test_update_blog_status_archive_blog_action() { 638 global $test_action_counter; 639 $test_action_counter = 0; 640 641 $blog_id = $this->factory->blog->create(); 642 643 add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); 644 update_blog_status( $blog_id, 'archived', 1 ); 645 $blog = get_blog_details( $blog_id ); 646 622 647 $this->assertEquals( '1', $blog->archived ); 623 $this->assertEquals( $count, $test_action_counter ); 624 625 // Same again 626 $count++; 627 $result = update_blog_status( $blog_id, 'archived', 1 ); 628 $this->assertEquals( 1, $result ); 629 $blog = get_blog_details( $blog_id ); 648 $this->assertEquals( 1, $test_action_counter ); 649 650 // The action should fire if the status of 'archived' stays the same. 651 update_blog_status( $blog_id, 'archived', 1 ); 652 $blog = get_blog_details( $blog_id ); 653 630 654 $this->assertEquals( '1', $blog->archived ); 631 $this->assertEquals( $count, $test_action_counter ); 632 remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 633 634 add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 635 $count++; 636 $result = update_blog_status( $blog_id, 'archived', 0 ); 637 $this->assertEquals( 0, $result ); 638 $blog = get_blog_details( $blog_id ); 655 $this->assertEquals( 2, $test_action_counter ); 656 657 remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); 658 } 659 660 function test_update_blog_status_unarchive_blog_action() { 661 global $test_action_counter; 662 $test_action_counter = 0; 663 664 $blog_id = $this->factory->blog->create(); 665 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 666 667 add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); 668 update_blog_status( $blog_id, 'archived', 0 ); 669 $blog = get_blog_details( $blog_id ); 670 639 671 $this->assertEquals( '0', $blog->archived ); 640 $this->assertEquals( $count, $test_action_counter ); 641 642 // Same again 643 $result = update_blog_status( $blog_id, 'archived', 0 ); 644 $count++; 645 $this->assertEquals( 0, $result ); 672 $this->assertEquals( 1, $test_action_counter ); 673 674 // The action should fire if the status of 'archived' stays the same. 675 update_blog_status( $blog_id, 'archived', 0 ); 646 676 $blog = get_blog_details( $blog_id ); 647 677 $this->assertEquals( '0', $blog->archived ); 648 $this->assertEquals( $count, $test_action_counter ); 649 remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 650 651 add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 652 $count++; 653 $result = update_blog_status( $blog_id, 'deleted', 1 ); 654 $this->assertEquals( 1, $result ); 655 $blog = get_blog_details( $blog_id ); 678 $this->assertEquals( 2, $test_action_counter ); 679 680 remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); 681 } 682 683 function test_update_blog_status_make_delete_blog_action() { 684 global $test_action_counter; 685 $test_action_counter = 0; 686 687 $blog_id = $this->factory->blog->create(); 688 689 add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); 690 update_blog_status( $blog_id, 'deleted', 1 ); 691 $blog = get_blog_details( $blog_id ); 692 656 693 $this->assertEquals( '1', $blog->deleted ); 657 $this->assertEquals( $count, $test_action_counter ); 658 659 // Same again 660 $count++; 661 $result = update_blog_status( $blog_id, 'deleted', 1 ); 662 $this->assertEquals( 1, $result ); 663 $blog = get_blog_details( $blog_id ); 694 $this->assertEquals( 1, $test_action_counter ); 695 696 // The action should fire if the status of 'deleted' stays the same. 697 update_blog_status( $blog_id, 'deleted', 1 ); 698 $blog = get_blog_details( $blog_id ); 699 664 700 $this->assertEquals( '1', $blog->deleted ); 665 $this->assertEquals( $count, $test_action_counter ); 666 remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 667 668 add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 669 $count++; 670 $result = update_blog_status( $blog_id, 'deleted', 0 ); 671 $this->assertEquals( 0, $result ); 672 $blog = get_blog_details( $blog_id ); 701 $this->assertEquals( 2, $test_action_counter ); 702 703 remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); 704 } 705 706 function test_update_blog_status_make_undelete_blog_action() { 707 global $test_action_counter; 708 $test_action_counter = 0; 709 710 $blog_id = $this->factory->blog->create(); 711 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 712 713 add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); 714 update_blog_status( $blog_id, 'deleted', 0 ); 715 $blog = get_blog_details( $blog_id ); 716 673 717 $this->assertEquals( '0', $blog->deleted ); 674 $this->assertEquals( $count, $test_action_counter ); 675 676 // Same again 677 $count++; 678 $result = update_blog_status( $blog_id, 'deleted', 0 ); 679 $this->assertEquals( 0, $result ); 680 $blog = get_blog_details( $blog_id ); 718 $this->assertEquals( 1, $test_action_counter ); 719 720 // The action should fire if the status of 'deleted' stays the same. 721 update_blog_status( $blog_id, 'deleted', 0 ); 722 $blog = get_blog_details( $blog_id ); 723 681 724 $this->assertEquals( '0', $blog->deleted ); 682 $this->assertEquals( $count, $test_action_counter ); 683 remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 684 685 add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 686 $count++; 687 $result = update_blog_status( $blog_id, 'mature', 1 ); 688 $this->assertEquals( 1, $result ); 689 $blog = get_blog_details( $blog_id ); 725 $this->assertEquals( 2, $test_action_counter ); 726 727 remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); 728 } 729 730 function test_update_blog_status_mature_blog_action() { 731 global $test_action_counter; 732 $test_action_counter = 0; 733 734 $blog_id = $this->factory->blog->create(); 735 736 add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); 737 update_blog_status( $blog_id, 'mature', 1 ); 738 $blog = get_blog_details( $blog_id ); 739 690 740 $this->assertEquals( '1', $blog->mature ); 691 $this->assertEquals( $count, $test_action_counter ); 692 693 // Same again 694 $count++; 695 $result = update_blog_status( $blog_id, 'mature', 1 ); 696 $this->assertEquals( 1, $result ); 697 $blog = get_blog_details( $blog_id ); 741 $this->assertEquals( 1, $test_action_counter ); 742 743 // The action should fire if the status of 'mature' stays the same. 744 update_blog_status( $blog_id, 'mature', 1 ); 745 $blog = get_blog_details( $blog_id ); 746 698 747 $this->assertEquals( '1', $blog->mature ); 699 $this->assertEquals( $count, $test_action_counter ); 700 remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 701 702 add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 703 $count++; 704 $result = update_blog_status( $blog_id, 'mature', 0 ); 705 $this->assertEquals( 0, $result ); 748 $this->assertEquals( 2, $test_action_counter ); 749 750 remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); 751 } 752 753 function test_update_blog_status_unmature_blog_action() { 754 global $test_action_counter; 755 $test_action_counter = 0; 756 757 $blog_id = $this->factory->blog->create(); 758 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 759 760 add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); 761 update_blog_status( $blog_id, 'mature', 0 ); 762 706 763 $blog = get_blog_details( $blog_id ); 707 764 $this->assertEquals( '0', $blog->mature ); 708 $this->assertEquals( $count, $test_action_counter ); 709 710 // Same again 711 $count++; 712 $result = update_blog_status( $blog_id, 'mature', 0 ); 713 $this->assertEquals( 0, $result ); 714 $blog = get_blog_details( $blog_id ); 765 $this->assertEquals( 1, $test_action_counter ); 766 767 // The action should fire if the status of 'mature' stays the same. 768 update_blog_status( $blog_id, 'mature', 0 ); 769 $blog = get_blog_details( $blog_id ); 770 715 771 $this->assertEquals( '0', $blog->mature ); 716 $this->assertEquals( $count, $test_action_counter ); 717 remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 718 719 add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); 720 $count++; 721 $result = update_blog_status( $blog_id, 'public', 0 ); 722 $this->assertEquals( 0, $result ); 772 $this->assertEquals( 2, $test_action_counter ); 773 774 remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); 775 } 776 777 function test_update_blog_status_update_blog_public_action() { 778 global $test_action_counter; 779 $test_action_counter = 0; 780 781 $blog_id = $this->factory->blog->create(); 782 783 add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 ); 784 update_blog_status( $blog_id, 'public', 0 ); 785 723 786 $blog = get_blog_details( $blog_id ); 724 787 $this->assertEquals( '0', $blog->public ); 725 $this->assertEquals( $count, $test_action_counter ); 726 727 // Same again 728 $count++; 729 $result = update_blog_status( $blog_id, 'public', 0 ); 730 $this->assertEquals( 0, $result ); 731 $blog = get_blog_details( $blog_id ); 788 $this->assertEquals( 1, $test_action_counter ); 789 790 // The action should fire if the status of 'mature' stays the same. 791 update_blog_status( $blog_id, 'public', 0 ); 792 $blog = get_blog_details( $blog_id ); 793 732 794 $this->assertEquals( '0', $blog->public ); 733 $this->assertEquals( $count, $test_action_counter ); 734 remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); 735 736 add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); 737 $count++; 738 $result = update_blog_status( $blog_id, 'public', 1 ); 739 $this->assertEquals( 1, $result ); 740 $blog = get_blog_details( $blog_id ); 741 $this->assertEquals( '1', $blog->public ); 742 $this->assertEquals( $count, $test_action_counter ); 743 744 // Same again 745 $count++; 746 $result = update_blog_status( $blog_id, 'public', 1 ); 747 $this->assertEquals( 1, $result ); 748 $blog = get_blog_details( $blog_id ); 749 $this->assertEquals( '1', $blog->public ); 750 $this->assertEquals( $count, $test_action_counter ); 751 remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10, 1 ); 752 753 // Updating a dummy field returns the value passed. Go fig. 754 $result = update_blog_status( $blog_id, 'doesnotexist', 1 ); 755 $this->assertEquals( 1, $result ); 795 $this->assertEquals( 2, $test_action_counter ); 796 797 remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 ); 756 798 } 757 799
Note: See TracChangeset
for help on using the changeset viewer.