3 require_once 'CiviTest/CiviUnitTestCase.php';
6 * Class CRM_Core_Page_RedirectTest
8 class CRM_Core_Page_RedirectTest
extends CiviUnitTestCase
{
17 public function examples() {
19 // $cases[] = array(string $requestPath, string $requestArgs, string $pageArgs, string $expectedUrl)
21 // Note: CRM_Utils_System::url() and CRM_Utils_System::redirect() represent the
22 // URL in "htmlized" format, so the $expectedUrl is "htmlized".
24 $cases[] = array('', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard');
25 $cases[] = array('', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard');
26 $cases[] = array('', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar');
27 $cases[] = array('', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&whiz=1&bang=2');
28 $cases[] = array('', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&unknown=');
29 $cases[] = array('civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar');
34 'url=civicrm/newfoo/%%gid%%?reset=%%reset%%',
35 '/index.php?q=civicrm/newfoo/2&reset=1',
42 * Note: Expected URL is htmlized because that's what CRM_Utils_System::url()
43 * and CRM_Utils_System::redirect() work with.
45 * @param string $requestPath
46 * Eg "civicrm/requested/path".
47 * @param string $requestArgs
48 * Eg "foo=bar&whiz=bang".
49 * @param string $pageArgs
50 * Eg "url=civicrm/foo/bar?whiz=bang".
51 * @param string $expectedUrl
52 * Eg "/index.php?q=civicrm/foo/bar&whiz=bang".
53 * @dataProvider examples
55 public function testCreateUrl($requestPath, $requestArgs, $pageArgs, $expectedUrl) {
56 $parsedRequestPath = explode('/', $requestPath);
57 parse_str($requestArgs, $parsedRequestArgs);
58 $parsedPageArgs = CRM_Core_Menu
::getArrayForPathArgs($pageArgs);
59 $actualUrl = CRM_Core_Page_Redirect
::createUrl($parsedRequestPath, $parsedRequestArgs, $parsedPageArgs, FALSE);
60 $this->assertEquals($expectedUrl, $actualUrl);