summaryrefslogtreecommitdiff
path: root/modules/simpletest/drupal_web_test_case.php
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2011-01-02 23:54:05 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2011-01-02 23:54:05 +0000
commit78601c3635d0569a71835743d2d2c6e850e4cc39 (patch)
tree39fdf9ae3f1a1baf69f2865472a122234ad2fb97 /modules/simpletest/drupal_web_test_case.php
parent8ae6dc4b2ecaa669e061aac7879435be01021c33 (diff)
downloadbrdo-78601c3635d0569a71835743d2d2c6e850e4cc39.tar.gz
brdo-78601c3635d0569a71835743d2d2c6e850e4cc39.tar.bz2
#754760 by sun, chx, dmitrig01, manarth, EvanDonovan, derjochenmeyer, joachim: Fixed all possible problems with comment links, using new generatePermutations testing function.
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r--modules/simpletest/drupal_web_test_case.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 841451746..fa9917d77 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -578,6 +578,55 @@ abstract class DrupalTestCase {
}
return $str;
}
+
+ /**
+ * Converts a list of possible parameters into a stack of permutations.
+ *
+ * Takes a list of parameters containing possible values, and converts all of
+ * them into a list of items containing every possible permutation.
+ *
+ * Example:
+ * @code
+ * $parameters = array(
+ * 'one' => array(0, 1),
+ * 'two' => array(2, 3),
+ * );
+ * $permutations = $this->permute($parameters);
+ * // Result:
+ * $permutations == array(
+ * array('one' => 0, 'two' => 2),
+ * array('one' => 1, 'two' => 2),
+ * array('one' => 0, 'two' => 3),
+ * array('one' => 1, 'two' => 3),
+ * )
+ * @endcode
+ *
+ * @param $parameters
+ * An associative array of parameters, keyed by parameter name, and whose
+ * values are arrays of parameter values.
+ *
+ * @return
+ * A list of permutations, which is an array of arrays. Each inner array
+ * contains the full list of parameters that have been passed, but with a
+ * single value only.
+ */
+ public static function generatePermutations($parameters) {
+ $all_permutations = array(array());
+ foreach ($parameters as $parameter => $values) {
+ $new_permutations = array();
+ // Iterate over all values of the parameter.
+ foreach ($values as $value) {
+ // Iterate over all existing permutations.
+ foreach ($all_permutations as $permutation) {
+ // Add the new parameter value to existing permutations.
+ $new_permutations[] = $permutation + array($parameter => $value);
+ }
+ }
+ // Replace the old permutations with the new permutations.
+ $all_permutations = $new_permutations;
+ }
+ return $all_permutations;
+ }
}
/**