Skip to content

Commit 4453a6b

Browse files
committed
- added test for get_graphql_admin_notices()
1 parent 44e0170 commit 4453a6b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

access-functions.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,6 @@ static function ( \WPGraphQL\Admin\AdminNotices $admin_notices ) use ( $slug, $c
974974
* @return array|mixed[][] An array of admin notices
975975
*/
976976
function get_graphql_admin_notices() {
977-
978-
if ( ! is_admin() ) {
979-
return [];
980-
}
981-
982977
$admin_notices = \WPGraphQL\Admin\AdminNotices::get_instance();
983978
return $admin_notices->get_admin_notices();
984979
}

tests/wpunit/AdminNoticesTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ public function testAddAndGetAdminNotices(): void {
4848
$this->assertSame($config, $notices[$slug]);
4949
}
5050

51+
/**
52+
* Test adding and retrieving admin notices.
53+
*/
54+
public function testGetAdminNotices(): void {
55+
$adminNotices = AdminNotices::get_instance();
56+
57+
$slug = 'test-notice';
58+
$config = [
59+
'message' => 'Test Notice Message',
60+
'type' => 'warning',
61+
'is_dismissable' => true
62+
];
63+
64+
$adminNotices->add_admin_notice($slug, $config);
65+
66+
$notices = $adminNotices->get_admin_notices();
67+
$this->assertArrayHasKey($slug, $notices);
68+
$this->assertSame($config, $notices[$slug]);
69+
70+
$get_admin_notices = get_graphql_admin_notices();
71+
72+
$this->assertSame($get_admin_notices, $notices);
73+
}
74+
5175
/**
5276
* Test removing admin notices.
5377
*/

0 commit comments

Comments
 (0)