wiki.techinc.nl/tests/phpunit/structure/PasswordPolicyStructureTest.php
Gergő Tisza 45d4e8d13a Exempt structure tests from @covers checks
@covers does not make any sense for structure tests, which either
do not cover any PHP lines (they test things like configuration or
messages), or cover lines which cannot be determined at the time
of writing the tests (e.g. they cover all classes implementing a
certain interface). Requiring @coversNothing to be manually added
for all of them is a waste of developer time.

tests/phpunit/suite.xml has forceCoversAnnotation=true so removing
the annotations will not change test coverage, these files will
still be skipped.

Change-Id: I27cb58e92341b9b1a76f109701f5bc843adbaa9b
2019-06-11 21:40:14 +00:00

46 lines
1.2 KiB
PHP

<?php
class PasswordPolicyStructureTest extends MediaWikiTestCase {
public function provideChecks() {
global $wgPasswordPolicy;
foreach ( $wgPasswordPolicy['checks'] as $name => $callback ) {
yield [ $name ];
}
}
public function provideFlags() {
global $wgPasswordPolicy;
// This won't actually find all flags, just the ones in use. Can't really be helped,
// other than adding the core flags here.
$flags = [ 'forceChange', 'suggestChangeOnLogin' ];
foreach ( $wgPasswordPolicy['policies'] as $group => $checks ) {
foreach ( $checks as $check => $settings ) {
if ( is_array( $settings ) ) {
$flags = array_unique(
array_merge( $flags, array_diff( array_keys( $settings ), [ 'value' ] ) )
);
}
}
}
foreach ( $flags as $flag ) {
yield [ $flag ];
}
}
/** @dataProvider provideChecks */
public function testCheckMessage( $check ) {
$msg = wfMessage( 'passwordpolicies-policy-' . strtolower( $check ) );
$this->assertTrue( $msg->exists() );
}
/** @dataProvider provideFlags */
public function testFlagMessage( $flag ) {
$msg = wfMessage( 'passwordpolicies-policyflag-' . strtolower( $flag ) );
$this->assertTrue( $msg->exists() );
}
}