1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\DrupalExtension\Context; |
4
|
|
|
|
5
|
|
|
use Behat\MinkExtension\Context\RawMinkContext; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Extensions to the Mink Extension. |
9
|
|
|
*/ |
10
|
|
|
class BatchContext extends RawMinkContext { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Wait for the Batch API to finish. |
14
|
|
|
* |
15
|
|
|
* Wait until the id="updateprogress" element is gone, |
16
|
|
|
* or timeout after 3 minutes (180,000 ms). |
17
|
|
|
* |
18
|
|
|
* @Given /^I wait for the batch job to finish$/ |
19
|
|
|
*/ |
20
|
|
|
public function iWaitForTheBatchJobToFinish() { |
21
|
|
|
$this->getSession()->wait(180000, 'jQuery("#updateprogress").length === 0'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Creats a queue item. Defaults inputs if none are available. |
26
|
|
|
* |
27
|
|
|
* Expects the data to be a json encoded string. |
28
|
|
|
* |
29
|
|
|
* @Given there is an item in the system queue: |
30
|
|
|
*/ |
31
|
|
|
public function thereIsAnItemInTheSystemQueue(TableNode $table) |
32
|
|
|
{ |
33
|
|
|
// Gather the data. |
34
|
|
|
$fields = $table->getRowsHash(); |
35
|
|
|
|
36
|
|
|
// Default data field separately since this is longish. |
37
|
|
|
if (empty($fields['data'])) { |
38
|
|
|
$fields['data'] = json_encode([]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// @see SystemQueue::createItem(). |
42
|
|
|
$query = db_insert('queue') |
43
|
|
|
->fields(array( |
44
|
|
|
'name' => $fields['name'] ?: user_password(), |
45
|
|
|
'data' => serialize(json_decode($fields['data'])), |
46
|
|
|
'created' => $fields['created'] ?: REQUEST_TIME, |
47
|
|
|
'expire' => $fields['expire'] ?: 0, |
48
|
|
|
)); |
49
|
|
|
if (!$query->execute()) { |
50
|
|
|
throw new Exception('Unable to create the queue item.'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|