Completed
Push — 62-logout-performance ( 400382...858f9a )
by Jonathan
01:37
created

BatchContext::iWaitForTheBatchJobToFinish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
  /**
14
   * Wait for the Batch API to finish.
15
   *
16
   * Wait until the id="updateprogress" element is gone,
17
   * or timeout after 3 minutes (180,000 ms).
18
   *
19
   * @Given /^I wait for the batch job to finish$/
20
   */
21
    public function iWaitForTheBatchJobToFinish()
22
    {
23
        $this->getSession()->wait(180000, 'jQuery("#updateprogress").length === 0');
24
    }
25
26
  /**
27
   * Creates a queue item. Defaults inputs if none are available.
28
   *
29
   * Expects the `data` to be a json encoded string.
30
   *
31
   * @Given there is an item in the system queue:
32
   */
33
    public function thereIsAnItemInTheSystemQueue(TableNode $table)
34
    {
35
        // Gather the data.
36
        $fields = $table->getRowsHash();
37
38
        // Default data field separately since this is longish.
39
        if (empty($fields['data'])) {
40
            $fields['data'] = json_encode([]);
41
        }
42
43
        // @see SystemQueue::createItem().
44
        $query = db_insert('queue')
45
        ->fields(array(
46
        'name' => $fields['name'] ?: user_password(),
47
        'data' => serialize(json_decode($fields['data'])),
48
        'created' => $fields['created'] ?: REQUEST_TIME,
49
        'expire' => $fields['expire'] ?: 0,
50
        ));
51
        if (!$query->execute()) {
52
            throw new Exception('Unable to create the queue item.');
53
        }
54
    }
55
}
56