[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/settings/ -> bpSettingsSanitizeNotificationSettings.php (source)

   1  <?php
   2  
   3  /**
   4   * @group settings
   5   */
   6  class BP_Tests_Settings_BpSettingsSanitizeNotificationSettings extends BP_UnitTestCase {
   7      protected $core_notification_settings = array(
   8          'notification_messages_new_message',
   9          'notification_activity_new_mention',
  10          'notification_activity_new_reply',
  11          'notification_groups_invite',
  12          'notification_groups_group_updated',
  13          'notification_groups_admin_promotion',
  14          'notification_groups_membership_request',
  15          'notification_friends_friendship_request',
  16          'notification_friends_friendship_accepted',
  17      );
  18  
  19      public function test_should_ignore_setting_not_added_via_bp_notification_settings_callback() {
  20          $settings = array(
  21              'foo' => 'yes',
  22          );
  23  
  24          $sanitized = bp_settings_sanitize_notification_settings( $settings );
  25  
  26          $this->assertArrayNotHasKey( 'foo', $sanitized );
  27      }
  28  
  29      public function test_should_accept_setting_added_via_bp_notification_settings_callback() {
  30          $settings = array(
  31              'foo' => 'yes',
  32          );
  33  
  34          add_action( 'bp_notification_settings', array( $this, 'add_custom_notification_setting' ) );
  35          $sanitized = bp_settings_sanitize_notification_settings( $settings );
  36          remove_action( 'bp_notification_settings', array( $this, 'add_custom_notification_setting' ) );
  37  
  38          $this->assertArrayHasKey( 'foo', $sanitized );
  39          $this->assertSame( 'yes', $sanitized['foo'] );
  40      }
  41  
  42      public function test_should_sanitize_invalid_values_to_no_for_core_settings() {
  43  
  44          $settings = array();
  45          foreach ( $this->core_notification_settings as $key ) {
  46              $settings[ $key ] = 'foo';
  47          }
  48  
  49          add_action( 'bp_notification_settings', array( $this, 'add_core_notification_settings' ) );
  50          $sanitized = bp_settings_sanitize_notification_settings( $settings );
  51          remove_action( 'bp_notification_settings', array( $this, 'add_core_notification_settings' ) );
  52  
  53          $expected = array();
  54          foreach ( $this->core_notification_settings as $key ) {
  55              $expected[ $key ] = 'no';
  56          }
  57  
  58          $this->assertEqualSets( $expected, $sanitized );
  59      }
  60  
  61      public function test_should_not_sanitize_values_for_custom_setting() {
  62          $settings = array(
  63              'foo' => 'bar',
  64          );
  65  
  66          add_action( 'bp_notification_settings', array( $this, 'add_custom_notification_setting' ) );
  67          $sanitized = bp_settings_sanitize_notification_settings( $settings );
  68          remove_action( 'bp_notification_settings', array( $this, 'add_custom_notification_setting' ) );
  69  
  70          $this->assertArrayHasKey( 'foo', $sanitized );
  71          $this->assertSame( 'bar', $sanitized['foo'] );
  72      }
  73  
  74  	public function add_custom_notification_setting() {
  75          echo '<input name="notifications[foo]" value="yes" />';
  76      }
  77  
  78  	public function add_core_notification_settings() {
  79          foreach ( $this->core_notification_settings as $key ) {
  80              echo '<input name="notifications[' . $key . ']" value="yes" />';
  81          }
  82      }
  83  }


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1