function GraphUnitTest::assertPaths

Verify expected paths in a graph.

Parameters

$graph: A graph array processed by Drupal\Component\Graph\Graph::searchAndSort().

$expected_paths: An associative array containing vertices with their expected paths.

1 call to GraphUnitTest::assertPaths()
GraphUnitTest::testDepthFirstSearch in drupal/core/modules/system/lib/Drupal/system/Tests/Graph/GraphUnitTest.php
Test depth-first-search features.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Graph/GraphUnitTest.php, line 117
Definition of Drupal\system\Tests\Graph\GraphUnitTest.

Class

GraphUnitTest
Unit tests for the graph handling features.

Namespace

Drupal\system\Tests\Graph

Code

function assertPaths($graph, $expected_paths) {
  foreach ($expected_paths as $vertex => $paths) {

    // Build an array with keys = $paths and values = TRUE.
    $expected = array_fill_keys($paths, TRUE);
    $result = isset($graph[$vertex]['paths']) ? $graph[$vertex]['paths'] : array();
    $this
      ->assertEqual($expected, $result, format_string('Expected paths for vertex @vertex: @expected-paths, got @paths', array(
      '@vertex' => $vertex,
      '@expected-paths' => $this
        ->displayArray($expected, TRUE),
      '@paths' => $this
        ->displayArray($result, TRUE),
    )));
  }
}