1.20.x redirect.test RedirectUnitTest::testCompareArrayRecursive()

Test the redirect_compare_array_recursive() function.

File

modules/redirect/tests/redirect.test, line 104
Unit tests for the redirect module.

Class

RedirectUnitTest

Code

function testCompareArrayRecursive() {
  backdrop_load('module', 'redirect');
  $haystack = array('a' => 'aa', 'b' => 'bb', 'c' => array('c1' => 'cc1', 'c2' => 'cc2'));
  $cases = array(
    array('query' => array('a' => 'aa', 'b' => 'invalid'), 'result' => FALSE),
    array('query' => array('b' => 'bb'), 'result' => TRUE),
    array('query' => array('b' => 'bb', 'c' => 'invalid'), 'result' => FALSE),
    array('query' => array('b' => 'bb', 'c' => array()), 'result' => TRUE),
    array('query' => array('b' => 'bb', 'c' => array('invalid')), 'result' => FALSE),
    array('query' => array('b' => 'bb', 'c' => array('c2' => 'invalid')), 'result' => FALSE),
    array('query' => array('b' => 'bb', 'c' => array('c2' => 'cc2')), 'result' => TRUE),
  );
  foreach ($cases as $index => $case) {
    $this->assertEqual($case['result'], redirect_compare_array_recursive($case['query'], $haystack));
  }
}