tests: Enforce parity between Gadget::serializeDefinition and toArray

Follows-up 087ab65e24 (Ieae6706537). To avoid silent mistakes such
as during development of T63007 (I7f797e35352b242).

Bug: T303194
Change-Id: If675f8d02ed3fee768af3d2b4912249319ae9ef4
This commit is contained in:
Timo Tijhof 2023-09-20 14:39:45 -07:00
parent 35179b9d7e
commit 5aaa843a28
2 changed files with 36 additions and 29 deletions

View file

@ -116,24 +116,24 @@ class Gadget {
return 'Gadget:' . $page;
};
return [
'name' => $id,
'resourceLoaded' => true,
'requiresES6' => $data['settings']['requiresES6'],
'requiredRights' => $data['settings']['rights'],
'onByDefault' => $data['settings']['default'],
'package' => $data['settings']['package'],
'hidden' => $data['settings']['hidden'],
'targets' => $data['settings']['targets'],
'requiredActions' => $data['settings']['actions'],
'requiredSkins' => $data['settings']['skins'],
'category' => $data['settings']['category'],
'supportsUrlLoad' => $data['settings']['supportsUrlLoad'],
'scripts' => array_map( $prefixGadgetNs, $data['module']['scripts'] ),
'styles' => array_map( $prefixGadgetNs, $data['module']['styles'] ),
'datas' => array_map( $prefixGadgetNs, $data['module']['datas'] ),
'dependencies' => $data['module']['dependencies'],
'peers' => $data['module']['peers'],
'hidden' => $data['settings']['hidden'],
'messages' => $data['module']['messages'],
'name' => $id,
'onByDefault' => $data['settings']['default'],
'package' => $data['settings']['package'],
'peers' => $data['module']['peers'],
'requiredActions' => $data['settings']['actions'],
'requiredRights' => $data['settings']['rights'],
'requiredSkins' => $data['settings']['skins'],
'requiresES6' => $data['settings']['requiresES6'],
'resourceLoaded' => true,
'scripts' => array_map( $prefixGadgetNs, $data['module']['scripts'] ),
'styles' => array_map( $prefixGadgetNs, $data['module']['styles'] ),
'supportsUrlLoad' => $data['settings']['supportsUrlLoad'],
'targets' => $data['settings']['targets'],
'type' => $data['module']['type'],
];
}
@ -144,26 +144,27 @@ class Gadget {
*/
public function toArray(): array {
return [
'name' => $this->name,
'definition' => $this->definition,
'resourceLoaded' => $this->resourceLoaded,
'requiresES6' => $this->requiresES6,
'requiredRights' => $this->requiredRights,
'onByDefault' => $this->onByDefault,
'package' => $this->package,
'hidden' => $this->hidden,
'requiredActions' => $this->requiredActions,
'requiredSkins' => $this->requiredSkins,
'category' => $this->category,
'supportsUrlLoad' => $this->supportsUrlLoad,
'scripts' => $this->scripts,
'styles' => $this->styles,
'datas' => $this->datas,
'dependencies' => $this->dependencies,
'peers' => $this->peers,
'hidden' => $this->hidden,
'messages' => $this->messages,
'type' => $this->type,
'name' => $this->name,
'onByDefault' => $this->onByDefault,
'package' => $this->package,
'peers' => $this->peers,
'requiredActions' => $this->requiredActions,
'requiredRights' => $this->requiredRights,
'requiredSkins' => $this->requiredSkins,
'requiresES6' => $this->requiresES6,
'resourceLoaded' => $this->resourceLoaded,
'scripts' => $this->scripts,
'styles' => $this->styles,
'supportsUrlLoad' => $this->supportsUrlLoad,
'targets' => $this->targets,
'type' => $this->type,
// Legacy (specific to MediaWikiGadgetsDefinitionRepo)
'definition' => $this->definition,
];
}

View file

@ -58,6 +58,12 @@ class GadgetTest extends MediaWikiUnitTestCase {
$this->assertCount( 0, $g->getJSONs() );
$this->assertCount( 1, $g->getDependencies() );
$this->assertCount( 1, $g->getMessages() );
// Ensure parity and internal consistency
// between Gadget::serializeDefinition and Gadget::toArray
$arr = $g->toArray();
unset( $arr['definition'] );
$this->assertSame( $arr, $gArray );
}
/**