Skip to content

Commit

Permalink
(tests) Move all tests to namespace MediaWiki\Moderation\Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspec committed Jan 3, 2025
1 parent 2ef80fc commit c530c44
Show file tree
Hide file tree
Showing 138 changed files with 712 additions and 73 deletions.
16 changes: 12 additions & 4 deletions tests/common/ModerationTestHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
* Implements HTML parsing methods for the automated testsuite.
*/

namespace MediaWiki\Moderation\Tests;

use DOMDocument;
use DOMElement;
use DOMNode;
use DOMNodeList;
use DomXpath;

class ModerationTestHTML extends DOMDocument {

/**
Expand Down Expand Up @@ -120,7 +128,7 @@ public function getModerationError() {

/**
* Returns HTML element of the main text of the page.
* @return DomElement|null
* @return DOMElement|null
*/
public function getMainContent() {
return $this->getElementById( 'mw-content-text' );
Expand Down Expand Up @@ -208,10 +216,10 @@ public function getLoaderModulesList() {

/**
* Return the array of <input> elements in the form (name => value).
* @param DomElement|null $formElement
* @return DomElement[]
* @param DOMElement|null $formElement
* @return DOMElement[]
*/
public function getFormElements( DomElement $formElement = null ) {
public function getFormElements( DOMElement $formElement = null ) {
if ( !$formElement ) {
$formElement = $this;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/common/ModerationTestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@
* Utility functions used in both benchmark and PHPUnit Testsuite.
*/

namespace MediaWiki\Moderation\Tests;

use CommentStoreComment;
use ContentHandler;
use FauxRequest;
use IContextSource;
use Language;
use MediaWiki\MediaWikiServices;
use MediaWiki\Moderation\ModerationCompatTools;
use MediaWiki\Revision\MutableRevisionRecord;
use MediaWiki\Revision\SlotRecord;
use MediaWikiIntegrationTestCase;
use RequestContext;
use Title;
use User;

class ModerationTestUtil {
/**
Expand Down
4 changes: 3 additions & 1 deletion tests/common/trait/ModerationTempUserTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
* Polyfill for TempUserTestTrait (which doesn't exist in MediaWiki 1.39-1.41).
*/

namespace MediaWiki\Moderation\Tests;

use MediaWiki\Tests\User\TempUser\TempUserTestTrait;

if ( trait_exists( TempUserTestTrait::class ) ) {
// MediaWiki 1.42+
// @phan-suppress-next-line PhanRedefineClassAlias
class_alias( TempUserTestTrait::class, 'ModerationTempUserTestTrait' );
class_alias( TempUserTestTrait::class, ModerationTempUserTestTrait::class );
} else {
// MediaWiki 1.39-1.41.
// Temporary accounts weren't enabled by default (or supported by Moderation) before 1.43,
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/blackbox/ModerationApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Verifies that modactions work via api.php?action=moderation.
*/

namespace MediaWiki\Moderation\Tests;

use FormatJson;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/phpunit/blackbox/ModerationApproveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
* Verifies that modaction=approve(all) works as expected.
*/

require_once __DIR__ . "/../framework/ModerationTestsuite.php";
namespace MediaWiki\Moderation\Tests;

use MediaWiki\Moderation\ModerationCompatTools;
use MWTimestamp;
use Title;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
* @group Database
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/blackbox/ModerationCheckuserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Ensures that checkuser-related functionality works correctly.
*/

namespace MediaWiki\Moderation\Tests;

use User;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/blackbox/ModerationEditChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* @note modaction=editchangesubmit is tested in ModerationActionTest.
*/

namespace MediaWiki\Moderation\Tests;

use SpecialPage;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationEditConflictTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* Note: unresolvable edit conflicts are tested by ModerationMergeTest.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Verifies that editing works as usual.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationFileRevertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Ensures that reverting image to old revision doesn't bypass Moderation.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationInterceptEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Ensures that edits are intercepted by Extension:Moderation.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationMergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Verifies that modaction=merge works as expected.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Verifies that moderators see "New changes await moderation" notice.
*/

namespace MediaWiki\Moderation\Tests;

use Title;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/blackbox/ModerationPageFormsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Verifies compatibility with Extension:PageForms.
*/

namespace MediaWiki\Moderation\Tests;

use SpecialPage;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @file
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationPreloadIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Checks that user can continue editing their version of the page.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationRejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Verifies that modaction=reject(all) works as expected.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationReturntoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @file
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/blackbox/ModerationShowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Verifies that modaction=show works as expected.
*/

namespace MediaWiki\Moderation\Tests;

use DomElement;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @file
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/blackbox/ModerationUploadStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
* Ensures that ModerationUploadStorage works for existing uploads and new uploads.
*/

require_once __DIR__ . "/../framework/ModerationTestsuite.php";
namespace MediaWiki\Moderation\Tests;

use MediaWiki\Moderation\ModerationCompatTools;
use MediaWiki\Moderation\ModerationUploadStorage;
use UploadStash;
use User;
use Wikimedia\TestingAccessWrapper;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
* @group Database
Expand Down Expand Up @@ -77,7 +82,7 @@ public function testMigrationFromPerUploaderStashes( ModerationTestsuite $t ) {
$stash = ModerationUploadStorage::getStash();
$this->assertInstanceOf( UploadStash::class, $stash );

$stashAccessWrapper = Wikimedia\TestingAccessWrapper::newFromObject( $stash );
$stashAccessWrapper = TestingAccessWrapper::newFromObject( $stash );
$stashOwner = $stashAccessWrapper->user;

$this->assertEquals( ModerationUploadStorage::USERNAME, $stashOwner->getName() );
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/blackbox/ModerationUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Ensures that uploads are intercepted by Extension:Moderation.
*/

namespace MediaWiki\Moderation\Tests;

require_once __DIR__ . "/../framework/ModerationTestsuite.php";

/**
Expand Down
10 changes: 9 additions & 1 deletion tests/phpunit/consequence/ActionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
* Unit test of ActionFactory.
*/

namespace MediaWiki\Moderation\Tests;

use DerivativeContext;
use FauxRequest;
use Language;
use MediaWiki\Moderation\ActionFactory;
use MediaWiki\Moderation\ActionLinkRenderer;
use MediaWiki\Moderation\EditFormOptions;
use MediaWiki\Moderation\EntryFactory;
use MediaWiki\Moderation\MockConsequenceManager;
use MediaWiki\Moderation\ModerationActionApprove;
use MediaWiki\Moderation\ModerationActionBlock;
use MediaWiki\Moderation\ModerationActionEditChange;
Expand All @@ -37,6 +41,10 @@
use MediaWiki\Moderation\ModerationCanSkip;
use MediaWiki\Moderation\ModerationError;
use MediaWiki\Revision\RevisionRenderer;
use ReadOnlyMode;
use RepoGroup;
use RequestContext;
use User;
use Wikimedia\TestingAccessWrapper;

require_once __DIR__ . "/autoload.php";
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/consequence/ActionLinkRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
* Unit test of ActionLinkRenderer.
*/

namespace MediaWiki\Moderation\Tests;

use IContextSource;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Moderation\ActionLinkRenderer;
use RawMessage;
use Title;
use User;

require_once __DIR__ . "/autoload.php";

Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/consequence/AddLogEntryConsequenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
* Unit test of AddLogEntryConsequence.
*/

namespace MediaWiki\Moderation\Tests;

use DatabaseLogEntry;
use ManualLogEntry;
use MediaWiki\Moderation\AddLogEntryConsequence;
use MediaWiki\Moderation\ModerationApproveHook;
use MediaWiki\Moderation\ModerationCompatTools;
use Title;
use User;

require_once __DIR__ . "/autoload.php";

Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/consequence/ApiModerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
* Unit test of ApiModeration.
*/

namespace MediaWiki\Moderation\Tests;

use ApiMain;
use ApiTestCase;
use ApiUsageException;
use MediaWiki\Moderation\ActionFactory;
use MediaWiki\Moderation\ApiModeration;
use MediaWiki\Moderation\ModerationError;
Expand Down
7 changes: 7 additions & 0 deletions tests/phpunit/consequence/ApiQueryModerationPreloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
* Unit test of ApiQueryModerationPreload.
*/

namespace MediaWiki\Moderation\Tests;

use ApiMain;
use ApiQuery;
use ApiQueryBase;
use ApiTestCase;
use MediaWiki\Moderation\ApiQueryModerationPreload;
use MediaWiki\Moderation\ModerationPreload;
use MediaWiki\Moderation\PendingEdit;
use Title;
use Wikimedia\TestingAccessWrapper;

require_once __DIR__ . "/autoload.php";
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/consequence/ApproveEditConsequenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
* Unit test of ApproveEditConsequence.
*/

namespace MediaWiki\Moderation\Tests;

use IDBAccessObject;
use MediaWiki\MediaWikiServices;
use MediaWiki\Moderation\ApproveEditConsequence;
use MediaWiki\Revision\SlotRecord;
use RecentChange;
use Title;
use User;

require_once __DIR__ . "/autoload.php";

Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/consequence/ApproveMoveConsequenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
* Unit test of ApproveMoveConsequence.
*/

namespace MediaWiki\Moderation\Tests;

use MediaWiki\Moderation\ApproveMoveConsequence;
use Title;

require_once __DIR__ . "/autoload.php";

Expand Down
Loading

0 comments on commit c530c44

Please sign in to comment.