diff --git a/app/Console/Commands/RebuildQueryserviceData.php b/app/Console/Commands/RebuildQueryserviceData.php
index 1f1ac79ab..8286950e4 100644
--- a/app/Console/Commands/RebuildQueryserviceData.php
+++ b/app/Console/Commands/RebuildQueryserviceData.php
@@ -5,6 +5,7 @@
use App\Constants\MediawikiNamespace;
use App\Jobs\SpawnQueryserviceUpdaterJob;
use App\QueryserviceNamespace;
+use App\Services\MediaWikiHostResolver;
use App\Traits;
use App\Wiki;
use App\WikiSetting;
@@ -25,11 +26,10 @@ class RebuildQueryserviceData extends Command {
protected string $queueName;
- public function handle() {
+ public function handle(MediaWikiHostResolver $mwHostResolver) {
$this->chunkSize = intval($this->option('chunkSize'));
$this->sparqlUrlFormat = $this->option('sparqlUrlFormat');
$this->queueName = $this->option('queueName');
- $this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php';
$wikiDomains = $this->option('domain');
$exitCode = 0;
@@ -42,6 +42,8 @@ public function handle() {
$skippedWikis = 0;
$processedWikis = 0;
foreach ($wikis as $wiki) {
+ $this->apiUrl = $mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace
+
try {
$entities = $this->getEntitiesForWiki($wiki);
$sparqlUrl = $this->getSparqlUrl($wiki);
diff --git a/app/Jobs/CirrusSearch/CirrusSearchJob.php b/app/Jobs/CirrusSearch/CirrusSearchJob.php
index 8e86dabac..ce6d6bad6 100644
--- a/app/Jobs/CirrusSearch/CirrusSearchJob.php
+++ b/app/Jobs/CirrusSearch/CirrusSearchJob.php
@@ -4,6 +4,7 @@
use App\Http\Curl\HttpRequest;
use App\Jobs\Job;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use App\WikiSetting;
use Illuminate\Contracts\Queue\ShouldBeUnique;
@@ -41,7 +42,7 @@ public function wikiId(): int {
/**
* @return void
*/
- public function handle(HttpRequest $request) {
+ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver) {
$this->wiki = Wiki::whereId($this->wikiId)->with('settings')->with('wikiDb')->first();
// job got triggered but no wiki
@@ -69,7 +70,7 @@ public function handle(HttpRequest $request) {
$request->setOptions(
[
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(),
+ CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wiki->domain) . '/w/api.php?action=' . $this->apiModule() . $this->getQueryParams(),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => $this->getRequestTimeout(),
diff --git a/app/Jobs/MediawikiInit.php b/app/Jobs/MediawikiInit.php
index 9fd6b5123..76bb5b4e4 100644
--- a/app/Jobs/MediawikiInit.php
+++ b/app/Jobs/MediawikiInit.php
@@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Http\Curl\HttpRequest;
+use App\Services\MediaWikiHostResolver;
class MediawikiInit extends Job {
private $wikiDomain;
@@ -23,14 +24,14 @@ public function __construct($wikiDomain, $username, $email) {
/**
* @return void
*/
- public function handle(HttpRequest $request) {
+ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver) {
$data = [
'username' => $this->username,
'email' => $this->email,
];
$request->setOptions([
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackInit&format=json',
+ CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wikiDomain) . '/w/api.php?action=wbstackInit&format=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 60,
diff --git a/app/Jobs/MediawikiSandboxLoadData.php b/app/Jobs/MediawikiSandboxLoadData.php
index ace75498b..8d2944326 100644
--- a/app/Jobs/MediawikiSandboxLoadData.php
+++ b/app/Jobs/MediawikiSandboxLoadData.php
@@ -2,6 +2,8 @@
namespace App\Jobs;
+use App\Services\MediaWikiHostResolver;
+
class MediawikiSandboxLoadData extends Job {
private $wikiDomain;
@@ -18,14 +20,14 @@ public function __construct($wikiDomain, $dataSet) {
/**
* @return void
*/
- public function handle() {
+ public function handle(MediaWikiHostResolver $mwHostResolver) {
$data = [
'dataSet' => $this->dataSet,
];
$curl = curl_init();
curl_setopt_array($curl, [
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/rest.php/wikibase-exampledata/v0/load',
+ CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wikiDomain) . '/w/rest.php/wikibase-exampledata/v0/load',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 10 * 60, // TODO Long 10 mins (probably shouldn't keep the request open...)
diff --git a/app/Jobs/PlatformStatsSummaryJob.php b/app/Jobs/PlatformStatsSummaryJob.php
index d882e6159..0312820a0 100644
--- a/app/Jobs/PlatformStatsSummaryJob.php
+++ b/app/Jobs/PlatformStatsSummaryJob.php
@@ -4,6 +4,7 @@
use App\Constants\MediawikiNamespace;
use App\Helper\MWTimestampHelper;
+use App\Services\MediaWikiHostResolver;
use App\Traits;
use App\User;
use App\Wiki;
@@ -39,10 +40,11 @@ class PlatformStatsSummaryJob extends Job {
private $platformSummaryStatsVersion = 'v1';
+ private MediaWikiHostResolver $mwHostResolver;
+
public function __construct() {
$this->inactiveThreshold = Config::get('wbstack.platform_summary_inactive_threshold');
$this->creationRateRanges = Config::get('wbstack.platform_summary_creation_rate_ranges');
- $this->apiUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php';
}
private function isNullOrEmpty($value): bool {
@@ -77,6 +79,7 @@ public function prepareStats(array $allStats, $wikis): array {
$currentTime = CarbonImmutable::now();
foreach ($wikis as $wiki) {
+ $this->apiUrl = $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php'; // used in PageFetcher::fetchPagesInNamespace
if (!is_null($wiki->deleted_at)) {
$deletedWikis[] = $wiki;
@@ -164,7 +167,8 @@ public function prepareStats(array $allStats, $wikis): array {
];
}
- public function handle(DatabaseManager $manager): void {
+ public function handle(DatabaseManager $manager, MediaWikiHostResolver $mwHostResolver): void {
+ $this->mwHostResolver = $mwHostResolver;
$wikis = Wiki::withTrashed()->with('wikidb')->get();
$conn = $manager->connection('mysql');
diff --git a/app/Jobs/PollForMediaWikiJobsJob.php b/app/Jobs/PollForMediaWikiJobsJob.php
index 91b00cae4..60d8d1e1b 100644
--- a/app/Jobs/PollForMediaWikiJobsJob.php
+++ b/app/Jobs/PollForMediaWikiJobsJob.php
@@ -2,6 +2,7 @@
namespace App\Jobs;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -9,9 +10,12 @@
use Illuminate\Support\Facades\Log;
class PollForMediaWikiJobsJob extends Job implements ShouldBeUnique, ShouldQueue {
+ private MediaWikiHostResolver $mwHostResolver;
+
public $timeout = 1800;
- public function handle(): void {
+ public function handle(MediaWikiHostResolver $mwHostResolver): void {
+ $this->mwHostResolver = $mwHostResolver;
$allWikiDomains = Wiki::all()->pluck('domain');
foreach ($allWikiDomains as $wikiDomain) {
if ($this->hasPendingJobs($wikiDomain)) {
@@ -24,7 +28,7 @@ private function hasPendingJobs(string $wikiDomain): bool {
$response = Http::withHeaders([
'host' => $wikiDomain,
])->get(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json'
+ $this->mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json'
);
if ($response->failed()) {
diff --git a/app/Jobs/SiteStatsUpdateJob.php b/app/Jobs/SiteStatsUpdateJob.php
index 118e35d32..d16afcddf 100644
--- a/app/Jobs/SiteStatsUpdateJob.php
+++ b/app/Jobs/SiteStatsUpdateJob.php
@@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Http\Curl\HttpRequest;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use Illuminate\Bus\Batchable;
use Illuminate\Support\Facades\Log;
@@ -22,7 +23,7 @@ public function __construct($wiki_id) {
$this->wiki_id = $wiki_id;
}
- public function handle(HttpRequest $request): void {
+ public function handle(HttpRequest $request, MediaWikiHostResolver $mwHostResolver): void {
$timeStart = microtime(true);
$wiki = Wiki::where('id', $this->wiki_id)->first();
@@ -30,10 +31,10 @@ public function handle(HttpRequest $request): void {
$this->fail(new \RuntimeException(" Could not find wiki with id: $this->wiki_id"));
}
- Log::info(__METHOD__ . ": Updating stats for or $wiki->domain");
+ Log::info(__METHOD__ . ": Updating stats for $wiki->domain");
$request->setOptions([
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackSiteStatsUpdate&format=json',
+ CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php?action=wbstackSiteStatsUpdate&format=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 60 * 5,
diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php
index 04e5368b1..f2453dbe7 100644
--- a/app/Jobs/UpdateWikiSiteStatsJob.php
+++ b/app/Jobs/UpdateWikiSiteStatsJob.php
@@ -2,6 +2,7 @@
namespace App\Jobs;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use App\WikiSiteStats;
use Carbon\Carbon;
@@ -17,7 +18,11 @@ class UpdateWikiSiteStatsJob extends Job implements ShouldBeUnique {
public $timeout = 3600;
- public function handle(): void {
+ private MediaWikiHostResolver $mwHostResolver;
+
+ public function handle(MediaWikiHostResolver $mwHostResolver): void {
+ $this->mwHostResolver = $mwHostResolver;
+
$allWikis = Wiki::all();
foreach ($allWikis as $wiki) {
try {
@@ -54,7 +59,7 @@ private function updateSiteStats(Wiki $wiki): void {
$response = Http::withHeaders([
'host' => $wiki->getAttribute('domain'),
])->get(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json'
+ $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json'
);
if ($response->failed()) {
@@ -76,7 +81,7 @@ private function updateSiteStats(Wiki $wiki): void {
private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface {
$allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php',
+ $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php',
[
'action' => 'query',
'format' => 'json',
@@ -94,7 +99,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface {
}
$revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php',
+ $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php',
[
'action' => 'query',
'format' => 'json',
@@ -114,7 +119,7 @@ private function getFirstEditedDate(Wiki $wiki): ?CarbonInterface {
private function getLastEditedDate(Wiki $wiki): ?CarbonInterface {
$allRevisions = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php',
+ $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php',
[
'action' => 'query',
'format' => 'json',
@@ -132,7 +137,7 @@ private function getLastEditedDate(Wiki $wiki): ?CarbonInterface {
}
$revisionInfo = Http::withHeaders(['host' => $wiki->getAttribute('domain')])->get(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php',
+ $this->mwHostResolver->getBackendHostForDomain($wiki->domain) . '/w/api.php',
[
'action' => 'query',
'format' => 'json',
diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php
index 6b0af4736..441f8d690 100644
--- a/app/Jobs/WikiEntityImportJob.php
+++ b/app/Jobs/WikiEntityImportJob.php
@@ -2,6 +2,7 @@
namespace App\Jobs;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use App\WikiEntityImport;
use App\WikiEntityImportStatus;
@@ -27,7 +28,7 @@ public function __construct(
public int $wikiId,
public string $sourceWikiUrl,
public array $entityIds,
- public int $importId,
+ public int $importId
) {}
private string $targetWikiUrl;
@@ -35,12 +36,12 @@ public function __construct(
/**
* Execute the job.
*/
- public function handle(Client $kubernetesClient): void {
+ public function handle(Client $kubernetesClient, MediaWikiHostResolver $mwHostResolver): void {
$import = null;
try {
$wiki = Wiki::findOrFail($this->wikiId);
$import = WikiEntityImport::findOrFail($this->importId);
- $creds = $this->acquireCredentials($wiki->domain);
+ $creds = $this->acquireCredentials($wiki->domain, $mwHostResolver);
$this->targetWikiUrl = $this->domainToOrigin($wiki->domain);
@@ -77,9 +78,9 @@ private static function domainToOrigin(string $domain): string {
: 'https://' . $domain;
}
- private static function acquireCredentials(string $wikiDomain): OAuthCredentials {
+ private static function acquireCredentials(string $wikiDomain, MediaWikiHostResolver $mwHostResolver): OAuthCredentials {
$response = Http::withHeaders(['host' => $wikiDomain])->asForm()->post(
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackPlatformOauthGet&format=json',
+ $mwHostResolver->getBackendHostForDomain($wikiDomain) . '/w/api.php?action=wbstackPlatformOauthGet&format=json',
[
'consumerName' => 'WikiEntityImportJob',
'ownerOnly' => '1',
diff --git a/phpunit.xml b/phpunit.xml
index 1b31238df..867f2ff2b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -9,7 +9,6 @@
-
diff --git a/tests/Commands/RebuildQueryserviceDataTest.php b/tests/Commands/RebuildQueryserviceDataTest.php
index aad23ed02..07387a22d 100644
--- a/tests/Commands/RebuildQueryserviceDataTest.php
+++ b/tests/Commands/RebuildQueryserviceDataTest.php
@@ -5,6 +5,7 @@
use App\Constants\MediawikiNamespace;
use App\Jobs\SpawnQueryserviceUpdaterJob;
use App\QueryserviceNamespace;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use App\WikiSetting;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@@ -16,11 +17,22 @@
class RebuildQueryserviceDataTest extends TestCase {
use DatabaseTransactions;
+ private $mwBackendHost;
+
protected function setUp(): void {
parent::setUp();
Wiki::query()->delete();
WikiSetting::query()->delete();
QueryserviceNamespace::query()->delete();
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
+
+ $this->app->instance(MediaWikiHostResolver::class, $mockMwHostResolver);
}
protected function tearDown(): void {
@@ -55,7 +67,7 @@ public function testWikiWithLexemes() {
]);
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
[
@@ -73,7 +85,7 @@ public function testWikiWithLexemes() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
'continue' => [
'apcontinue' => 'Q6',
],
@@ -102,7 +114,7 @@ public function testWikiWithLexemes() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
[
@@ -124,7 +136,7 @@ public function testWikiWithLexemes() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
[
@@ -185,7 +197,7 @@ public function testWikiNoLexemes() {
]);
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
[
@@ -203,7 +215,7 @@ public function testWikiNoLexemes() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
[
@@ -229,7 +241,7 @@ public function testWikiNoLexemes() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
'error' => 'Lexemes not enabled for this wiki',
], 400),
]);
@@ -261,7 +273,7 @@ public function testFailure() {
]);
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
[
@@ -279,10 +291,10 @@ public function testFailure() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
'error' => 'THE DINOSAURS ESCAPED!',
], 500),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
'error' => 'Lexemes not enabled for this wiki',
], 400),
]);
@@ -301,17 +313,17 @@ public function testEmptyWiki() {
]);
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=146&apcontinue=&aplimit=max&format=json' => Http::response([
'error' => 'Lexemes not enabled for this wiki',
], 400),
]);
diff --git a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php
index 1d538f324..c87d02b19 100644
--- a/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php
+++ b/tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php
@@ -5,6 +5,7 @@
use App\Http\Curl\CurlRequest;
use App\Http\Curl\HttpRequest;
use App\Jobs\CirrusSearch\ElasticSearchIndexInit;
+use App\Services\MediaWikiHostResolver;
use App\User;
use App\Wiki;
use App\WikiDb;
@@ -25,6 +26,10 @@ class ElasticSearchIndexInitTest extends TestCase {
private $user;
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
@@ -42,6 +47,13 @@ protected function setUp(): void {
$this->wikiDb = WikiDb::factory()->create([
'wiki_id' => $this->wiki->id,
]);
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
public function testDispatching() {
@@ -50,7 +62,7 @@ public function testDispatching() {
$job->setJob($mockJob);
$mockJob->expects($this->once())
->method('fail');
- $job->handle(new CurlRequest);
+ $job->handle(new CurlRequest, $this->mockMwHostResolver);
}
public function testSuccess() {
@@ -71,7 +83,7 @@ public function testSuccess() {
$request->expects($this->once())
->method('setOptions')
->with([
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackElasticSearchInit&format=json&cluster=all',
+ CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackElasticSearchInit&format=json&cluster=all',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 1234,
@@ -90,7 +102,7 @@ public function testSuccess() {
$job = new ElasticSearchIndexInit($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
// feature should get enabled
$this->assertSame(
@@ -119,7 +131,7 @@ public function testUpdate() {
$job = new ElasticSearchIndexInit($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
// feature should get enabled
$this->assertSame(
@@ -134,7 +146,7 @@ public function testJobTriggeredButNoSetting() {
$request->expects($this->never())->method('execute');
$job = new ElasticSearchIndexInit($this->wiki->id);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
/**
@@ -152,7 +164,7 @@ public function testFailure(string $expectedFailure, $mockResponse) {
$job = new ElasticSearchIndexInit($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
$this->assertSame(
1,
@@ -174,7 +186,7 @@ public function testCurlFailure() {
$job = new ElasticSearchIndexInit($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
$this->assertSame(
1,
diff --git a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php
index 43df89ab5..c20b36cda 100644
--- a/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php
+++ b/tests/Jobs/CirrusSearch/ForceSearchIndexTest.php
@@ -4,6 +4,7 @@
use App\Http\Curl\HttpRequest;
use App\Jobs\CirrusSearch\ForceSearchIndex;
+use App\Services\MediaWikiHostResolver;
use App\User;
use App\Wiki;
use App\WikiDb;
@@ -25,6 +26,10 @@ class ForceSearchIndexTest extends TestCase {
private $user;
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
@@ -42,6 +47,13 @@ protected function setUp(): void {
$this->wikiDb = WikiDb::factory()->create([
'wiki_id' => $this->wiki->id,
]);
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
public function testSuccess() {
@@ -89,7 +101,7 @@ public function testSuccess() {
$request->expects($this->once())
->method('setOptions')
->with([
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackForceSearchIndex&format=json&fromId=' . $fromId . '&toId=' . $toId,
+ CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackForceSearchIndex&format=json&fromId=' . $fromId . '&toId=' . $toId,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 1000,
@@ -108,6 +120,6 @@ public function testSuccess() {
$job = new ForceSearchIndex('id', $this->wiki->id, $fromId, $toId);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
}
diff --git a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php
index 892ddb347..1e7845c7d 100644
--- a/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php
+++ b/tests/Jobs/CirrusSearch/QueueSearchIndexBatchesTest.php
@@ -5,6 +5,7 @@
use App\Http\Curl\HttpRequest;
use App\Jobs\CirrusSearch\ForceSearchIndex;
use App\Jobs\CirrusSearch\QueueSearchIndexBatches;
+use App\Services\MediaWikiHostResolver;
use App\User;
use App\Wiki;
use App\WikiDb;
@@ -26,6 +27,8 @@ class QueueSearchIndexBatchesTest extends TestCase {
private $user;
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
@@ -43,6 +46,13 @@ protected function setUp(): void {
$this->wikiDb = WikiDb::factory()->create([
'wiki_id' => $this->wiki->id,
]);
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
public function testSuccess() {
@@ -65,7 +75,7 @@ public function testSuccess() {
$request->expects($this->once())
->method('setOptions')
->with([
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json',
+ CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 1000,
@@ -84,7 +94,7 @@ public function testSuccess() {
$job = new QueueSearchIndexBatches($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
Queue::assertPushed(function (ForceSearchIndex $job) {
return $job->wikiId() === $this->wiki->id
@@ -114,7 +124,7 @@ public function testMediawikiErrorResponse() {
$request->expects($this->once())
->method('setOptions')
->with([
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json',
+ CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackQueueSearchIndexBatches&format=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 1000,
@@ -133,6 +143,6 @@ public function testMediawikiErrorResponse() {
$job = new QueueSearchIndexBatches($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
}
diff --git a/tests/Jobs/MediawikiInitTest.php b/tests/Jobs/MediawikiInitTest.php
index 6398b9b65..0bd26a25b 100644
--- a/tests/Jobs/MediawikiInitTest.php
+++ b/tests/Jobs/MediawikiInitTest.php
@@ -4,6 +4,7 @@
use App\Http\Curl\HttpRequest;
use App\Jobs\MediawikiInit;
+use App\Services\MediaWikiHostResolver;
use Illuminate\Contracts\Queue\Job;
use Tests\TestCase;
@@ -14,11 +15,21 @@ class MediawikiInitTest extends TestCase {
private $username;
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
$this->wikiDomain = 'some.domain.com';
$this->username = 'username';
$this->email = 'some@email.com';
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
private function getMockRequest(string $mockResponse): HttpRequest {
@@ -29,7 +40,7 @@ private function getMockRequest(string $mockResponse): HttpRequest {
->method('setOptions')
->with(
[
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackInit&format=json',
+ CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackInit&format=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 60,
@@ -68,7 +79,7 @@ public function testSuccess() {
$job = new MediawikiInit($this->wikiDomain, $this->username, $this->email);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
public function testFatalErrorIsHandled() {
@@ -84,6 +95,6 @@ public function testFatalErrorIsHandled() {
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage($expectedExceptionMessage);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
}
diff --git a/tests/Jobs/PlatformStatsSummaryJobTest.php b/tests/Jobs/PlatformStatsSummaryJobTest.php
index 282d32131..4a954200f 100644
--- a/tests/Jobs/PlatformStatsSummaryJobTest.php
+++ b/tests/Jobs/PlatformStatsSummaryJobTest.php
@@ -6,6 +6,7 @@
use App\Helper\MWTimestampHelper;
use App\Jobs\PlatformStatsSummaryJob;
use App\Jobs\ProvisionWikiDbJob;
+use App\Services\MediaWikiHostResolver;
use App\User;
use App\Wiki;
use App\WikiDb;
@@ -31,6 +32,10 @@ class PlatformStatsSummaryJobTest extends TestCase {
private $db_name = 'some_cool_db_name';
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
for ($n = 0; $n < $this->numWikis; $n++) {
@@ -38,6 +43,13 @@ protected function setUp(): void {
}
$this->wikis = [];
$this->users = [];
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
protected function tearDown(): void {
@@ -57,7 +69,7 @@ private function seedWikis() {
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
$job = new ProvisionWikiDbJob($this->db_prefix . $n, $this->db_name . $n, null);
- $job->handle($manager);
+ $job->handle($manager, $this->mockMwHostResolver);
$wikiDb = WikiDb::whereName($this->db_name . $n)->first();
$wikiDb->update(['wiki_id' => $wiki->id]);
@@ -80,7 +92,7 @@ public function testQueryGetsStats() {
$job = new PlatformStatsSummaryJob;
$job->setJob($mockJob);
- $job->handle($manager);
+ $job->handle($manager, $this->mockMwHostResolver);
}
public function testGroupings() {
@@ -110,7 +122,7 @@ public function testGroupings() {
]);
// Generate some items/properties for testing, each wiki will have 3 props and 9 items
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
['title' => 'Property:P1', 'namespace' => MediawikiNamespace::property],
@@ -119,7 +131,7 @@ public function testGroupings() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json' => Http::response([
'continue' => [
'apcontinue' => 'Q6',
],
@@ -133,7 +145,7 @@ public function testGroupings() {
],
],
], 200),
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=Q6&aplimit=max&format=json' => Http::response([
'query' => [
'allpages' => [
['title' => 'Item:Q6', 'namespace' => MediawikiNamespace::item],
diff --git a/tests/Jobs/PollForMediaWikiJobsJobTest.php b/tests/Jobs/PollForMediaWikiJobsJobTest.php
index b46b1eb69..ddd33cd68 100644
--- a/tests/Jobs/PollForMediaWikiJobsJobTest.php
+++ b/tests/Jobs/PollForMediaWikiJobsJobTest.php
@@ -4,6 +4,7 @@
use App\Jobs\PollForMediaWikiJobsJob;
use App\Jobs\ProcessMediaWikiJobsJob;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Database\Eloquent\Model;
@@ -17,14 +18,25 @@ class PollForMediaWikiJobsJobTest extends TestCase {
private Model $wiki;
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
$this->wiki = Wiki::factory()->create();
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
public function testNoJobs() {
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([
'query' => [
'statistics' => [
'jobs' => 0,
@@ -40,13 +52,13 @@ public function testNoJobs() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->never())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
Bus::assertNothingDispatched();
}
public function testWithJobs() {
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([
'query' => [
'statistics' => [
'jobs' => 3,
@@ -63,13 +75,13 @@ public function testWithJobs() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->never())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
Bus::assertDispatched(ProcessMediaWikiJobsJob::class);
}
public function testWithFailure() {
Http::fake([
- getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json' => Http::response([
'error' => 'Something went wrong',
], 500),
]);
@@ -82,7 +94,7 @@ public function testWithFailure() {
$mockJob->expects($this->once())->method('markAsFailed');
$mockJob->expects($this->never())->method('fail');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
Bus::assertNothingDispatched();
}
}
diff --git a/tests/Jobs/SiteStatsUpdateJobTest.php b/tests/Jobs/SiteStatsUpdateJobTest.php
index c2cd839d7..2851b4d19 100644
--- a/tests/Jobs/SiteStatsUpdateJobTest.php
+++ b/tests/Jobs/SiteStatsUpdateJobTest.php
@@ -4,6 +4,7 @@
use App\Http\Curl\HttpRequest;
use App\Jobs\SiteStatsUpdateJob;
+use App\Services\MediaWikiHostResolver;
use App\User;
use App\Wiki;
use App\WikiManager;
@@ -14,11 +15,27 @@
class SiteStatsUpdateJobTest extends TestCase {
use RefreshDatabase;
+ private $user;
+
+ private $wiki;
+
+ private $manager;
+
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
$this->user = User::factory()->create(['verified' => true]);
$this->wiki = Wiki::factory()->create();
$this->manager = WikiManager::factory()->create(['wiki_id' => $this->wiki->id, 'user_id' => $this->user->id]);
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
private function getMockRequest(string $mockResponse): HttpRequest {
@@ -29,7 +46,7 @@ private function getMockRequest(string $mockResponse): HttpRequest {
->method('setOptions')
->with(
[
- CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=wbstackSiteStatsUpdate&format=json',
+ CURLOPT_URL => $this->mwBackendHost . '/w/api.php?action=wbstackSiteStatsUpdate&format=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 60 * 5,
@@ -63,7 +80,7 @@ public function testSuccess() {
$job = new SiteStatsUpdateJob($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
public function testFatalErrorIsHandled() {
@@ -83,6 +100,6 @@ public function testFatalErrorIsHandled() {
$job = new SiteStatsUpdateJob($this->wiki->id);
$job->setJob($mockJob);
- $job->handle($request);
+ $job->handle($request, $this->mockMwHostResolver);
}
}
diff --git a/tests/Jobs/UpdateWikiSiteStatsJobTest.php b/tests/Jobs/UpdateWikiSiteStatsJobTest.php
index 56f9709d6..fe32937d0 100644
--- a/tests/Jobs/UpdateWikiSiteStatsJobTest.php
+++ b/tests/Jobs/UpdateWikiSiteStatsJobTest.php
@@ -3,6 +3,7 @@
namespace Tests\Jobs;
use App\Jobs\UpdateWikiSiteStatsJob;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -15,12 +16,23 @@ class UpdateWikiSiteStatsJobTest extends TestCase {
private $fakeResponses;
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
// Other tests leave dangling wikis around so we need to clean them up
parent::setUp();
Wiki::query()->delete();
$this->fakeResponses = [];
Http::preventStrayRequests();
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
protected function tearDown(): void {
@@ -29,12 +41,12 @@ protected function tearDown(): void {
}
private function addFakeSiteStatsResponse($site, $response) {
- $siteStatsUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json';
+ $siteStatsUrl = $this->mwBackendHost . '/w/api.php?action=query&meta=siteinfo&siprop=statistics&format=json';
$this->fakeResponses[$siteStatsUrl][$site] = $response;
}
private function addFakeRevisionTimestamp($site, $revid, $timestamp) {
- $revTimestampUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&prop=revisions&rvprop=timestamp&formatversion=2&revids=' . $revid;
+ $revTimestampUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&prop=revisions&rvprop=timestamp&formatversion=2&revids=' . $revid;
$this->fakeResponses[$revTimestampUrl][$site] = Http::response([
'query' => [
'pages' => [
@@ -51,13 +63,13 @@ private function addFakeRevisionTimestamp($site, $revid, $timestamp) {
}
private function addFakeEmptyRevisionList($site) {
- $firstRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer';
+ $firstRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer';
$this->fakeResponses[$firstRevisionIdUrl][$site] = Http::response([
'query' => [
'allrevisions' => [],
],
]);
- $lastRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older';
+ $lastRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older';
$this->fakeResponses[$lastRevisionIdUrl][$site] = Http::response([
'query' => [
'allrevisions' => [],
@@ -66,7 +78,7 @@ private function addFakeEmptyRevisionList($site) {
}
private function addFakeFirstRevisionId($site, $id) {
- $firstRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer';
+ $firstRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=newer';
$this->fakeResponses[$firstRevisionIdUrl][$site] = Http::response([
'query' => [
'allrevisions' => [
@@ -83,7 +95,7 @@ private function addFakeFirstRevisionId($site, $id) {
}
private function addFakeLastRevisionId($site, $id) {
- $lastRevisionIdUrl = getenv('PLATFORM_MW_BACKEND_HOST') . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older';
+ $lastRevisionIdUrl = $this->mwBackendHost . '/w/api.php?action=query&format=json&list=allrevisions&formatversion=2&arvlimit=1&arvprop=ids&arvexcludeuser=PlatformReservedUser&arvdir=older';
$this->fakeResponses[$lastRevisionIdUrl][$site] = Http::response([
'query' => [
'allrevisions' => [
@@ -148,7 +160,7 @@ public function testWikiSiteStatsIsSuccessfullyUpdated() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->never())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
$stats1 = Wiki::with('wikiSiteStats')->where(['domain' => 'this.wikibase.cloud'])->first()->wikiSiteStats()->first();
$this->assertEquals($stats1['admins'], 7);
@@ -214,7 +226,7 @@ public function testSuccessOfMultipleWikisTogether() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->never())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
$stats1 = Wiki::with('wikiSiteStats')->where(['domain' => 'this.wikibase.cloud'])->first()->wikiSiteStats()->first();
$this->assertEquals($stats1['admins'], 7);
@@ -247,7 +259,7 @@ public function testJobFailsIfSiteStatsLookupFails() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->once())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
}
public function testIncompleteSiteStatsDoesNotCauseFailure() {
@@ -276,7 +288,7 @@ public function testIncompleteSiteStatsDoesNotCauseFailure() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->never())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
$stats2 = Wiki::with('wikiSiteStats')->where(['domain' => 'incomplete.wikibase.cloud'])->first()->wikiSiteStats()->first();
$this->assertEquals($stats2['articles'], 99);
@@ -298,7 +310,7 @@ public function testNeverEditedWikiCreatesEmptyLifecycleEvents() {
$mockJob->expects($this->never())->method('fail');
$mockJob->expects($this->never())->method('markAsFailed');
- $job->handle();
+ $job->handle($this->mockMwHostResolver);
$events = Wiki::with('wikiLifecycleEvents')->where(['domain' => 'this.wikibase.cloud'])->first()->wikiLifecycleEvents()->first();
$this->assertNull($events['first_edited']);
diff --git a/tests/Jobs/WikiEntityImportJobTest.php b/tests/Jobs/WikiEntityImportJobTest.php
index ad8e62a48..15c8aa6b5 100644
--- a/tests/Jobs/WikiEntityImportJobTest.php
+++ b/tests/Jobs/WikiEntityImportJobTest.php
@@ -3,6 +3,7 @@
namespace Tests\Jobs;
use App\Jobs\WikiEntityImportJob;
+use App\Services\MediaWikiHostResolver;
use App\Wiki;
use App\WikiEntityImport;
use App\WikiEntityImportStatus;
@@ -19,10 +20,21 @@
class WikiEntityImportJobTest extends TestCase {
use RefreshDatabase;
+ private $mwBackendHost;
+
+ private $mockMwHostResolver;
+
protected function setUp(): void {
parent::setUp();
Wiki::query()->delete();
WikiEntityImport::query()->delete();
+
+ $this->mwBackendHost = 'mediawiki.localhost';
+
+ $this->mockMwHostResolver = $this->createMock(MediaWikiHostResolver::class);
+ $this->mockMwHostResolver->method('getBackendHostForDomain')->willReturn(
+ $this->mwBackendHost
+ );
}
protected function tearDown(): void {
@@ -34,7 +46,7 @@ protected function tearDown(): void {
public function testJobDoesNotFail() {
Http::fake([
- 'mediawiki-139-app-backend.default.svc.cluster.default/w/api.php?action=wbstackPlatformOauthGet&format=json' => Http::response([
+ $this->mwBackendHost . '/w/api.php?action=wbstackPlatformOauthGet&format=json' => Http::response([
'wbstackPlatformOauthGet' => [
'success' => '1',
'data' => [
@@ -80,9 +92,11 @@ public function testJobDoesNotFail() {
'verify' => '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt',
]);
- $job->handle(new Client([
+ $k8sClient = new Client([
'master' => 'https://kubernetes.default.svc',
'token' => '/var/run/secrets/kubernetes.io/serviceaccount/token',
- ], null, $mockGuzzle));
+ ], null, $mockGuzzle);
+
+ $job->handle($k8sClient, $this->mockMwHostResolver);
}
}