These are not only 100% identical to the actual code, but also: * It's error-prone. Some are already wrong. * These test…() functions are not meant to be called from anywhere. What is the target audience for this documentation? * There is a @dataProvider. What such @param tags actually do is document the provider, but in an odd place. Just looking at the provider should give the same information. * The MediaWiki CodeSniffer allows to skip @param when there is a @dataProvider, for the reasone listed. Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
78 lines
2 KiB
PHP
78 lines
2 KiB
PHP
<?php
|
|
/**
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
use MediaWiki\EditPage\Constraint\IEditConstraint;
|
|
use MediaWiki\EditPage\Constraint\PageSizeConstraint;
|
|
|
|
/**
|
|
* Tests the PageSizeConstraint
|
|
*
|
|
* @author DannyS712
|
|
*
|
|
* @covers \MediaWiki\EditPage\Constraint\PageSizeConstraint
|
|
*/
|
|
class PageSizeConstraintTest extends MediaWikiUnitTestCase {
|
|
use EditConstraintTestTrait;
|
|
|
|
/**
|
|
* @dataProvider provideCodes
|
|
*/
|
|
public function testPass( string $type, int $errorCode ) {
|
|
// 1023 < ( 1 * 1024 )
|
|
$constraint = new PageSizeConstraint(
|
|
1,
|
|
1023,
|
|
$type
|
|
);
|
|
$this->assertConstraintPassed( $constraint );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideCodes
|
|
*/
|
|
public function testFailure( string $type, int $errorCode ) {
|
|
// 1025 > ( 1 * 1024 )
|
|
$constraint = new PageSizeConstraint(
|
|
1,
|
|
1025,
|
|
$type
|
|
);
|
|
$this->assertConstraintFailed( $constraint, $errorCode );
|
|
}
|
|
|
|
public function provideCodes() {
|
|
return [
|
|
'Before merge - CONTENT_TOO_BIG' => [
|
|
PageSizeConstraint::BEFORE_MERGE,
|
|
IEditConstraint::AS_CONTENT_TOO_BIG
|
|
],
|
|
'After merge - MAX_ARTICLE_SIZE' => [
|
|
PageSizeConstraint::AFTER_MERGE,
|
|
IEditConstraint::AS_MAX_ARTICLE_SIZE_EXCEEDED
|
|
]
|
|
];
|
|
}
|
|
|
|
public function testInvalidType() {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
new PageSizeConstraint( 1, 1023, 'FooBar' );
|
|
}
|
|
|
|
}
|