-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds wwExtEnableElasticSearch to new wikis and dispatches a job to initialize the index and enable the feature. Lexeme and Wikibase terms end up in the same index so we do not need to take this into consideration.
- Loading branch information
Showing
5 changed files
with
242 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace Tests\Jobs; | ||
|
||
use App\User; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
use App\Jobs\ElasticSearchIndexInit; | ||
use App\Http\Curl\HttpRequest; | ||
use App\WikiManager; | ||
use App\WikiSetting; | ||
use App\Wiki; | ||
|
||
class ElasticSearchIndexInitTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
private $wiki; | ||
private $user; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->user = User::factory()->create(['verified' => true]); | ||
$this->wiki = Wiki::factory()->create(); | ||
WikiManager::factory()->create(['wiki_id' => $this->wiki->id, 'user_id' => $this->user->id]); | ||
WikiSetting::factory()->create( | ||
[ | ||
'wiki_id' => $this->wiki->id, | ||
'name' => WikiSetting::wwExtEnableElasticSearch, | ||
'value' => false | ||
] | ||
); | ||
} | ||
|
||
public function testSuccess() | ||
{ | ||
$mockResponse = [ | ||
'warnings' => [], | ||
'wbstackElasticSearchInit' => [ | ||
"success" => 1, | ||
"output" => [ | ||
"\tCreating index...ok" // successfully created some index | ||
] | ||
] | ||
]; | ||
$request = $this->createMock(HttpRequest::class); | ||
$request->method('execute')->willReturn(json_encode($mockResponse)); | ||
|
||
$job = new ElasticSearchIndexInit($this->wiki->domain, $this->wiki->id, $request); | ||
$job->handle(); | ||
|
||
// feature should get enabled | ||
$this->assertSame( | ||
1, | ||
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count() | ||
); | ||
} | ||
|
||
public function testUpdate() | ||
{ | ||
$mockResponse = [ | ||
'warnings' => [], | ||
'wbstackElasticSearchInit' => [ | ||
"success" => 1, | ||
"output" => [ | ||
"\t\tValidating {$this->wiki->domain}_general alias...ok" | ||
] | ||
] | ||
]; | ||
$request = $this->createMock(HttpRequest::class); | ||
$request->method('execute')->willReturn(json_encode($mockResponse)); | ||
|
||
$job = new ElasticSearchIndexInit($this->wiki->domain, $this->wiki->id, $request); | ||
$job->handle(); | ||
|
||
// feature should get enabled | ||
$this->assertSame( | ||
1, | ||
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count() | ||
); | ||
} | ||
|
||
public function testFailure() | ||
{ | ||
$mockResponse = [ | ||
'warnings' => [], | ||
'wbstackElasticSearchInit' => [ | ||
"success" => 0, | ||
"output" => [] | ||
] | ||
]; | ||
$request = $this->createMock(HttpRequest::class); | ||
$request->method('execute')->willReturn(json_encode($mockResponse)); | ||
|
||
$job = new ElasticSearchIndexInit($this->wiki->domain, $this->wiki->id, $request); | ||
$job->handle(); | ||
|
||
// feature should not get enabled | ||
$this->assertSame( | ||
0, | ||
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count() | ||
); | ||
} | ||
|
||
public function testJobTriggeredButNoSetting() | ||
{ | ||
WikiSetting::where( ['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch ])->first()->delete(); | ||
$request = $this->createMock(HttpRequest::class); | ||
$request->expects( $this->never() )->method('execute'); | ||
|
||
$job = new ElasticSearchIndexInit($this->wiki->domain, $this->wiki->id, $request); | ||
$job->handle(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters