Merge code paths in assertTemplateData() helper method

This streamlines the code of the helper method a bit, mostly by
avoiding duplication.

What actually happens is the exact same as before, with one
exception: When a test case doesn't have an expected "output",
the default (mostly empty) output does not run through the
roundtrip test. While doing this is not wrong, it doesn't tell
us anything about the specific test case.

Change-Id: I4a3d8a22c3dd6a9c5c3766195e5aef3cf37a6441
This commit is contained in:
Thiemo Kreuz 2021-08-28 12:35:15 +02:00
parent da75004c11
commit d253fa4e28

View file

@ -628,61 +628,38 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
if ( !isset( $case['msg'] ) ) {
$case['msg'] = is_string( $case['status'] ) ? $case['status'] : 'TemplateData assertion';
}
if ( !isset( $case['output'] ) ) {
if ( is_string( $case['status'] ) ) {
$case['output'] = '{
"description": null,
"params": {},
"sets": [],
"maps": {},
"format": null
}';
} else {
$case['output'] = $case['input'];
}
}
$t = TemplateDataBlob::newFromJSON( $this->db, $case['input'] );
$actual = $t->getJSON();
$status = $t->getStatus();
if ( !$status->isGood() ) {
$this->assertSame(
$case['status'],
self::getStatusText( $status ),
'Status: ' . $case['msg']
);
$this->assertSame(
$case['status'],
is_string( $case['status'] ) ? self::getStatusText( $status ) : $status->isGood(),
'Status: ' . $case['msg']
);
if ( !isset( $case['output'] ) ) {
$expected = is_string( $case['status'] )
? '{ "description": null, "params": {}, "sets": [], "maps": {}, "format": null }'
: $case['input'];
$this->assertStrictJsonEquals( $expected, $actual, $case['msg'] );
} else {
$this->assertSame(
$case['status'],
$status->isGood(),
'Status: ' . $case['msg']
$this->assertStrictJsonEquals( $case['output'], $actual, $case['msg'] );
// Assert this case roundtrips properly by running through the output as input.
$t = TemplateDataBlob::newFromJSON( $this->db, $case['output'] );
$status = $t->getStatus();
if ( !$status->isGood() ) {
$this->assertSame( $case['status'], self::getStatusText( $status ),
'Roundtrip status: ' . $case['msg']
);
}
$this->assertStrictJsonEquals( $case['output'], $t->getJSON(),
'Roundtrip: ' . $case['msg']
);
}
$this->assertStrictJsonEquals(
$case['output'],
$actual,
$case['msg']
);
// Assert this case roundtrips properly by running through the output as input.
$t = TemplateDataBlob::newFromJSON( $this->db, $case['output'] );
$status = $t->getStatus();
if ( !$status->isGood() ) {
$this->assertSame(
$case['status'],
self::getStatusText( $status ),
'Roundtrip status: ' . $case['msg']
);
}
$this->assertStrictJsonEquals(
$case['output'],
$t->getJSON(),
'Roundtrip: ' . $case['msg']
);
}
/**