Skip to content

Commit 3a3fdda

Browse files
authored
NodeInfo: Make sure usage data has correct format (#1667)
1 parent 2440d58 commit 3a3fdda

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
NodeInfo endpoint response now correctly formats `localPosts` values.

includes/rest/class-nodeinfo-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function get_version_2_0() {
159159
'activeHalfyear' => get_active_users( 6 ),
160160
'activeMonth' => get_active_users(),
161161
),
162-
'localPosts' => $posts->publish,
162+
'localPosts' => (int) $posts->publish,
163163
'localComments' => $comments->approved,
164164
),
165165
'metadata' => array(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public function test_get_items() {
7373
* @covers ::get_version_2_0
7474
*/
7575
public function test_get_item() {
76+
self::factory()->post->create();
77+
self::factory()->comment->create();
78+
7679
$request = new \WP_REST_Request( 'GET', '/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo/2.0' );
7780
$response = \rest_get_server()->dispatch( $request );
7881
$data = $response->get_data();
@@ -85,8 +88,9 @@ public function test_get_item() {
8588
$this->assertEquals( array( 'activitypub' ), $data['protocols'] );
8689
$this->assertArrayHasKey( 'services', $data );
8790
$this->assertEquals( (bool) \get_option( 'users_can_register' ), $data['openRegistrations'] );
88-
$this->assertArrayHasKey( 'usage', $data );
89-
$this->assertArrayHasKey( 'metadata', $data );
91+
$this->assertIsInt( $data['usage']['localPosts'] );
92+
$this->assertIsInt( $data['usage']['localComments'] );
93+
$this->assertSame( \get_bloginfo( 'name' ), $data['metadata']['nodeName'] );
9094
}
9195

9296
/**

0 commit comments

Comments
 (0)