Skip to content

Commit ffe95b9

Browse files
committed
Register adapters during Microsub initialization
Adds an 'adapters_registered' flag to prevent duplicate adapter registration and ensures adapters are registered when Microsub is initialized. Updates the REST controller test to verify that core channels are returned, reflecting the new adapter registration behavior.
1 parent 9c7b286 commit ffe95b9

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

includes/class-microsub.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class Microsub {
2828
*/
2929
private $initialized = false;
3030

31+
/**
32+
* Whether adapters have been registered.
33+
*
34+
* @var bool
35+
*/
36+
private $adapters_registered = false;
37+
3138
/**
3239
* Get the instance of the class.
3340
*
@@ -57,6 +64,7 @@ public function init() {
5764
}
5865

5966
$this->register_hooks();
67+
$this->register_adapters();
6068

6169
$this->initialized = true;
6270
}
@@ -89,6 +97,12 @@ public function register_hooks() {
8997
* Register built-in adapters.
9098
*/
9199
public function register_adapters() {
100+
if ( $this->adapters_registered ) {
101+
return;
102+
}
103+
104+
$this->adapters_registered = true;
105+
92106
// Register WordPress core feeds adapter.
93107
$adapter = new Adapters\WordPress();
94108
$adapter->register();

tests/phpunit/includes/class-test-rest-controller.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,22 @@ public function test_register_routes() {
7373
*
7474
* @covers ::get_channels
7575
*/
76-
public function test_get_channels_without_adapter() {
76+
public function test_get_channels_returns_core_channels() {
7777
wp_set_current_user( $this->user_id );
7878

7979
$request = new WP_REST_Request( 'GET', '/microsub/1.0/endpoint' );
8080
$request->set_param( 'action', 'channels' );
8181

8282
$response = $this->server->dispatch( $request );
83+
$data = $response->get_data();
8384

84-
$this->assertEquals( 501, $response->get_status() );
85+
$this->assertEquals( 200, $response->get_status() );
86+
$this->assertArrayHasKey( 'channels', $data );
87+
$this->assertNotEmpty( $data['channels'] );
88+
$this->assertTrue(
89+
in_array( 'wp-dashboard', wp_list_pluck( $data['channels'], 'uid' ), true ),
90+
'Expected WordPress core adapter to add wp-dashboard channel'
91+
);
8592
}
8693

8794
/**

0 commit comments

Comments
 (0)