You are here

protected function CommentAlterTestBase::getCommentAlterations in Comment Alter 8

Get a comment alteration diffs from the current page.

Return value

array An associative array keyed by field label pointing to an array which contains arrays which have two values, the original and new value for the given field.

1 call to CommentAlterTestBase::getCommentAlterations()
CommentAlterTestBase::assertCommentDiff in tests/src/Functional/CommentAlterTestBase.php
Asserts that a Comment Alter diff table on the current page is as expected.

File

tests/src/Functional/CommentAlterTestBase.php, line 201

Class

CommentAlterTestBase
Base class for Comment Alter test cases.

Namespace

Drupal\Tests\comment_alter\Functional

Code

protected function getCommentAlterations() {

  // Extract the values from the
  // '<table class="comment-alter-diff">...</table>'.
  $this
    ->drupalGet('entity_test_rev/manage/' . $this->entity
    ->id());
  $td_s = $this
    ->xpath('//table[@class=:class]/tbody/tr/td', [
    ':class' => 'comment-alter-diff',
  ]);
  $fields = [];
  $i = 0;
  foreach ($td_s as $td) {
    switch ($i % 4) {
      case 0:
        $field_name = $td
          ->getText();
        $field_name = empty($field_name) ? $last_field_name : $field_name;
        break;
      case 1:
        $old_value = $td
          ->getText();
        break;
      case 3:
        $new_value = $td
          ->getText();
        break;
    }
    $i++;
    if ($i % 4 == 0) {
      $last_field_name = $field_name;
      $fields[$field_name][] = [
        $old_value,
        $new_value,
      ];
    }
  }
  return $fields;
}