Commit c7095deb authored by webchick's avatar webchick

#423664 by Berdir: Fix dependency checking of non-existing modules. (with corrected tests)

parent 1de1293d
......@@ -121,19 +121,23 @@ function _drupal_depth_first_search(&$graph, &$state, $start, &$component = NULL
unset($state['components'][$component]);
$component = $new_component;
}
// Only visit existing vertices.
if (isset($graph[$end])) {
// Visit the connected vertex.
_drupal_depth_first_search($graph, $state, $end, $component);
// Visit the connected vertex.
_drupal_depth_first_search($graph, $state, $end, $component);
// All vertices reachable by $end are also reachable by $start.
$graph[$start]['paths'] += $graph[$end]['paths'];
// All vertices reachable by $end are also reachable by $start.
$graph[$start]['paths'] += $graph[$end]['paths'];
}
}
}
// Now that any other subgraph has been explored, add $start to all reverse
// paths.
foreach ($graph[$start]['paths'] as $end => $v) {
$graph[$end]['reverse_paths'][$start] = TRUE;
if (isset($graph[$end])) {
$graph[$end]['reverse_paths'][$start] = TRUE;
}
}
// Record the order of the last visit. This is the reverse of the
......
......@@ -170,7 +170,7 @@ function _module_build_dependencies($files) {
}
drupal_depth_first_search($graph, array_keys($roots));
foreach ($graph as $module => $data) {
$files[$module]->required_by= isset($data['reverse_paths']) ? $data['reverse_paths'] : array();
$files[$module]->required_by = isset($data['reverse_paths']) ? $data['reverse_paths'] : array();
$files[$module]->requires = isset($data['paths']) ? $data['paths'] : array();
$files[$module]->sort = $data['weight'];
}
......
......@@ -39,6 +39,7 @@ class GraphUnitTest extends DrupalWebTestCase {
5 => array(6),
7 => array(4, 5),
8 => array(9),
9 => array(),
));
drupal_depth_first_search($graph);
......@@ -48,7 +49,6 @@ class GraphUnitTest extends DrupalWebTestCase {
3 => array(),
4 => array(3),
5 => array(6),
6 => array(),
7 => array(4, 3, 5, 6),
8 => array(9),
9 => array(),
......@@ -61,15 +61,17 @@ class GraphUnitTest extends DrupalWebTestCase {
3 => array(2, 1, 4, 7),
4 => array(2, 1, 7),
5 => array(7),
6 => array(5, 7),
7 => array(),
8 => array(),
9 => array(8),
);
$this->assertReversePaths($graph, $expected_reverse_paths);
// Assert that DFS didn't created "missing" vertexes automatically.
$this->assertFALSE(isset($graph[6]), t('Vertex 6 has not been created'));
$expected_components = array(
array(1, 2, 3, 4, 5, 6, 7),
array(1, 2, 3, 4, 5, 7),
array(8, 9),
);
$this->assertComponents($graph, $expected_components);
......@@ -78,7 +80,7 @@ class GraphUnitTest extends DrupalWebTestCase {
array(1, 2, 3),
array(2, 4, 3),
array(7, 4, 3),
array(7, 5, 6),
array(7, 5),
array(8, 9),
);
$this->assertWeights($graph, $expected_weights);
......@@ -90,6 +92,8 @@ class GraphUnitTest extends DrupalWebTestCase {
function normalizeGraph($graph) {
$normalized_graph = array();
foreach ($graph as $vertex => $edges) {
// Create vertex even if it hasn't any edges.
$normalized_graph[$vertex] = array();
foreach ($edges as $edge) {
$normalized_graph[$vertex]['edges'][$edge] = TRUE;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment