user->create( array( 'role' => 'administrator' ) );
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
self::$contributor_id = $factory->user->create( array( 'role' => 'contributor' ) );
self::$subscriber_id = $factory->user->create( array( 'role' => 'subscriber' ) );
}
public static function wpTearDownAfterClass() {
self::delete_user( self::$admin_id );
self::delete_user( self::$editor_id );
self::delete_user( self::$contributor_id );
self::delete_user( self::$subscriber_id );
}
public function set_up() {
parent::set_up();
$collections = array(
'test-public' => true,
'test-private' => false,
);
foreach ( $collections as $slug => $is_public ) {
wp_register_icon_collection(
$slug,
array(
'label' => $slug,
'public' => $is_public,
)
);
wp_register_icon(
$slug . '/visibility-icon',
array(
'label' => 'Visibility Icon',
'content' => '',
)
);
}
}
public function tear_down() {
wp_unregister_icon_collection( 'test-public' );
wp_unregister_icon_collection( 'test-private' );
parent::tear_down();
}
/**
* Test that GET /wp/v2/icons returns a list of icons for users with edit_posts capability.
*/
public function test_get_items_returns_icons_list() {
wp_set_current_user( self::$editor_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/icons' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$this->assertSame( 200, $response->get_status() );
$this->assertIsArray( $data );
$this->assertNotEmpty( $data, 'Icon registry should contain at least one icon' );
// Check structure of first icon
$icon = $data[0];
$this->assertArrayHasKey( 'name', $icon );
$this->assertArrayHasKey( 'content', $icon );
$this->assertIsString( $icon['name'] );
$this->assertIsString( $icon['content'] );
$this->assertStringStartsWith( '