Follows-up 5e6cccc3a4.
- Let PHPUnit do the diffing instead of exporting expected value
into the description.
- Use a stricter and complete assertion of the result, not just
one key existence only. Specifically, this means the value (true)
is asserted, and any additional or unexpected properties result in
failure. For example, if all of them were marked as missing+invalid
the old test would pass as it wasn't checking absence. In general,
assertArrayHasKey() is almost always indicates a lax test that can
be improved, or a redundant assertion (such as here, where it was
used to check 'purge' exists before use, but PHP and PHPUnit naturally
validate that already).
Change-Id: Ie7067633e4df0b9a1b451ce4c53a98e8ee3c3ae7
40 lines
836 B
PHP
40 lines
836 B
PHP
<?php
|
|
|
|
/**
|
|
* @group API
|
|
* @group Database
|
|
* @group medium
|
|
*
|
|
* @covers ApiPurge
|
|
*/
|
|
class ApiPurgeTest extends ApiTestCase {
|
|
|
|
public function testPurgePage() {
|
|
$this->getExistingTestPage( 'UTPage' );
|
|
$this->getNonexistingTestPage( 'UTPage-NotFound' );
|
|
|
|
list( $data ) = $this->doApiRequest( [
|
|
'action' => 'purge',
|
|
'titles' => 'UTPage|UTPage-NotFound|%5D'
|
|
] );
|
|
|
|
$resultByTitle = [];
|
|
foreach ( $data['purge'] as $entry ) {
|
|
$key = $entry['title'];
|
|
// Ignore localised or redundant field
|
|
unset( $entry['invalidreason'] );
|
|
unset( $entry['title'] );
|
|
$resultByTitle[$key] = $entry;
|
|
}
|
|
|
|
$this->assertEquals(
|
|
[
|
|
'UTPage' => [ 'purged' => true, 'ns' => 0 ],
|
|
'UTPage-NotFound' => [ 'missing' => true, 'ns' => 0 ],
|
|
'%5D' => [ 'invalid' => true ],
|
|
],
|
|
$resultByTitle,
|
|
'Result'
|
|
);
|
|
}
|
|
}
|