Skip to content

Commit 4c0f763

Browse files
committed
Object ID tests.
1 parent 121caea commit 4c0f763

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ public function test_collaboration_client_id_integer_coercion(): void {
504504
*
505505
* @ticket 64696
506506
*/
507-
public function test_collaboration_client_id_accepts_string_at_max_length(): void {
507+
public function test_collaboration_client_id_accepts_numeric_string_at_max_length(): void {
508508
wp_set_current_user( self::$editor_id );
509509

510-
$client_id = str_repeat( 'a', 32 );
510+
$client_id = str_repeat( '1', 32 );
511511
$this->assertSame( 32, strlen( $client_id ), 'Client ID should be 32 characters.' );
512512

513513
$rooms = array( $this->build_room( $this->get_post_room(), $client_id ) );
@@ -521,10 +521,10 @@ public function test_collaboration_client_id_accepts_string_at_max_length(): voi
521521
*
522522
* @ticket 64696
523523
*/
524-
public function test_collaboration_client_id_rejects_string_over_max_length(): void {
524+
public function test_collaboration_client_id_rejects_numeric_string_over_max_length(): void {
525525
wp_set_current_user( self::$editor_id );
526526

527-
$client_id = str_repeat( 'a', 33 );
527+
$client_id = str_repeat( '1', 33 );
528528
$this->assertSame( 33, strlen( $client_id ), 'Client ID should be 33 characters.' );
529529

530530
$rooms = array( $this->build_room( $this->get_post_room(), $client_id ) );
@@ -2694,17 +2694,33 @@ public function test_collaboration_too_many_rooms_rejected(): void {
26942694
* Verifies that a non-numeric object ID in a room name is rejected.
26952695
*
26962696
* @ticket 64696
2697+
*
2698+
* @dataProvider data_collaboration_invalid_object_id_rejected
26972699
*/
2698-
public function test_collaboration_non_numeric_object_id_rejected(): void {
2700+
public function test_collaboration_invalid_object_id_rejected( $object_id ): void {
26992701
wp_set_current_user( self::$editor_id );
27002702

27012703
$response = $this->dispatch_collaboration(
27022704
array(
2703-
$this->build_room( 'postType/post:abc' ),
2705+
$this->build_room( "postType/post:{$object_id}" ),
27042706
)
27052707
);
27062708

2707-
$this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
2709+
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
2710+
}
2711+
2712+
/**
2713+
* Data provider for invalid test_collaboration_invalid_object_id_rejected.
2714+
*
2715+
* @return string[][]
2716+
*/
2717+
public function data_collaboration_invalid_object_id_rejected(): array {
2718+
return array(
2719+
'non-numeric' => array( 'abc' ),
2720+
'negative' => array( '-1' ),
2721+
'zero' => array( '0' ),
2722+
'float' => array( '3.14' ),
2723+
);
27082724
}
27092725

27102726
/**

0 commit comments

Comments
 (0)