',
+ ),
+ 'unsafe additional classes' => array(
+ 'message' => 'A notice with unsafe additional classes.',
+ 'args' => array(
+ 'additional_classes' => array( '">
alert( "Howdy, admin!" );
A notice with unsafe additional classes.
',
+ ),
+ 'a type that is not a string' => array(
+ 'message' => 'A notice with a type that is not a string.',
+ 'args' => array(
+ 'type' => array(),
+ ),
+ 'expected' => '
A notice with a type that is not a string.
',
+ ),
+ 'a type with only empty space' => array(
+ 'message' => 'A notice with a type with only empty space.',
+ 'args' => array(
+ 'type' => " \t\r\n",
+ ),
+ 'expected' => '
A notice with a type with only empty space.
',
+ ),
+ 'an ID that is not a string' => array(
+ 'message' => 'A notice with an ID that is not a string.',
+ 'args' => array(
+ 'id' => array( 'message' ),
+ ),
+ 'expected' => '
A notice with an ID that is not a string.
',
+ ),
+ 'an ID with only empty space' => array(
+ 'message' => 'A notice with an ID with only empty space.',
+ 'args' => array(
+ 'id' => " \t\r\n",
+ ),
+ 'expected' => '
A notice with an ID with only empty space.
',
+ ),
+ 'dismissible as a truthy value rather than (bool) true' => array(
+ 'message' => 'A notice with dismissible as a truthy value rather than (bool) true.',
+ 'args' => array(
+ 'dismissible' => 1,
+ ),
+ 'expected' => '
A notice with dismissible as a truthy value rather than (bool) true.
',
+ ),
+ 'additional classes that are not an array' => array(
+ 'message' => 'A notice with additional classes that are not an array.',
+ 'args' => array(
+ 'additional_classes' => 'class-1 class-2 class-3',
+ ),
+ 'expected' => '
A notice with additional classes that are not an array.
',
+ ),
+ 'additional attribute with a value' => array(
+ 'message' => 'A notice with an additional attribute with a value.',
+ 'args' => array(
+ 'attributes' => array( 'aria-live' => 'assertive' ),
+ ),
+ 'expected' => '
A notice with an additional attribute with a value.
',
+ ),
+ 'additional hidden attribute' => array(
+ 'message' => 'A notice with the hidden attribute.',
+ 'args' => array(
+ 'attributes' => array( 'hidden' => true ),
+ ),
+ 'expected' => '
A notice with the hidden attribute.
',
+ ),
+ 'additional attribute no associative keys' => array(
+ 'message' => 'A notice with a boolean attribute without an associative key.',
+ 'args' => array(
+ 'attributes' => array( 'hidden' ),
+ ),
+ 'expected' => '
A notice with a boolean attribute without an associative key.
',
+ ),
+ 'additional attribute with role' => array(
+ 'message' => 'A notice with an additional attribute role.',
+ 'args' => array(
+ 'attributes' => array( 'role' => 'alert' ),
+ ),
+ 'expected' => '
A notice with an additional attribute role.
',
+ ),
+ 'multiple additional attributes' => array(
+ 'message' => 'A notice with multiple additional attributes.',
+ 'args' => array(
+ 'attributes' => array(
+ 'role' => 'alert',
+ 'data-test' => -1,
+ ),
+ ),
+ 'expected' => '
A notice with multiple additional attributes.
',
+ ),
+ 'data attribute with unsafe value' => array(
+ 'message' => 'A notice with an additional attribute with an unsafe value.',
+ 'args' => array(
+ 'attributes' => array( 'data-unsafe' => '' ),
+ ),
+ 'expected' => '
A notice with an additional attribute with an unsafe value.
',
+ ),
+ 'additional invalid attribute' => array(
+ 'message' => 'A notice with an additional attribute that is invalid.',
+ 'args' => array(
+ 'attributes' => array( 'not-valid' => 'not-valid' ),
+ ),
+ 'expected' => '
A notice with an additional attribute that is invalid.
',
+ ),
+ 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array(
+ 'message' => 'A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.',
+ 'args' => array(
+ 'attributes' => array(
+ 'role' => 'alert',
+ 'disabled' => 'disabled',
+ 'data-name' => 'my-name',
+ 'data-id' => 1,
+ 'hidden',
+ ),
+ ),
+ 'expected' => '
A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.
',
+ ),
+ 'paragraph wrapping as a falsy value rather than (bool) false' => array(
+ 'message' => 'A notice with paragraph wrapping as a falsy value rather than (bool) false.',
+ 'args' => array(
+ 'paragraph_wrap' => 0,
+ ),
+ 'expected' => '
A notice with paragraph wrapping as a falsy value rather than (bool) false.
',
+ ),
+ 'a notice that should be dismissed permanently' => array(
+ 'message' => 'A notice that should be dismissed permanently.',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-permanently',
+ ),
+ ),
+ 'expected' => '
A notice that should be dismissed permanently.
',
+ ),
+ 'a notice that should be dismissed for 30 days' => array(
+ 'message' => 'A notice that should be dismissed for 30 days.',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-for-30-days',
+ 'expiration' => 30 * DAY_IN_SECONDS,
+ ),
+ ),
+ 'expected' => '
A notice that should be dismissed for 30 days.
',
+ ),
+ );
+ }
+
+ /**
+ * Tests that `_doing_it_wrong()` is thrown when a 'type' containing spaces is passed.
+ *
+ * @ticket 57791
+ *
+ * @expectedIncorrectUsage wp_get_admin_notice
+ */
+ public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() {
+ ob_start();
+ wp_admin_notice(
+ 'A type containing spaces.',
+ array( 'type' => 'first second third fourth' )
+ );
+ $actual = ob_get_clean();
+
+ $this->assertSame(
+ '
A type containing spaces.
',
+ $actual
+ );
+ }
+
+ /**
+ * Tests that `wp_admin_notice()` fires the 'wp_admin_notice' action.
+ *
+ * @ticket 57791
+ */
+ public function test_should_fire_wp_admin_notice_action() {
+ $action = new MockAction();
+ add_action( 'wp_admin_notice', array( $action, 'action' ) );
+
+ ob_start();
+ wp_admin_notice( 'A notice.', array( 'type' => 'success' ) );
+ ob_end_clean();
+
+ $this->assertSame( 1, $action->get_call_count() );
+ }
+
+
+ /**
+ * Tests that `wp_admin_notice()` outputs an empty string for a notice that is still dismissed.
+ *
+ * @ticket
+ *
+ * @dataProvider data_notices_with_dismissible_array
+ *
+ * @param array $dismissible The value for the dismissible array.
+ */
+ public function test_should_output_empty_string_for_a_notice_that_is_still_dismissed( $dismissible ) {
+ // The notice is still dismissed.
+ set_site_transient( 'wp_admin_notice_dismissed_' . $dismissible['slug'], 1 );
+
+ ob_start();
+ wp_admin_notice(
+ 'A notice that is still dismissed.',
+ array(
+ 'dismissible' => $dismissible,
+ )
+ );
+ $actual = ob_get_clean();
+
+ $this->assertSame( '', $actual );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_notices_with_dismissible_array() {
+ return array(
+ 'a permanently dismissed notice (slug only, no expiration provided)' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-forever',
+ ),
+ ),
+ 'a notice dismissed for 30 days' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-for-30-days',
+ 'expiration' => 30 * DAY_IN_SECONDS,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Tests that `wp_admin_notice()` triggers an error.
+ *
+ * @ticket
+ *
+ * @dataProvider data_should_trigger_error_for_an_invalid_dismissible_slug
+ * @dataProvider data_should_trigger_error_for_invalid_dismissible_expiration
+ *
+ * @param string $message The message.
+ * @param array $args Arguments for the admin notice.
+ * @param string $expected_markup The expected admin notice markup.
+ * @param string $expected_error The expected error message.
+ */
+ public function test_should_trigger_error( $message, $args, $expected_markup, $expected_error ) {
+ // Ensure no previous errors exist.
+ error_clear_last();
+
+ // Backup the error reporting value.
+ $original_error_reporting = error_reporting();
+
+ // Suppress E_USER_NOTICE.
+ error_reporting( E_ALL & ~E_USER_NOTICE );
+
+ ob_start();
+ wp_admin_notice( $message, $args );
+ $actual = ob_get_clean();
+ $last_error = error_get_last();
+
+ // Reset error reporting.
+ error_reporting( $original_error_reporting );
+
+ $this->assertSame( $expected_markup, $actual );
+ $this->assertIsArray( $last_error, 'An error was not triggered.' );
+ $this->assertSame( E_USER_NOTICE, $last_error['type'], 'The error was not a notice.' );
+ $this->assertSame( $last_error['message'], 'wp_get_admin_notice(): ' . $expected_error, 'The wrong error message was sent.' );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_should_trigger_error_for_an_invalid_dismissible_slug() {
+ return array(
+ 'an empty "dismissible" array' => array(
+ 'message' => 'an empty "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(),
+ ),
+ 'expected_markup' => '
an empty "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'no "slug" key in the "dismissible" array' => array(
+ 'message' => 'no "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'expiration' => 30 * DAY_IN_SECONDS ),
+ ),
+ 'expected_markup' => '
no "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a NULL "slug" key in the "dismissible" array' => array(
+ 'message' => 'a NULL "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => null ),
+ ),
+ 'expected_markup' => '
a NULL "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a (bool) false "slug" key in the "dismissible" array' => array(
+ 'message' => 'a (bool) false "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => false ),
+ ),
+ 'expected_markup' => '
a (bool) false "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a (bool) true "slug" key in the "dismissible" array' => array(
+ 'message' => 'a (bool) true "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => true ),
+ ),
+ 'expected_markup' => '
a (bool) true "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an integer "slug" key in the "dismissible" array' => array(
+ 'message' => 'an integer "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => 1234 ),
+ ),
+ 'expected_markup' => '
an integer "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a float "slug" key in the "dismissible" array' => array(
+ 'message' => 'a float "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => 12.34 ),
+ ),
+ 'expected_markup' => '
a float "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an empty array "slug" key in the "dismissible" array' => array(
+ 'message' => 'an empty array "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => array() ),
+ ),
+ 'expected_markup' => '
an empty array "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a populated array "slug" key in the "dismissible" array' => array(
+ 'message' => 'a populated array "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => array( 'mynotice-dismiss-forever' ) ),
+ ),
+ 'expected_markup' => '
a populated array "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an object "slug" key in the "dismissible" array' => array(
+ 'message' => 'an object "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => new stdClass() ),
+ ),
+ 'expected_markup' => '
an object "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an empty string "slug" key in the "dismissible" array' => array(
+ 'message' => 'an empty string "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => '' ),
+ ),
+ 'expected_markup' => '
an empty string "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a non-empty string.',
+ ),
+ 'a "slug" key containing only space in the "dismissible" array' => array(
+ 'message' => 'a "slug" key containing only space in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => " \r\t\n" ),
+ ),
+ 'expected_markup' => '
a "slug" key containing only space in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a non-empty string.',
+ ),
+ );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_should_trigger_error_for_invalid_dismissible_expiration() {
+ return array(
+ 'a NULL "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a null "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-null-expiration',
+ 'expiration' => null,
+ ),
+ ),
+ 'expected_markup' => '
a null "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a (bool) false "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a (bool) false "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-false-expiration',
+ 'expiration' => false,
+ ),
+ ),
+ 'expected_markup' => '
a (bool) false "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a (bool) true "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a (bool) true "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-true-expiration',
+ 'expiration' => true,
+ ),
+ ),
+ 'expected_markup' => '
a (bool) true "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'an empty array "expiration" value in the "dismissible" array' => array(
+ 'message' => 'an empty array "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-empty-array-expiration',
+ 'expiration' => array(),
+ ),
+ ),
+ 'expected_markup' => '
an empty array "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a populated array "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a populated array "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-populated-array-expiration',
+ 'expiration' => array( 30 * DAY_IN_SECONDS ),
+ ),
+ ),
+ 'expected_markup' => '
a populated array "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'an object "expiration" value in the "dismissible" array' => array(
+ 'message' => 'an object "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-object-expiration',
+ 'expiration' => array( 30 * DAY_IN_SECONDS ),
+ ),
+ ),
+ 'expected_markup' => '
an object "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a float "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a float "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-float-expiration',
+ 'expiration' => 30.0,
+ ),
+ ),
+ 'expected_markup' => '
a float "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a numeric string "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a numeric string "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-numeric-string-expiration',
+ 'expiration' => '30',
+ ),
+ ),
+ 'expected_markup' => '
a numeric string "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a NAN "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a NAN "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-nan-expiration',
+ 'expiration' => NAN,
+ ),
+ ),
+ 'expected_markup' => '
a NAN "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'an INF "expiration" value in the "dismissible" array' => array(
+ 'message' => 'an INF "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-inf-expiration',
+ 'expiration' => INF,
+ ),
+ ),
+ 'expected_markup' => '
an INF "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a negative "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a negative "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-negative-expiration',
+ 'expiration' => -1,
+ ),
+ ),
+ 'expected_markup' => '
a negative "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be greater than or equal to 0.',
+ ),
+ );
+ }
+}
diff --git a/tests/phpunit/tests/functions/wpGetAdminNotice.php b/tests/phpunit/tests/functions/wpGetAdminNotice.php
index 2aacdba7fed8d..9cfd4f5739378 100644
--- a/tests/phpunit/tests/functions/wpGetAdminNotice.php
+++ b/tests/phpunit/tests/functions/wpGetAdminNotice.php
@@ -1,326 +1,688 @@
-assertSame( $expected, wp_get_admin_notice( $message, $args ) );
- }
-
- /**
- * Data provider.
- *
- * @return array[]
- */
- public function data_should_return_admin_notice() {
- return array(
- 'defaults' => array(
- 'message' => 'A notice with defaults.',
- 'args' => array(),
- 'expected' => '
',
- ),
- 'an empty message (used for templates)' => array(
- 'message' => '',
- 'args' => array(
- 'type' => 'error',
- 'dismissible' => true,
- 'id' => 'message',
- 'additional_classes' => array( 'inline', 'hidden' ),
- ),
- 'expected' => '
',
- ),
- 'an empty message (used for templates) without paragraph wrapping' => array(
- 'message' => '',
- 'args' => array(
- 'type' => 'error',
- 'dismissible' => true,
- 'id' => 'message',
- 'additional_classes' => array( 'inline', 'hidden' ),
- 'paragraph_wrap' => false,
- ),
- 'expected' => '
',
- ),
- 'an "error" notice' => array(
- 'message' => 'An "error" notice.',
- 'args' => array(
- 'type' => 'error',
- ),
- 'expected' => '
',
- ),
- 'a "success" notice' => array(
- 'message' => 'A "success" notice.',
- 'args' => array(
- 'type' => 'success',
- ),
- 'expected' => '
',
- ),
- 'a "warning" notice' => array(
- 'message' => 'A "warning" notice.',
- 'args' => array(
- 'type' => 'warning',
- ),
- 'expected' => '
',
- ),
- 'an "info" notice' => array(
- 'message' => 'An "info" notice.',
- 'args' => array(
- 'type' => 'info',
- ),
- 'expected' => '
',
- ),
- 'a type that already starts with "notice-"' => array(
- 'message' => 'A type that already starts with "notice-".',
- 'args' => array(
- 'type' => 'notice-info',
- ),
- 'expected' => '
A type that already starts with "notice-".
',
- ),
- 'a dismissible notice' => array(
- 'message' => 'A dismissible notice.',
- 'args' => array(
- 'dismissible' => true,
- ),
- 'expected' => '
',
- ),
- 'no type and an ID' => array(
- 'message' => 'A notice with an ID.',
- 'args' => array(
- 'id' => 'message',
- ),
- 'expected' => '
',
- ),
- 'a type and an ID' => array(
- 'message' => 'A warning notice with an ID.',
- 'args' => array(
- 'type' => 'warning',
- 'id' => 'message',
- ),
- 'expected' => '
A warning notice with an ID.
',
- ),
- 'no type and additional classes' => array(
- 'message' => 'A notice with additional classes.',
- 'args' => array(
- 'additional_classes' => array( 'error', 'notice-alt' ),
- ),
- 'expected' => '
A notice with additional classes.
',
- ),
- 'a type and additional classes' => array(
- 'message' => 'A warning notice with additional classes.',
- 'args' => array(
- 'type' => 'warning',
- 'additional_classes' => array( 'error', 'notice-alt' ),
- ),
- 'expected' => '
A warning notice with additional classes.
',
- ),
- 'a dismissible notice with a type and additional classes' => array(
- 'message' => 'A dismissible warning notice with a type and additional classes.',
- 'args' => array(
- 'type' => 'warning',
- 'dismissible' => true,
- 'additional_classes' => array( 'error', 'notice-alt' ),
- ),
- 'expected' => '
A dismissible warning notice with a type and additional classes.
',
- ),
- 'a notice without paragraph wrapping' => array(
- 'message' => '
A notice without paragraph wrapping.',
- 'args' => array(
- 'paragraph_wrap' => false,
- ),
- 'expected' => '
A notice without paragraph wrapping.
',
- ),
- 'an unsafe type' => array(
- 'message' => 'A notice with an unsafe type.',
- 'args' => array(
- 'type' => '">',
- ),
- 'expected' => '
">
A notice with an unsafe type.
',
- ),
- 'an unsafe ID' => array(
- 'message' => 'A notice with an unsafe ID.',
- 'args' => array(
- 'id' => '">
A notice with an unsafe ID.
',
- ),
- 'unsafe additional classes' => array(
- 'message' => 'A notice with unsafe additional classes.',
- 'args' => array(
- 'additional_classes' => array( '">
A notice with unsafe additional classes.
',
- ),
- 'a type that is not a string' => array(
- 'message' => 'A notice with a type that is not a string.',
- 'args' => array(
- 'type' => array(),
- ),
- 'expected' => '
A notice with a type that is not a string.
',
- ),
- 'a type with only empty space' => array(
- 'message' => 'A notice with a type with only empty space.',
- 'args' => array(
- 'type' => " \t\r\n",
- ),
- 'expected' => '
A notice with a type with only empty space.
',
- ),
- 'an ID that is not a string' => array(
- 'message' => 'A notice with an ID that is not a string.',
- 'args' => array(
- 'id' => array( 'message' ),
- ),
- 'expected' => '
A notice with an ID that is not a string.
',
- ),
- 'an ID with only empty space' => array(
- 'message' => 'A notice with an ID with only empty space.',
- 'args' => array(
- 'id' => " \t\r\n",
- ),
- 'expected' => '
A notice with an ID with only empty space.
',
- ),
- 'dismissible as a truthy value rather than (bool) true' => array(
- 'message' => 'A notice with dismissible as a truthy value rather than (bool) true.',
- 'args' => array(
- 'dismissible' => 1,
- ),
- 'expected' => '
A notice with dismissible as a truthy value rather than (bool) true.
',
- ),
- 'additional classes that are not an array' => array(
- 'message' => 'A notice with additional classes that are not an array.',
- 'args' => array(
- 'additional_classes' => 'class-1 class-2 class-3',
- ),
- 'expected' => '
A notice with additional classes that are not an array.
',
- ),
- 'additional attribute with a value' => array(
- 'message' => 'A notice with an additional attribute with a value.',
- 'args' => array(
- 'attributes' => array( 'aria-live' => 'assertive' ),
- ),
- 'expected' => '
A notice with an additional attribute with a value.
',
- ),
- 'additional hidden attribute' => array(
- 'message' => 'A notice with the hidden attribute.',
- 'args' => array(
- 'attributes' => array( 'hidden' => true ),
- ),
- 'expected' => '
A notice with the hidden attribute.
',
- ),
- 'additional attribute no associative keys' => array(
- 'message' => 'A notice with a boolean attribute without an associative key.',
- 'args' => array(
- 'attributes' => array( 'hidden' ),
- ),
- 'expected' => '
A notice with a boolean attribute without an associative key.
',
- ),
- 'additional attribute with role' => array(
- 'message' => 'A notice with an additional attribute role.',
- 'args' => array(
- 'attributes' => array( 'role' => 'alert' ),
- ),
- 'expected' => '
A notice with an additional attribute role.
',
- ),
- 'multiple additional attributes' => array(
- 'message' => 'A notice with multiple additional attributes.',
- 'args' => array(
- 'attributes' => array(
- 'role' => 'alert',
- 'data-test' => -1,
- ),
- ),
- 'expected' => '
A notice with multiple additional attributes.
',
- ),
- 'data attribute with unsafe value' => array(
- 'message' => 'A notice with an additional attribute with an unsafe value.',
- 'args' => array(
- 'attributes' => array( 'data-unsafe' => '' ),
- ),
- 'expected' => '
A notice with an additional attribute with an unsafe value.
',
- ),
- 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array(
- 'message' => 'A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.',
- 'args' => array(
- 'attributes' => array(
- 'role' => 'alert',
- 'disabled' => 'disabled',
- 'data-name' => 'my-name',
- 'data-id' => 1,
- 'hidden',
- ),
- ),
- 'expected' => '
A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.
',
- ),
- 'paragraph wrapping as a falsy value rather than (bool) false' => array(
- 'message' => 'A notice with paragraph wrapping as a falsy value rather than (bool) false.',
- 'args' => array(
- 'paragraph_wrap' => 0,
- ),
- 'expected' => '
A notice with paragraph wrapping as a falsy value rather than (bool) false.
',
- ),
- );
- }
-
- /**
- * Tests that `wp_get_admin_notice()` throws a `_doing_it_wrong()` when
- * a 'type' containing spaces is passed.
- *
- * @ticket 57791
- *
- * @expectedIncorrectUsage wp_get_admin_notice
- */
- public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() {
- $this->assertSame(
- '
A type containing spaces.
',
- wp_get_admin_notice(
- 'A type containing spaces.',
- array( 'type' => 'first second third fourth' )
- )
- );
- }
-
- /**
- * Tests that `wp_get_admin_notice()` applies filters.
- *
- * @ticket 57791
- *
- * @dataProvider data_should_apply_filters
- *
- * @param string $hook_name The name of the filter hook.
- */
- public function test_should_apply_filters( $hook_name ) {
- $filter = new MockAction();
- add_filter( $hook_name, array( $filter, 'filter' ) );
-
- wp_get_admin_notice( 'A notice.', array( 'type' => 'success' ) );
-
- $this->assertSame( 1, $filter->get_call_count() );
- }
-
- /**
- * Data provider.
- *
- * @return array[]
- */
- public function data_should_apply_filters() {
- return array(
- 'wp_admin_notice_args' => array( 'hook_name' => 'wp_admin_notice_args' ),
- 'wp_admin_notice_markup' => array( 'hook_name' => 'wp_admin_notice_markup' ),
- );
- }
-}
+assertSame( $expected, wp_get_admin_notice( $message, $args ) );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_should_return_admin_notice() {
+ return array(
+ 'defaults' => array(
+ 'message' => 'A notice with defaults.',
+ 'args' => array(),
+ 'expected' => '
',
+ ),
+ 'an empty message (used for templates)' => array(
+ 'message' => '',
+ 'args' => array(
+ 'type' => 'error',
+ 'dismissible' => true,
+ 'id' => 'message',
+ 'additional_classes' => array( 'inline', 'hidden' ),
+ ),
+ 'expected' => '
',
+ ),
+ 'an empty message (used for templates) without paragraph wrapping' => array(
+ 'message' => '',
+ 'args' => array(
+ 'type' => 'error',
+ 'dismissible' => true,
+ 'id' => 'message',
+ 'additional_classes' => array( 'inline', 'hidden' ),
+ 'paragraph_wrap' => false,
+ ),
+ 'expected' => '
',
+ ),
+ 'an "error" notice' => array(
+ 'message' => 'An "error" notice.',
+ 'args' => array(
+ 'type' => 'error',
+ ),
+ 'expected' => '
',
+ ),
+ 'a "success" notice' => array(
+ 'message' => 'A "success" notice.',
+ 'args' => array(
+ 'type' => 'success',
+ ),
+ 'expected' => '
',
+ ),
+ 'a "warning" notice' => array(
+ 'message' => 'A "warning" notice.',
+ 'args' => array(
+ 'type' => 'warning',
+ ),
+ 'expected' => '
',
+ ),
+ 'an "info" notice' => array(
+ 'message' => 'An "info" notice.',
+ 'args' => array(
+ 'type' => 'info',
+ ),
+ 'expected' => '
',
+ ),
+ 'a type that already starts with "notice-"' => array(
+ 'message' => 'A type that already starts with "notice-".',
+ 'args' => array(
+ 'type' => 'notice-info',
+ ),
+ 'expected' => '
A type that already starts with "notice-".
',
+ ),
+ 'a dismissible notice' => array(
+ 'message' => 'A dismissible notice.',
+ 'args' => array(
+ 'dismissible' => true,
+ ),
+ 'expected' => '
',
+ ),
+ 'no type and an ID' => array(
+ 'message' => 'A notice with an ID.',
+ 'args' => array(
+ 'id' => 'message',
+ ),
+ 'expected' => '
',
+ ),
+ 'a type and an ID' => array(
+ 'message' => 'A warning notice with an ID.',
+ 'args' => array(
+ 'type' => 'warning',
+ 'id' => 'message',
+ ),
+ 'expected' => '
A warning notice with an ID.
',
+ ),
+ 'no type and additional classes' => array(
+ 'message' => 'A notice with additional classes.',
+ 'args' => array(
+ 'additional_classes' => array( 'error', 'notice-alt' ),
+ ),
+ 'expected' => '
A notice with additional classes.
',
+ ),
+ 'a type and additional classes' => array(
+ 'message' => 'A warning notice with additional classes.',
+ 'args' => array(
+ 'type' => 'warning',
+ 'additional_classes' => array( 'error', 'notice-alt' ),
+ ),
+ 'expected' => '
A warning notice with additional classes.
',
+ ),
+ 'a dismissible notice with a type and additional classes' => array(
+ 'message' => 'A dismissible warning notice with a type and additional classes.',
+ 'args' => array(
+ 'type' => 'warning',
+ 'dismissible' => true,
+ 'additional_classes' => array( 'error', 'notice-alt' ),
+ ),
+ 'expected' => '
A dismissible warning notice with a type and additional classes.
',
+ ),
+ 'a notice without paragraph wrapping' => array(
+ 'message' => '
A notice without paragraph wrapping.',
+ 'args' => array(
+ 'paragraph_wrap' => false,
+ ),
+ 'expected' => '
A notice without paragraph wrapping.
',
+ ),
+ 'an unsafe type' => array(
+ 'message' => 'A notice with an unsafe type.',
+ 'args' => array(
+ 'type' => '">',
+ ),
+ 'expected' => '
">
A notice with an unsafe type.
',
+ ),
+ 'an unsafe ID' => array(
+ 'message' => 'A notice with an unsafe ID.',
+ 'args' => array(
+ 'id' => '">
A notice with an unsafe ID.
',
+ ),
+ 'unsafe additional classes' => array(
+ 'message' => 'A notice with unsafe additional classes.',
+ 'args' => array(
+ 'additional_classes' => array( '">
A notice with unsafe additional classes.
',
+ ),
+ 'a type that is not a string' => array(
+ 'message' => 'A notice with a type that is not a string.',
+ 'args' => array(
+ 'type' => array(),
+ ),
+ 'expected' => '
A notice with a type that is not a string.
',
+ ),
+ 'a type with only empty space' => array(
+ 'message' => 'A notice with a type with only empty space.',
+ 'args' => array(
+ 'type' => " \t\r\n",
+ ),
+ 'expected' => '
A notice with a type with only empty space.
',
+ ),
+ 'an ID that is not a string' => array(
+ 'message' => 'A notice with an ID that is not a string.',
+ 'args' => array(
+ 'id' => array( 'message' ),
+ ),
+ 'expected' => '
A notice with an ID that is not a string.
',
+ ),
+ 'an ID with only empty space' => array(
+ 'message' => 'A notice with an ID with only empty space.',
+ 'args' => array(
+ 'id' => " \t\r\n",
+ ),
+ 'expected' => '
A notice with an ID with only empty space.
',
+ ),
+ 'dismissible as a truthy value rather than (bool) true' => array(
+ 'message' => 'A notice with dismissible as a truthy value rather than (bool) true.',
+ 'args' => array(
+ 'dismissible' => 1,
+ ),
+ 'expected' => '
A notice with dismissible as a truthy value rather than (bool) true.
',
+ ),
+ 'additional classes that are not an array' => array(
+ 'message' => 'A notice with additional classes that are not an array.',
+ 'args' => array(
+ 'additional_classes' => 'class-1 class-2 class-3',
+ ),
+ 'expected' => '
A notice with additional classes that are not an array.
',
+ ),
+ 'additional attribute with a value' => array(
+ 'message' => 'A notice with an additional attribute with a value.',
+ 'args' => array(
+ 'attributes' => array( 'aria-live' => 'assertive' ),
+ ),
+ 'expected' => '
A notice with an additional attribute with a value.
',
+ ),
+ 'additional hidden attribute' => array(
+ 'message' => 'A notice with the hidden attribute.',
+ 'args' => array(
+ 'attributes' => array( 'hidden' => true ),
+ ),
+ 'expected' => '
A notice with the hidden attribute.
',
+ ),
+ 'additional attribute no associative keys' => array(
+ 'message' => 'A notice with a boolean attribute without an associative key.',
+ 'args' => array(
+ 'attributes' => array( 'hidden' ),
+ ),
+ 'expected' => '
A notice with a boolean attribute without an associative key.
',
+ ),
+ 'additional attribute with role' => array(
+ 'message' => 'A notice with an additional attribute role.',
+ 'args' => array(
+ 'attributes' => array( 'role' => 'alert' ),
+ ),
+ 'expected' => '
A notice with an additional attribute role.
',
+ ),
+ 'multiple additional attributes' => array(
+ 'message' => 'A notice with multiple additional attributes.',
+ 'args' => array(
+ 'attributes' => array(
+ 'role' => 'alert',
+ 'data-test' => -1,
+ ),
+ ),
+ 'expected' => '
A notice with multiple additional attributes.
',
+ ),
+ 'data attribute with unsafe value' => array(
+ 'message' => 'A notice with an additional attribute with an unsafe value.',
+ 'args' => array(
+ 'attributes' => array( 'data-unsafe' => '' ),
+ ),
+ 'expected' => '
A notice with an additional attribute with an unsafe value.
',
+ ),
+ 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array(
+ 'message' => 'A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.',
+ 'args' => array(
+ 'attributes' => array(
+ 'role' => 'alert',
+ 'disabled' => 'disabled',
+ 'data-name' => 'my-name',
+ 'data-id' => 1,
+ 'hidden',
+ ),
+ ),
+ 'expected' => '
A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.
',
+ ),
+ 'paragraph wrapping as a falsy value rather than (bool) false' => array(
+ 'message' => 'A notice with paragraph wrapping as a falsy value rather than (bool) false.',
+ 'args' => array(
+ 'paragraph_wrap' => 0,
+ ),
+ 'expected' => '
A notice with paragraph wrapping as a falsy value rather than (bool) false.
',
+ ),
+ 'a notice that should be dismissed permanently' => array(
+ 'message' => 'A notice that should be dismissed permanently.',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-permanently',
+ ),
+ ),
+ 'expected' => '
A notice that should be dismissed permanently.
',
+ ),
+ 'a notice that should be dismissed for 30 days' => array(
+ 'message' => 'A notice that should be dismissed for 30 days.',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-for-30-days',
+ 'expiration' => 30 * DAY_IN_SECONDS,
+ ),
+ ),
+ 'expected' => '
A notice that should be dismissed for 30 days.
',
+ ),
+ );
+ }
+
+ /**
+ * Tests that `wp_get_admin_notice()` throws a `_doing_it_wrong()` when
+ * a 'type' containing spaces is passed.
+ *
+ * @ticket 57791
+ *
+ * @expectedIncorrectUsage wp_get_admin_notice
+ */
+ public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() {
+ $this->assertSame(
+ '
A type containing spaces.
',
+ wp_get_admin_notice(
+ 'A type containing spaces.',
+ array( 'type' => 'first second third fourth' )
+ )
+ );
+ }
+
+ /**
+ * Tests that `wp_get_admin_notice()` applies filters.
+ *
+ * @ticket 57791
+ *
+ * @dataProvider data_should_apply_filters
+ *
+ * @param string $hook_name The name of the filter hook.
+ */
+ public function test_should_apply_filters( $hook_name ) {
+ $filter = new MockAction();
+ add_filter( $hook_name, array( $filter, 'filter' ) );
+
+ wp_get_admin_notice( 'A notice.', array( 'type' => 'success' ) );
+
+ $this->assertSame( 1, $filter->get_call_count() );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_should_apply_filters() {
+ return array(
+ 'wp_admin_notice_args' => array( 'hook_name' => 'wp_admin_notice_args' ),
+ 'wp_admin_notice_markup' => array( 'hook_name' => 'wp_admin_notice_markup' ),
+ );
+ }
+
+ /**
+ * Tests that `wp_get_admin_notice()` returns an empty string for a notice that is still dismissed.
+ *
+ * @ticket
+ *
+ * @dataProvider data_notices_with_dismissible_array
+ *
+ * @param array $dismissible The value for the dismissible array.
+ */
+ public function test_should_return_empty_string_for_a_notice_that_is_still_dismissed( $dismissible ) {
+ // The notice is still dismissed.
+ set_site_transient( 'wp_admin_notice_dismissed_' . $dismissible['slug'], 1 );
+
+ $this->assertSame(
+ '',
+ wp_get_admin_notice(
+ 'A notice that is still dismissed.',
+ array(
+ 'dismissible' => $dismissible,
+ )
+ )
+ );
+ }
+
+ /**
+ * Tests that `wp_get_admin_notice()` does not apply markup filters for a notice that is still dismissed.
+ *
+ * @ticket
+ *
+ * @dataProvider data_notices_with_dismissible_array
+ *
+ * @param array $dismissible The value for the dismissible array.
+ */
+ public function test_should_not_apply_markup_filters_for_a_notice_that_is_still_dismissed( $dismissible ) {
+ $filter = new MockAction();
+ add_filter( 'wp_admin_notice_markup', array( $filter, 'filter' ) );
+
+ // The notice is still dismissed.
+ set_site_transient( 'wp_admin_notice_dismissed_' . $dismissible['slug'], 1 );
+
+ wp_get_admin_notice(
+ 'A notice that is still dismissed.',
+ array(
+ 'dismissible' => $dismissible,
+ )
+ );
+
+ $this->assertSame( 0, $filter->get_call_count() );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_notices_with_dismissible_array() {
+ return array(
+ 'a permanently dismissed notice (slug only, no expiration provided)' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-forever',
+ ),
+ ),
+ 'a notice dismissed for 30 days' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-dismiss-for-30-days',
+ 'expiration' => 30 * DAY_IN_SECONDS,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Tests that `wp_get_admin_notice()` triggers an error.
+ *
+ * @ticket
+ *
+ * @dataProvider data_should_trigger_error_for_an_invalid_dismissible_slug
+ * @dataProvider data_should_trigger_error_for_invalid_dismissible_expiration
+ *
+ * @param string $message The message.
+ * @param array $args Arguments for the admin notice.
+ * @param string $expected_markup The expected admin notice markup.
+ * @param string $expected_error The expected error message.
+ */
+ public function test_should_trigger_error( $message, $args, $expected_markup, $expected_error ) {
+ // Ensure no previous errors exist.
+ error_clear_last();
+
+ // Backup the error reporting value.
+ $original_error_reporting = error_reporting();
+
+ // Suppress E_USER_NOTICE.
+ error_reporting( E_ALL & ~E_USER_NOTICE );
+
+ $actual = wp_get_admin_notice( $message, $args );
+ $last_error = error_get_last();
+
+ // Reset error reporting.
+ error_reporting( $original_error_reporting );
+
+ $this->assertSame( $expected_markup, $actual );
+ $this->assertIsArray( $last_error, 'An error was not triggered.' );
+ $this->assertSame( E_USER_NOTICE, $last_error['type'], 'The error was not a notice.' );
+ $this->assertSame( $last_error['message'], 'wp_get_admin_notice(): ' . $expected_error, 'The wrong error message was sent.' );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_should_trigger_error_for_an_invalid_dismissible_slug() {
+ return array(
+ 'an empty "dismissible" array' => array(
+ 'message' => 'an empty "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(),
+ ),
+ 'expected_markup' => '
an empty "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'no "slug" key in the "dismissible" array' => array(
+ 'message' => 'no "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'expiration' => 30 * DAY_IN_SECONDS ),
+ ),
+ 'expected_markup' => '
no "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a NULL "slug" key in the "dismissible" array' => array(
+ 'message' => 'a NULL "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => null ),
+ ),
+ 'expected_markup' => '
a NULL "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a (bool) false "slug" key in the "dismissible" array' => array(
+ 'message' => 'a (bool) false "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => false ),
+ ),
+ 'expected_markup' => '
a (bool) false "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a (bool) true "slug" key in the "dismissible" array' => array(
+ 'message' => 'a (bool) true "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => true ),
+ ),
+ 'expected_markup' => '
a (bool) true "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an integer "slug" key in the "dismissible" array' => array(
+ 'message' => 'an integer "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => 1234 ),
+ ),
+ 'expected_markup' => '
an integer "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a float "slug" key in the "dismissible" array' => array(
+ 'message' => 'a float "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => 12.34 ),
+ ),
+ 'expected_markup' => '
a float "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an empty array "slug" key in the "dismissible" array' => array(
+ 'message' => 'an empty array "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => array() ),
+ ),
+ 'expected_markup' => '
an empty array "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'a populated array "slug" key in the "dismissible" array' => array(
+ 'message' => 'a populated array "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => array( 'mynotice-dismiss-forever' ) ),
+ ),
+ 'expected_markup' => '
a populated array "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an object "slug" key in the "dismissible" array' => array(
+ 'message' => 'an object "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => new stdClass() ),
+ ),
+ 'expected_markup' => '
an object "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a string.',
+ ),
+ 'an empty string "slug" key in the "dismissible" array' => array(
+ 'message' => 'an empty string "slug" key in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => '' ),
+ ),
+ 'expected_markup' => '
an empty string "slug" key in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a non-empty string.',
+ ),
+ 'a "slug" key containing only space in the "dismissible" array' => array(
+ 'message' => 'a "slug" key containing only space in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array( 'slug' => " \r\t\n" ),
+ ),
+ 'expected_markup' => '
a "slug" key containing only space in the "dismissible" array
',
+ 'expected_error' => 'The "slug" key in the "dismissible" array must be a non-empty string.',
+ ),
+ );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_should_trigger_error_for_invalid_dismissible_expiration() {
+ return array(
+ 'a NULL "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a null "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-null-expiration',
+ 'expiration' => null,
+ ),
+ ),
+ 'expected_markup' => '
a null "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a (bool) false "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a (bool) false "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-false-expiration',
+ 'expiration' => false,
+ ),
+ ),
+ 'expected_markup' => '
a (bool) false "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a (bool) true "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a (bool) true "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-true-expiration',
+ 'expiration' => true,
+ ),
+ ),
+ 'expected_markup' => '
a (bool) true "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'an empty array "expiration" value in the "dismissible" array' => array(
+ 'message' => 'an empty array "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-empty-array-expiration',
+ 'expiration' => array(),
+ ),
+ ),
+ 'expected_markup' => '
an empty array "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a populated array "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a populated array "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-populated-array-expiration',
+ 'expiration' => array( 30 * DAY_IN_SECONDS ),
+ ),
+ ),
+ 'expected_markup' => '
a populated array "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'an object "expiration" value in the "dismissible" array' => array(
+ 'message' => 'an object "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-object-expiration',
+ 'expiration' => array( 30 * DAY_IN_SECONDS ),
+ ),
+ ),
+ 'expected_markup' => '
an object "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a float "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a float "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-float-expiration',
+ 'expiration' => 30.0,
+ ),
+ ),
+ 'expected_markup' => '
a float "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a numeric string "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a numeric string "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-numeric-string-expiration',
+ 'expiration' => '30',
+ ),
+ ),
+ 'expected_markup' => '
a numeric string "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a NAN "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a NAN "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-nan-expiration',
+ 'expiration' => NAN,
+ ),
+ ),
+ 'expected_markup' => '
a NAN "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'an INF "expiration" value in the "dismissible" array' => array(
+ 'message' => 'an INF "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-inf-expiration',
+ 'expiration' => INF,
+ ),
+ ),
+ 'expected_markup' => '
an INF "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be an integer.',
+ ),
+ 'a negative "expiration" value in the "dismissible" array' => array(
+ 'message' => 'a negative "expiration" value in the "dismissible" array',
+ 'args' => array(
+ 'dismissible' => array(
+ 'slug' => 'mynotice-negative-expiration',
+ 'expiration' => -1,
+ ),
+ ),
+ 'expected_markup' => '
a negative "expiration" value in the "dismissible" array
',
+ 'expected_error' => 'The "expiration" key in the "dismissible" array must be greater than or equal to 0.',
+ ),
+ );
+ }
+}