Skip to content

Commit

Permalink
max test coverage for sanitize_options()
Browse files Browse the repository at this point in the history
  • Loading branch information
stklcode committed Mar 14, 2024
1 parent 5b8a384 commit a067a32
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion tests/test-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function test_sanitize_options() {
'snippet' => 0,
'blacklist' => 0,
'show_totals' => 0,
'show_widget_roles' => null, // Just for documentation, the default is calculated later.
'show_widget_roles' => null,
'skip' => array(
'logged_in' => Statify::SKIP_USERS_ALL,
),
Expand Down Expand Up @@ -66,6 +66,61 @@ public function test_sanitize_options() {
'string values should be sanitized to numbers or 1/0 for boolean flags'
);

self::assertSame(
array(
'days' => 14,
'days_show' => 14,
'limit' => 100,
'today' => 0,
'blacklist' => 0,
'show_totals' => 0,
),
Statify_Settings::sanitize_options( array( 'limit' => 101 ) ),
'limit was not capped at 100'
);

self::assertSame(
array(
'days' => 14,
'days_show' => 14,
'limit' => 3,
'snippet' => 1,
'today' => 0,
'blacklist' => 0,
'show_totals' => 0,
'skip' => array(
'logged_in' => 0,
),
),
Statify_Settings::sanitize_options(
array(
'snippet' => '1',
'skip' => array(
'logged_in' => '0',
),
)
),
'valid "snippet" and "logged_in" settings not passed through'
);

self::assertSame(
array(
'days' => 14,
'days_show' => 14,
'limit' => 3,
'today' => 0,
'blacklist' => 0,
'show_totals' => 0,
),
Statify_Settings::sanitize_options(
array(
'snippet' => 3,
'logged_in' => -1,
)
),
'illegal "snippet" and "logged_in" settings not removed'
);

self::assertSame(
array(
'days' => 14,
Expand Down

0 comments on commit a067a32

Please sign in to comment.