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