Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PopulateTestData | |
0.00% |
0 / 38 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo\Maintenance; |
4 | |
5 | use BackupReader; |
6 | use MediaWiki\CommentStore\CommentStoreComment; |
7 | use MediaWiki\Context\RequestContext; |
8 | use MediaWiki\Maintenance\Maintenance; |
9 | use MediaWiki\Request\FauxRequest; |
10 | use MediaWiki\Revision\SlotRecord; |
11 | use MediaWiki\Title\Title; |
12 | |
13 | $IP = getenv( 'MW_INSTALL_PATH' ); |
14 | if ( $IP === false ) { |
15 | $IP = __DIR__ . '/../../..'; |
16 | } |
17 | require_once "$IP/maintenance/Maintenance.php"; |
18 | |
19 | /** |
20 | * Helper script to setup required test fixtures for WDIO browser tests. |
21 | */ |
22 | class PopulateTestData extends Maintenance { |
23 | |
24 | public function __construct() { |
25 | parent::__construct(); |
26 | $this->addDescription( 'Import test data for use in WDIO E2E tests' ); |
27 | $this->addOption( 'ip', 'Test IP to associate with temp user edits', true, true ); |
28 | $this->addOption( 'temp-name', 'The temporary user name to use', true, true ); |
29 | $this->requireExtension( 'IPInfo' ); |
30 | } |
31 | |
32 | public function execute() { |
33 | if ( !$this->getServiceContainer()->getTempUserConfig()->isEnabled() ) { |
34 | $this->fatalError( 'Setting up test data requires temporary user support to be active.' ); |
35 | } |
36 | |
37 | $this->output( "Importing IP edit fixture..\n" ); |
38 | |
39 | $importDump = $this->runChild( BackupReader::class ); |
40 | $importDump->setArg( 0, __DIR__ . '/../tests/fixtures/ip-edit-fixture.xml' ); |
41 | $importDump->execute(); |
42 | |
43 | $this->output( "Creating test page as temporary user...\n" ); |
44 | |
45 | $req = new FauxRequest(); |
46 | $req->setIP( $this->getOption( 'ip' ) ); |
47 | |
48 | RequestContext::getMain()->setRequest( $req ); |
49 | |
50 | $tempName = $this->getOption( 'temp-name' ); |
51 | |
52 | if ( !$this->getServiceContainer()->getTempUserConfig()->isTempName( $tempName ) ) { |
53 | $this->fatalError( "The given name \"$tempName\" is not a valid temporary user name.\n" ); |
54 | } |
55 | |
56 | $tempUser = $this->getServiceContainer() |
57 | ->getUserIdentityLookup() |
58 | ->getUserIdentityByName( $tempName ); |
59 | |
60 | if ( $tempUser === null ) { |
61 | $tempUser = $this->getServiceContainer() |
62 | ->getTempUserCreator() |
63 | ->create( $tempName, $req ) |
64 | ->getUser(); |
65 | } |
66 | |
67 | $page = Title::makeTitle( NS_MAIN, 'IPInfo Temp User Test' ); |
68 | $content = $this->getServiceContainer() |
69 | ->getContentHandlerFactory() |
70 | ->getContentHandler( CONTENT_MODEL_WIKITEXT ) |
71 | ->unserializeContent( 'test content' ); |
72 | |
73 | $pageUpdater = $this->getServiceContainer() |
74 | ->getPageUpdaterFactory() |
75 | ->newPageUpdater( $page, $tempUser ) |
76 | ->setContent( SlotRecord::MAIN, $content ); |
77 | |
78 | $pageUpdater->saveRevision( CommentStoreComment::newUnsavedComment( 'test' ) ); |
79 | |
80 | if ( !$pageUpdater->wasSuccessful() ) { |
81 | $this->fatalError( $pageUpdater->getStatus() ); |
82 | } |
83 | } |
84 | } |
85 | |
86 | $maintClass = PopulateTestData::class; |
87 | require_once RUN_MAINTENANCE_IF_MAIN; |