You are here

public function DiffContext::compareRevisions in Lightning Workflow 8.2

Same name and namespace in other branches
  1. 8 tests/contexts/DiffContext.behat.inc \Acquia\LightningExtension\Context\DiffContext::compareRevisions()

Compares two revisions of a node.

@When I compare the :a and :b revisions

Parameters

string $a: The one-based index of a revision to compare. 1st is oldest.

string $b: The one-based index of a revision to compare. 1st is oldest.

File

tests/contexts/DiffContext.behat.inc, line 23

Class

DiffContext
Contains step definitions for interacting with the Diff module.

Namespace

Acquia\LightningExtension\Context

Code

public function compareRevisions($a, $b) {
  $assert = $this
    ->assertSession();

  /** @var MinkContext $context */
  $context = $this
    ->getContext(MinkContext::class);
  $re = '/^[0-9]+(st|nd|rd|th)$/i';
  if (preg_match($re, $a)) {
    $a = substr($a, 0, -2);
  }
  if (preg_match($re, $b)) {
    $b = substr($b, 0, -2);
  }
  $a = (int) $a - 1;
  $b = (int) $b - 1;
  $assert
    ->elementExists('named', [
    'link',
    'Revisions',
  ])
    ->click();

  /** @var \Behat\Mink\Element\NodeElement[] $rows */
  $rows = $this
    ->getSession()
    ->getPage()
    ->findAll('css', '.diff-revisions tbody tr');
  $rows = array_reverse($rows);
  $a = $rows[$a]
    ->findField('radios_left')
    ->getValue();
  $b = $rows[$b]
    ->findField('radios_right')
    ->getValue();
  $context
    ->selectOption('radios_left', $a);
  $context
    ->selectOption('radios_right', $b);
  $assert
    ->elementExists('named', [
    'button',
    'Compare',
  ])
    ->press();
}