[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/messages/ -> class.bp-messages-notice.php (source)

   1  <?php
   2  
   3  /**
   4   * @group notices
   5   */
   6  class BP_Tests_BP_Messages_Notice_TestCases extends BP_UnitTestCase {
   7  
   8      protected $old_current_user = 0;
   9  
  10  	public function setUp() {
  11          parent::setUp();
  12          $this->old_current_user = get_current_user_id();
  13          $this->set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
  14      }
  15  
  16  	public function tearDown() {
  17          parent::tearDown();
  18          $this->set_current_user( $this->old_current_user );
  19      }
  20  
  21      /**
  22       * @group cache
  23       */
  24  	public function test_get_active_notices() {
  25          // send notice
  26          $subject = 'Test notice';
  27          $message = 'This is a notice';
  28          messages_send_notice( $subject, $message );
  29  
  30          // now get the active notice and assert
  31          $notice = BP_Messages_Notice::get_active();
  32          $this->assertEquals( $subject, $notice->subject );
  33          $this->assertEquals( $message, $notice->message );
  34  
  35          // deactivate notice and make sure cache is invalidated
  36          $notice->deactivate();
  37          $this->assertFalse( wp_cache_get( 'active_notice', 'bp_messages' ) );
  38  
  39          // create a new notice
  40          $subject2 = 'Another notice';
  41          $message2 = 'Say what?';
  42          messages_send_notice( $subject2, $message2 );
  43  
  44          // now get the new active notice
  45          BP_Messages_Notice::get_active();
  46  
  47          // grab the cache and make sure it equals our new notice
  48          $cache = wp_cache_get( 'active_notice', 'bp_messages' );
  49          $this->assertEquals( $subject2, $cache->subject );
  50          $this->assertEquals( $message2, $cache->message );
  51      }
  52  
  53  }


Generated: Thu Dec 26 01:01:04 2024 Cross-referenced by PHPXref 0.7.1