You are here

protected function NodeorderCrudTest::assertNodeorderByTid in Node Order 8

Tests actual order against an expected order.

Parameters

int $tid: Term ID to check order against.

array $expected: Expected order keyed by node ID.

1 call to NodeorderCrudTest::assertNodeorderByTid()
NodeorderCrudTest::testNodeCrudOperations in src/Tests/NodeorderCrudTest.php
Test node CRUD operations that nodeorder depends on.

File

src/Tests/NodeorderCrudTest.php, line 298

Class

NodeorderCrudTest
Test CRUD operations that Nodeorder relies on.

Namespace

Drupal\nodeorder\Tests

Code

protected function assertNodeorderByTid($tid, array $expected) {
  $order = \Drupal::database()
    ->select('taxonomy_index', 'ti')
    ->fields('ti', [
    'nid',
    'weight',
  ])
    ->condition('tid', $tid)
    ->execute()
    ->fetchAllAssoc('nid');
  foreach ($order as $nid => $row) {
    if (isset($expected[$nid]) && $expected[$nid] == $row->weight) {
      unset($expected[$nid]);
      unset($order[$nid]);
    }
  }
  if (!empty($expected) || !empty($order)) {
    debug($expected, 'Orderings that did not match.');
    debug($order, 'Orderings found that were not expected.');
    $this
      ->fail('Order did not match.');
  }
  else {
    $this
      ->pass('Order of nodes matched.');
  }
}