diff options
author | bpirkle <bpirkle@wikimedia.org> | 2024-10-16 12:58:10 -0500 |
---|---|---|
committer | bpirkle <bpirkle@wikimedia.org> | 2024-10-16 12:58:10 -0500 |
commit | 330e1633c260311f705361cf0ddc392e39b1d48c (patch) | |
tree | cf61312d96445b50a97bf2b759b5c307bcf18de6 | |
parent | 1d0075a16d124bf5fbb5a2e3c9b961fc98bf05b4 (diff) | |
download | mediawikicore-330e1633c260311f705361cf0ddc392e39b1d48c.tar.gz mediawikicore-330e1633c260311f705361cf0ddc392e39b1d48c.zip |
REST: Add items wrapper for restbase compat to some response bodies
Bug: T374136
Change-Id: I995916f53eb9408923456cce8b1f3be391fbf942
5 files changed, 23 insertions, 22 deletions
diff --git a/includes/Rest/Handler/PageSourceHandler.php b/includes/Rest/Handler/PageSourceHandler.php index 4ddaf0bbbd18..0429617ffec8 100644 --- a/includes/Rest/Handler/PageSourceHandler.php +++ b/includes/Rest/Handler/PageSourceHandler.php @@ -98,7 +98,7 @@ class PageSourceHandler extends SimpleHandler { $outputMode = $this->getOutputMode(); switch ( $outputMode ) { case 'restbase': // compatibility for restbase migration - $body = $this->contentHelper->constructRestbaseCompatibleMetadata(); + $body = [ 'items' => [ $this->contentHelper->constructRestbaseCompatibleMetadata() ] ]; break; case 'bare': $body = $this->contentHelper->constructMetadata(); diff --git a/includes/Rest/Handler/RevisionSourceHandler.php b/includes/Rest/Handler/RevisionSourceHandler.php index 66e245c2497e..d52879251240 100644 --- a/includes/Rest/Handler/RevisionSourceHandler.php +++ b/includes/Rest/Handler/RevisionSourceHandler.php @@ -54,7 +54,7 @@ class RevisionSourceHandler extends SimpleHandler { $outputMode = $this->getOutputMode(); switch ( $outputMode ) { case 'restbase': // compatibility for restbase migration - $body = $this->contentHelper->constructRestbaseCompatibleMetadata(); + $body = [ 'items' => [ $this->contentHelper->constructRestbaseCompatibleMetadata() ] ]; break; case 'bare': $revisionRecord = $this->contentHelper->getTargetRevision(); diff --git a/tests/api-testing/REST/content.v1/Page.js b/tests/api-testing/REST/content.v1/Page.js index f8ff47105d18..49a103fff2f0 100644 --- a/tests/api-testing/REST/content.v1/Page.js +++ b/tests/api-testing/REST/content.v1/Page.js @@ -194,12 +194,12 @@ describe( 'Page Source', () => { assert.deepEqual( status, 200, text ); assert.match( headers[ 'content-type' ], /^application\/json/ ); assert.match( headers.vary, /\bx-restbase-compat\b/ ); - assert.containsAllKeys( body, [ 'title', 'page_id', 'rev', 'tid', 'namespace', 'user_id', + assert.containsAllKeys( body.items[ 0 ], [ 'title', 'page_id', 'rev', 'tid', 'namespace', 'user_id', 'user_text', 'timestamp', 'comment', 'tags', 'restrictions', 'page_language', 'redirect' ] ); - assert.deepEqual( body.title, utils.dbkey( page ) ); - assert.isAbove( body.page_id, 0 ); - assert.isAbove( body.rev, 0 ); + assert.deepEqual( body.items[ 0 ].title, utils.dbkey( page ) ); + assert.isAbove( body.items[ 0 ].page_id, 0 ); + assert.isAbove( body.items[ 0 ].rev, 0 ); } ); it( 'Should successfully return restbase-compatible errors', async () => { diff --git a/tests/api-testing/REST/content.v1/Revision.js b/tests/api-testing/REST/content.v1/Revision.js index a36ed2139893..fd4de2c888f8 100644 --- a/tests/api-testing/REST/content.v1/Revision.js +++ b/tests/api-testing/REST/content.v1/Revision.js @@ -79,12 +79,12 @@ describe( 'Revision', () => { assert.deepEqual( status, 200, text ); assert.match( headers[ 'content-type' ], /^application\/json/ ); assert.match( headers.vary, /\bx-restbase-compat\b/ ); - assert.containsAllKeys( body, [ 'title', 'page_id', 'rev', 'tid', 'namespace', 'user_id', + assert.containsAllKeys( body.items[ 0 ], [ 'title', 'page_id', 'rev', 'tid', 'namespace', 'user_id', 'user_text', 'timestamp', 'comment', 'tags', 'restrictions', 'page_language', 'redirect' ] ); - assert.deepEqual( body.title, utils.dbkey( page ) ); - assert.deepEqual( body.page_id, pageid ); - assert.deepEqual( body.rev, newrevid ); + assert.deepEqual( body.items[ 0 ].title, utils.dbkey( page ) ); + assert.deepEqual( body.items[ 0 ].page_id, pageid ); + assert.deepEqual( body.items[ 0 ].rev, newrevid ); } ); it( 'Should successfully return restbase-compatible errors', async () => { diff --git a/tests/phpunit/integration/includes/Rest/Handler/PageSourceHandlerTest.php b/tests/phpunit/integration/includes/Rest/Handler/PageSourceHandlerTest.php index 18f178b82027..3a506c6c3e87 100644 --- a/tests/phpunit/integration/includes/Rest/Handler/PageSourceHandlerTest.php +++ b/tests/phpunit/integration/includes/Rest/Handler/PageSourceHandlerTest.php @@ -161,24 +161,25 @@ class PageSourceHandlerTest extends MediaWikiIntegrationTestCase { * @param array $data */ private function assertRestbaseCompatibleResponseData( WikiPage $page, array $data ): void { - $this->assertSame( $page->getTitle()->getPrefixedDBkey(), $data['title'] ); - $this->assertSame( $page->getId(), $data['page_id'] ); - $this->assertSame( $page->getLatest(), $data['rev'] ); - $this->assertSame( $page->getNamespace(), $data['namespace'] ); - $this->assertSame( $page->getUser(), $data['user_id'] ); - $this->assertSame( $page->getUserText(), $data['user_text'] ); + $this->assertArrayHasKey( 'items', $data ); + $this->assertSame( $page->getTitle()->getPrefixedDBkey(), $data['items'][0]['title'] ); + $this->assertSame( $page->getId(), $data['items'][0]['page_id'] ); + $this->assertSame( $page->getLatest(), $data['items'][0]['rev'] ); + $this->assertSame( $page->getNamespace(), $data['items'][0]['namespace'] ); + $this->assertSame( $page->getUser(), $data['items'][0]['user_id'] ); + $this->assertSame( $page->getUserText(), $data['items'][0]['user_text'] ); $this->assertSame( wfTimestampOrNull( TS_ISO_8601, $page->getTimestamp() ), - $data['timestamp'] + $data['items'][0]['timestamp'] ); - $this->assertSame( $page->getComment(), $data['comment'] ); - $this->assertSame( [], $data['tags'] ); - $this->assertSame( [], $data['restrictions'] ); + $this->assertSame( $page->getComment(), $data['items'][0]['comment'] ); + $this->assertSame( [], $data['items'][0]['tags'] ); + $this->assertSame( [], $data['items'][0]['restrictions'] ); $this->assertSame( $page->getTitle()->getPageLanguage()->getCode(), - $data['page_language'] + $data['items'][0]['page_language'] ); - $this->assertSame( $page->isRedirect(), $data['redirect'] ); + $this->assertSame( $page->isRedirect(), $data['items'][0]['redirect'] ); } } |