-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForceSearchIndexTest.php
More file actions
117 lines (105 loc) · 5.1 KB
/
Copy pathForceSearchIndexTest.php
File metadata and controls
117 lines (105 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace Tests\Jobs\CirrusSearch;
use App\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Jobs\CirrusSearch\ElasticSearchIndexInit;
use App\Http\Curl\HttpRequest;
use App\WikiManager;
use App\WikiSetting;
use App\Wiki;
use Illuminate\Contracts\Queue\Job;
use App\WikiDb;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\DB;
use PHPUnit\TextUI\RuntimeException;
use App\Jobs\CirrusSearch\QueueSearchIndexBatches;
use App\Jobs\CirrusSearch\ForceSearchIndex;
use Illuminate\Support\Facades\Bus;
use Queue;
class ForceSearchIndexTest extends TestCase
{
use RefreshDatabase;
use DispatchesJobs;
private $wiki;
private $wikiDb;
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' => true
]
);
$this->wikiDb = WikiDb::factory()->create([
'wiki_id' => $this->wiki->id
]);
}
public function testSuccess()
{
Queue::fake();
$toId = 10;
$fromId = 0;
$mockResponse = [
'warnings' => [],
'wbstackForceSearchIndex' => [
"return" => 0,
"output" => [
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 10 at 2/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 20 at 4/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 30 at 6/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 40 at 7/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 50 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 60 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 70 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 80 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 90 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 100 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 110 at 9/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 120 at 10/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 130 at 10/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 140 at 10/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 150 at 10/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 160 at 10/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 170 at 11/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 180 at 11/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 190 at 11/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 200 at 11/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 210 at 11/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 10 pages ending at 220 at 11/second",
"[mwdb_febf08b4c7-mwt_f66e770e74_] Indexed 9 pages ending at 229 at 11/second",
"Indexed a total of 229 pages at 11/second"
]
]
];
$request = $this->createMock(HttpRequest::class);
$request->method('execute')->willReturn(json_encode($mockResponse));
$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_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 1000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'content-type: application/x-www-form-urlencoded',
'host: '.$this->wiki->domain,
]
]);
$mockJob = $this->createMock(Job::class);
$mockJob->expects($this->never())
->method('fail')
->withAnyParameters();
$job = new ForceSearchIndex('id', $this->wiki->id, $fromId, $toId);
$job->setJob($mockJob);
$job->handle($request);
}
}