@@ -94,8 +94,11 @@ public function test_collaboration_storage_set_awareness_rejects_empty_client_id
9494 $ result = $ storage ->set_awareness_state ( 'postType/post:1 ' , '' , array ( 'user ' => 'test ' ), 1 );
9595 $ this ->assertFalse ( $ result , 'set_awareness_state should reject an empty client_id. ' );
9696 }
97+
9798 /**
9899 * Ensure awareness updates are not stored in the DB for sites using a persistent cache.
100+ *
101+ * @ticket 64696
99102 */
100103 public function test_awareness_uses_persistent_object_cache () {
101104 if ( ! wp_using_ext_object_cache () ) {
@@ -113,6 +116,8 @@ public function test_awareness_uses_persistent_object_cache() {
113116
114117 /**
115118 * Ensure awareness retrieval uses in-memory cache within a single request, even when a persistent cache is in use.
119+ *
120+ * @ticket 64696
116121 */
117122 public function test_awareness_uses_in_memory_cache () {
118123 if ( wp_using_ext_object_cache () ) {
@@ -142,6 +147,8 @@ public function test_awareness_uses_in_memory_cache() {
142147
143148 /**
144149 * Ensure adding subsequent client does not remove existing clients from room.
150+ *
151+ * @ticket 64696
145152 */
146153 public function test_awareness_updates_for_multiple_users () {
147154 $ storage = new WP_Collaboration_Table_Storage ();
@@ -158,10 +165,13 @@ public function test_awareness_updates_for_multiple_users() {
158165
159166 $ this ->assertContains ( 'client-1 ' , $ clients , 'Client 1 should be present in awareness state. ' );
160167 $ this ->assertContains ( 'client-2 ' , $ clients , 'Client 2 should be present in awareness state. ' );
168+ $ this ->assertCount ( 2 , $ awareness , 'There should be two clients present in awareness state. ' );
161169 }
162170
163171 /**
164172 * Ensure awareness does not include out of date clients from cached results.
173+ *
174+ * @ticket 64696
165175 */
166176 public function test_awareness_excludes_expired_clients_from_cached_results () {
167177 $ storage = new WP_Collaboration_Table_Storage ();
@@ -188,4 +198,34 @@ public function test_awareness_excludes_expired_clients_from_cached_results() {
188198 $ this ->assertContains ( 'client-2 ' , $ clients , 'Active client should be present in awareness state. ' );
189199 $ this ->assertCount ( 1 , $ awareness , 'Only one active client should be present in awareness state. ' );
190200 }
201+
202+ /**
203+ * Ensure awareness getter returns data of the correct shape.
204+ *
205+ * @ticket 64696
206+ */
207+ public function test_awareness_getter_is_of_correct_shape () {
208+ $ storage = new WP_Collaboration_Table_Storage ();
209+ $ storage ->set_awareness_state ( 'test-room ' , 'client-1 ' , array ( 'name ' => 'Client 1 ' ), 1 );
210+
211+ $ awareness = $ storage ->get_awareness_state ( 'test-room ' );
212+
213+ $ this ->assertIsArray ( $ awareness , 'Awareness state should be an array. ' );
214+ $ this ->assertCount ( 1 , $ awareness , 'There should be one client state in awareness. ' );
215+ $ this ->assertArrayHasKey ( 0 , $ awareness , 'Awareness state should be an array of client states. ' );
216+
217+ $ expected_keys = array (
218+ 'client_id ' ,
219+ 'state ' ,
220+ 'timestamp ' ,
221+ 'user_id ' ,
222+ );
223+
224+ $ this ->assertSameSets ( $ expected_keys , array_keys ( $ awareness [0 ] ), 'Client state should have expected keys. ' );
225+ $ this ->assertSame ( 'client-1 ' , $ awareness [0 ]['client_id ' ], 'Client ID should match what was set. ' );
226+ $ this ->assertIsArray ( $ awareness [0 ]['state ' ], 'Client state should be an array. ' );
227+ $ this ->assertSame ( 'Client 1 ' , $ awareness [0 ]['state ' ]['name ' ], 'Client state should match what was set. ' );
228+ $ this ->assertIsInt ( $ awareness [0 ]['user_id ' ], 'Client state user_id should be an integer. ' );
229+ $ this ->assertIsInt ( $ awareness [0 ]['timestamp ' ], 'Client state timestamp should be an integer. ' );
230+ }
191231}
0 commit comments