Skip to content

Commit 75b1c85

Browse files
committed
Fix tests.
1 parent 7517f0c commit 75b1c85

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

tests/phpunit/tests/collaboration/wpCollaborationTableStorage.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function test_get_updates_after_cursor_drops_malformed_json() {
290290
* @ticket 64696
291291
*/
292292
public function test_duplicate_awareness_rows_coalesces_on_latest_row() {
293-
if ( ! wp_using_ext_object_cache() ) {
293+
if ( wp_using_ext_object_cache() ) {
294294
$this->markTestSkipped( 'This test requires that an external object cache is not in use.' );
295295
}
296296

@@ -328,10 +328,54 @@ public function test_duplicate_awareness_rows_coalesces_on_latest_row() {
328328
wp_cache_flush();
329329
$awareness = $storage->get_awareness_state( $room );
330330
$this->assertCount( 1, $awareness, 'Only one awareness state should be returned for the client.' );
331-
$this->assertSame( array( 'name' => 'Latest' ), $awareness[0] );
331+
$this->assertSame( array( 'name' => 'Latest' ), $awareness[0]['state'] );
332+
$storage->set_awareness_state( $room, '1', array( 'name' => 'Current' ), 1 );
333+
$awareness = $storage->get_awareness_state( $room );
334+
$this->assertCount( 1, $awareness, 'Only one awareness state should be returned for the client.' );
335+
$this->assertSame( array( 'name' => 'Current' ), $awareness[0]['state'] );
336+
}
337+
338+
339+
/**
340+
* Ensure awareness getter returns the last client entry when duplicates exist.
341+
*
342+
* @ticket 64696
343+
*/
344+
public function test_duplicate_awareness_rows_coalesces_on_latest_entry_with_object_cache() {
345+
if ( ! wp_using_ext_object_cache() ) {
346+
$this->markTestSkipped( 'This test requires that an external object cache is in use.' );
347+
}
348+
349+
global $wpdb;
350+
351+
$storage = new WP_Collaboration_Table_Storage();
352+
$room = __FUNCTION__;
353+
354+
wp_cache_set(
355+
'awareness::' . $room,
356+
array(
357+
array(
358+
'client_id' => '1',
359+
'state' => array( 'name' => 'Cached Stale' ),
360+
'timestamp' => time(),
361+
),
362+
array(
363+
'client_id' => '1',
364+
'state' => array( 'name' => 'Cached Latest' ),
365+
'timestamp' => time(),
366+
),
367+
),
368+
'collaboration',
369+
HOUR_IN_SECONDS
370+
);
371+
372+
// get_awareness_state and set_awareness_state should target the latest row.
373+
$awareness = $storage->get_awareness_state( $room );
374+
$this->assertCount( 1, $awareness, 'Only one awareness state should be returned for the client.' );
375+
$this->assertSame( array( 'name' => 'Latest' ), $awareness[0]['state'] );
332376
$storage->set_awareness_state( $room, '1', array( 'name' => 'Current' ), 1 );
333377
$awareness = $storage->get_awareness_state( $room );
334378
$this->assertCount( 1, $awareness, 'Only one awareness state should be returned for the client.' );
335-
$this->assertSame( array( 'name' => 'Current' ), $awareness[0] );
379+
$this->assertSame( array( 'name' => 'Current' ), $awareness[0]['state'] );
336380
}
337381
}

0 commit comments

Comments
 (0)