Commit | Line | Data |
---|---|---|
5c2885f8 | 1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | ||
5 | /** | |
6 | * Class CRM_Core_Page_RedirectTest | |
7 | */ | |
8 | class CRM_Core_Page_RedirectTest extends CiviUnitTestCase { | |
7fe37828 EM |
9 | /** |
10 | * Get example data. | |
11 | * | |
12 | * @return array | |
13 | */ | |
14 | /** | |
15 | * @return array | |
16 | */ | |
00be9182 | 17 | public function examples() { |
5c2885f8 | 18 | $cases = array(); |
19 | // $cases[] = array(string $requestPath, string $requestArgs, string $pageArgs, string $expectedUrl) | |
20 | ||
21 | // Note: CRM_Utils_System::url() and CRM_Utils_System::redirect() represent the | |
22 | // URL in "htmlized" format, so the $expectedUrl is "htmlized". | |
23 | ||
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'); | |
30 | ||
31 | $cases[] = array( | |
32 | '', | |
33 | 'gid=2&reset=1', | |
34 | 'url=civicrm/newfoo/%%gid%%?reset=%%reset%%', | |
21dfd5f5 | 35 | '/index.php?q=civicrm/newfoo/2&reset=1', |
5c2885f8 | 36 | ); |
37 | ||
38 | return $cases; | |
39 | } | |
40 | ||
41 | /** | |
42 | * Note: Expected URL is htmlized because that's what CRM_Utils_System::url() | |
43 | * and CRM_Utils_System::redirect() work with. | |
44 | * | |
e16033b4 TO |
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". | |
5c2885f8 | 53 | * @dataProvider examples |
54 | */ | |
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); | |
61 | } | |
96025800 | 62 | |
5c2885f8 | 63 | } |