Skip to content

Commit e9f492b

Browse files
committed
Collaboration: Bump db_version and add deprecated route test
Increment $wp_db_version from 61833 to 61834 so the upgrade_700() routine triggers dbDelta() for the new collaboration table. Add a PHPUnit test covering the backward-compatible wp-sync/v1 route alias, including a $_namespace parameter on the dispatch_collaboration helper.
1 parent 344d24d commit e9f492b

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

src/wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @global int $wp_db_version
2525
*/
26-
$wp_db_version = 61833;
26+
$wp_db_version = 61834;
2727

2828
/**
2929
* Holds the TinyMCE version.

tests/phpunit/tests/rest-api/rest-collaboration-server.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ private function build_room( $room, $client_id = '1', $cursor = 0, $awareness =
6161
/**
6262
* Dispatches a collaboration request with the given rooms.
6363
*
64-
* @param array $rooms Array of room request data.
64+
* @param array $rooms Array of room request data.
65+
* @param string $_namespace REST namespace to dispatch against.
6566
* @return WP_REST_Response Response object.
6667
*/
67-
private function dispatch_collaboration( $rooms ) {
68-
$request = new WP_REST_Request( 'POST', '/wp-collaboration/v1/updates' );
68+
private function dispatch_collaboration( $rooms, $_namespace = 'wp-collaboration/v1' ) {
69+
$request = new WP_REST_Request( 'POST', '/' . $_namespace . '/updates' );
6970
$request->set_body_params( array( 'rooms' => $rooms ) );
7071
return rest_get_server()->dispatch( $request );
7172
}
@@ -1674,6 +1675,53 @@ public function test_collaboration_null_awareness_skips_write() {
16741675
* Query count tests.
16751676
*/
16761677

1678+
/*
1679+
* Deprecated route tests.
1680+
*/
1681+
1682+
/**
1683+
* Verifies the deprecated wp-sync/v1 route alias works identically to
1684+
* the canonical wp-collaboration/v1 namespace.
1685+
*
1686+
* @ticket 64696
1687+
*/
1688+
public function test_collaboration_deprecated_sync_route() {
1689+
wp_set_current_user( self::$editor_id );
1690+
1691+
$room = $this->get_post_room();
1692+
$update = array(
1693+
'type' => 'update',
1694+
'data' => 'c3luYyByb3V0ZQ==',
1695+
);
1696+
1697+
// Send an update via the deprecated namespace.
1698+
$response = $this->dispatch_collaboration(
1699+
array(
1700+
$this->build_room( $room, '1', 0, array( 'user' => 'client1' ), array( $update ) ),
1701+
),
1702+
'wp-sync/v1'
1703+
);
1704+
1705+
$this->assertSame( 200, $response->get_status(), 'Deprecated wp-sync/v1 route should return 200.' );
1706+
1707+
$data = $response->get_data();
1708+
$this->assertArrayHasKey( 'rooms', $data, 'Response should contain rooms key.' );
1709+
$this->assertSame( $room, $data['rooms'][0]['room'], 'Room identifier should match.' );
1710+
1711+
// Verify the update is retrievable via the canonical namespace.
1712+
$response2 = $this->dispatch_collaboration(
1713+
array(
1714+
$this->build_room( $room, '2', 0 ),
1715+
)
1716+
);
1717+
1718+
$updates = $response2->get_data()['rooms'][0]['updates'];
1719+
$this->assertNotEmpty( $updates, 'Update sent via deprecated route should be retrievable via canonical route.' );
1720+
1721+
$update_data = wp_list_pluck( $updates, 'data' );
1722+
$this->assertContains( 'c3luYyByb3V0ZQ==', $update_data );
1723+
}
1724+
16771725
/**
16781726
* An idle poll (no new updates) should use at most 4 queries per room:
16791727
* 1. SELECT … FROM collaboration WHERE type = 'awareness' (read + ownership check)

0 commit comments

Comments
 (0)