| 589 | * @group bp_core_get_directory_page_ids |
| 590 | */ |
| 591 | public function test_bp_core_get_directory_page_ids_register_activate_pages_created_signup_not_allowed() { |
| 592 | $bp = buddypress(); |
| 593 | $reset_page_ids = bp_core_get_directory_page_ids(); |
| 594 | $reset_bp_pages = $bp->pages; |
| 595 | $reset_current_component = $bp->current_component; |
| 596 | $reset_unfiltered_uri = $bp->unfiltered_uri; |
| 597 | |
| 598 | // Reset pages |
| 599 | $bp->pages = bp_core_get_directory_pages(); |
| 600 | |
| 601 | $r = $this->factory->post->create( array( |
| 602 | 'post_type' => 'page', |
| 603 | 'post_title' => 'Register', |
| 604 | 'post_status' => 'publish' |
| 605 | ) ); |
| 606 | |
| 607 | $a = $this->factory->post->create( array( |
| 608 | 'post_type' => 'page', |
| 609 | 'post_title' => 'Activate', |
| 610 | 'post_status' => 'publish' |
| 611 | ) ); |
| 612 | |
| 613 | $new_page_ids = array_merge( $reset_page_ids, array( 'register' => $r, 'activate' => $a ) ); |
| 614 | bp_core_update_directory_page_ids( $new_page_ids ); |
| 615 | |
| 616 | add_filter( 'bp_get_signup_allowed', '__return_false', 999 ); |
| 617 | |
| 618 | $test_page_ids = bp_core_get_directory_page_ids(); |
| 619 | |
| 620 | // If the admin set the activate and register pages, bp_core_get_directory_page_ids() should include them |
| 621 | $this->assertEqualSets( $new_page_ids, $test_page_ids ); |
| 622 | |
| 623 | // Go to signup page |
| 624 | $this->go_to( bp_get_signup_page() ); |
| 625 | |
| 626 | $this->assertTrue( $r == $bp->pages->register->id ); |
| 627 | $this->assertTrue( $a == $bp->pages->activate->id ); |
| 628 | $this->assertEquals( $bp->current_component, 'register', 'Current component should be set to register when a page is defined for registration even if signups are not allowed' ); |
| 629 | |
| 630 | remove_filter( 'bp_get_signup_allowed', '__return_false', 999 ); |
| 631 | |
| 632 | // Reset page_ids |
| 633 | bp_core_update_directory_page_ids( $reset_page_ids ); |
| 634 | |
| 635 | // Reset buddypress() vars |
| 636 | $bp->pages = $reset_bp_pages; |
| 637 | $bp->current_component = $reset_current_component; |
| 638 | $bp->unfiltered_uri = $reset_unfiltered_uri; |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * @group bp_core_get_directory_page_ids |
| 643 | */ |
| 644 | public function test_bp_core_get_directory_page_ids_register_activate_pages_notcreated_signup_not_allowed() { |
| 645 | $bp = buddypress(); |
| 646 | $reset_bp_pages = $bp->pages; |
| 647 | $reset_current_component = $bp->current_component; |
| 648 | $reset_unfiltered_uri = $bp->unfiltered_uri; |
| 649 | |
| 650 | add_filter( 'bp_get_signup_allowed', '__return_false', 999 ); |
| 651 | |
| 652 | // Go to signup page |
| 653 | $this->go_to( bp_get_signup_page() ); |
| 654 | |
| 655 | $this->assertFalse( isset( $bp->pages->register ) ); |
| 656 | $this->assertFalse( isset( $bp->pages->activate ) ); |
| 657 | $this->assertEmpty( $bp->current_component, 'Current component should not be set when the register page has not been created' ); |
| 658 | |
| 659 | remove_filter( 'bp_get_signup_allowed', '__return_false', 999 ); |
| 660 | |
| 661 | // Reset buddypress() vars |
| 662 | $bp->pages = $reset_bp_pages; |
| 663 | $bp->current_component = $reset_current_component; |
| 664 | $bp->unfiltered_uri = $reset_unfiltered_uri; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * @group bp_core_get_directory_page_ids |
| 669 | */ |
| 670 | public function test_bp_core_get_directory_page_ids_register_activate_pages_created_signup_allowed() { |
| 671 | $bp = buddypress(); |
| 672 | $reset_page_ids = bp_core_get_directory_page_ids(); |
| 673 | $reset_bp_pages = $bp->pages; |
| 674 | $reset_current_component = $bp->current_component; |
| 675 | $reset_unfiltered_uri = $bp->unfiltered_uri; |
| 676 | |
| 677 | // Reset pages |
| 678 | $bp->pages = bp_core_get_directory_pages(); |
| 679 | |
| 680 | $r = $this->factory->post->create( array( |
| 681 | 'post_type' => 'page', |
| 682 | 'post_title' => 'Register', |
| 683 | 'post_status' => 'publish' |
| 684 | ) ); |
| 685 | |
| 686 | $a = $this->factory->post->create( array( |
| 687 | 'post_type' => 'page', |
| 688 | 'post_title' => 'Activate', |
| 689 | 'post_status' => 'publish' |
| 690 | ) ); |
| 691 | |
| 692 | $new_page_ids = array_merge( $reset_page_ids, array( 'register' => $r, 'activate' => $a ) ); |
| 693 | bp_core_update_directory_page_ids( $new_page_ids ); |
| 694 | |
| 695 | add_filter( 'bp_get_signup_allowed', '__return_true', 999 ); |
| 696 | |
| 697 | $test_page_ids = bp_core_get_directory_page_ids(); |
| 698 | |
| 699 | // If the admin set the activate and register pages, bp_core_get_directory_page_ids() should include them |
| 700 | $this->assertEqualSets( $new_page_ids, $test_page_ids ); |
| 701 | |
| 702 | // Go to signup page |
| 703 | $this->go_to( bp_get_signup_page() ); |
| 704 | |
| 705 | $this->assertTrue( $r == $bp->pages->register->id ); |
| 706 | $this->assertTrue( $a == $bp->pages->activate->id ); |
| 707 | $this->assertEquals( $bp->current_component, 'register', 'Current component should be set to register when a page is defined for registration' ); |
| 708 | |
| 709 | remove_filter( 'bp_get_signup_allowed', '__return_true', 999 ); |
| 710 | |
| 711 | // Reset page_ids |
| 712 | bp_core_update_directory_page_ids( $reset_page_ids ); |
| 713 | |
| 714 | // Reset buddypress() vars |
| 715 | $bp->pages = $reset_bp_pages; |
| 716 | $bp->current_component = $reset_current_component; |
| 717 | $bp->unfiltered_uri = $reset_unfiltered_uri; |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * @group bp_core_get_directory_page_ids |
| 722 | */ |
| 723 | public function test_bp_core_get_directory_page_ids_register_activate_pages_notcreated_signup_allowed() { |
| 724 | $bp = buddypress(); |
| 725 | $reset_bp_pages = $bp->pages; |
| 726 | $reset_current_component = $bp->current_component; |
| 727 | $reset_unfiltered_uri = $bp->unfiltered_uri; |
| 728 | |
| 729 | // Reset pages |
| 730 | $bp->pages = bp_core_get_directory_pages(); |
| 731 | |
| 732 | add_filter( 'bp_get_signup_allowed', '__return_true', 999 ); |
| 733 | |
| 734 | // Go to signup page |
| 735 | $this->go_to( bp_get_signup_page() ); |
| 736 | |
| 737 | $this->assertFalse( isset( $bp->pages->register ) ); |
| 738 | $this->assertFalse( isset( $bp->pages->activate ) ); |
| 739 | $this->assertEmpty( $bp->current_component, 'Current component should not be set when the register page has not been created even if signups are allowed' ); |
| 740 | |
| 741 | remove_filter( 'bp_get_signup_allowed', '__return_true', 999 ); |
| 742 | |
| 743 | // Reset buddypress() vars |
| 744 | $bp->pages = $reset_bp_pages; |
| 745 | $bp->current_component = $reset_current_component; |
| 746 | $bp->unfiltered_uri = $reset_unfiltered_uri; |
| 747 | } |
| 748 | |
| 749 | /** |