Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SeedTestData | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | use MediaWiki\Maintenance\Maintenance; |
| 4 | use MediaWiki\User\User; |
| 5 | |
| 6 | // @codeCoverageIgnoreStart |
| 7 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 8 | if ( $IP === false ) { |
| 9 | $IP = __DIR__ . '/../../..'; |
| 10 | } |
| 11 | require_once "$IP/maintenance/Maintenance.php"; |
| 12 | // @codeCoverageIgnoreEnd |
| 13 | |
| 14 | /** |
| 15 | * Seeds a test banner + campaign so selenium tests that look for |
| 16 | * #centralnotice_testbanner pass on a fresh environment. |
| 17 | * |
| 18 | * CentralNotice's selenium test (tests/selenium/specs/centralnotice.js) expects a |
| 19 | * banner to be showing on the Main Page. Betacluster keeps one as persistent data, but |
| 20 | * ephemeral environments (e.g. catalyst) start empty, so they must seed it before the |
| 21 | * test runs. Idempotent: skips anything that already exists. |
| 22 | * |
| 23 | * See https://phabricator.wikimedia.org/T429531 |
| 24 | */ |
| 25 | class SeedTestData extends Maintenance { |
| 26 | public function __construct() { |
| 27 | parent::__construct(); |
| 28 | $this->requireExtension( 'CentralNotice' ); |
| 29 | $this->addDescription( |
| 30 | 'Seed a test banner + campaign for selenium runs on fresh environments (e.g. catalyst).' |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | public function execute() { |
| 35 | $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [ 'steal' => true ] ); |
| 36 | |
| 37 | if ( Banner::fromName( 'testbanner' )->exists() ) { |
| 38 | $this->output( "Banner 'testbanner' already exists; skipping.\n" ); |
| 39 | } else { |
| 40 | Banner::addBanner( |
| 41 | name: 'testbanner', |
| 42 | body: '<div id="centralnotice_testbanner">CI test banner</div>', |
| 43 | user: $user, |
| 44 | displayAnon: true, |
| 45 | displayAccount: true |
| 46 | ); |
| 47 | $this->output( "Created banner 'testbanner'.\n" ); |
| 48 | } |
| 49 | |
| 50 | if ( Campaign::campaignExists( 'TestCampaign' ) ) { |
| 51 | $this->output( "Campaign 'TestCampaign' already exists; skipping.\n" ); |
| 52 | } else { |
| 53 | Campaign::addCampaign( |
| 54 | noticeName: 'TestCampaign', |
| 55 | enabled: true, |
| 56 | startTs: wfTimestamp( TS_MW ), |
| 57 | projects: [ 'wikipedia' ], |
| 58 | project_languages: [ 'en' ], |
| 59 | geotargeted: false, |
| 60 | geo_countries: [], |
| 61 | geo_regions: [], |
| 62 | throttle: 100, |
| 63 | priority: CentralNotice::NORMAL_PRIORITY, |
| 64 | user: $user, |
| 65 | type: null |
| 66 | ); |
| 67 | Campaign::addTemplateTo( 'TestCampaign', 'testbanner', 25 ); |
| 68 | $this->output( "Created campaign 'TestCampaign' with banner 'testbanner'.\n" ); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // @codeCoverageIgnoreStart |
| 74 | $maintClass = SeedTestData::class; |
| 75 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 76 | // @codeCoverageIgnoreEnd |