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 { |
9 | function examples() { |
10 | $cases = array(); |
11 | // $cases[] = array(string $requestPath, string $requestArgs, string $pageArgs, string $expectedUrl) |
12 | |
13 | // Note: CRM_Utils_System::url() and CRM_Utils_System::redirect() represent the |
14 | // URL in "htmlized" format, so the $expectedUrl is "htmlized". |
15 | |
16 | $cases[] = array('', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard'); |
17 | $cases[] = array('', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard'); |
18 | $cases[] = array('', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar'); |
19 | $cases[] = array('', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&whiz=1&bang=2'); |
20 | $cases[] = array('', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&unknown='); |
21 | $cases[] = array('civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar'); |
22 | |
23 | $cases[] = array( |
24 | '', |
25 | 'gid=2&reset=1', |
26 | 'url=civicrm/newfoo/%%gid%%?reset=%%reset%%', |
27 | '/index.php?q=civicrm/newfoo/2&reset=1' |
28 | ); |
29 | |
30 | return $cases; |
31 | } |
32 | |
33 | /** |
34 | * Note: Expected URL is htmlized because that's what CRM_Utils_System::url() |
35 | * and CRM_Utils_System::redirect() work with. |
36 | * |
37 | * @param string $requestPath eg "civicrm/requested/path" |
38 | * @param string $requestArgs eg "foo=bar&whiz=bang" |
39 | * @param string $pageArgs eg "url=civicrm/foo/bar?whiz=bang" |
40 | * @param string $expectedUrl eg "/index.php?q=civicrm/foo/bar&whiz=bang" |
41 | * @dataProvider examples |
42 | */ |
43 | public function testCreateUrl($requestPath, $requestArgs, $pageArgs, $expectedUrl) { |
44 | $parsedRequestPath = explode('/', $requestPath); |
45 | parse_str($requestArgs, $parsedRequestArgs); |
46 | $parsedPageArgs = CRM_Core_Menu::getArrayForPathArgs($pageArgs); |
47 | $actualUrl = CRM_Core_Page_Redirect::createUrl($parsedRequestPath, $parsedRequestArgs, $parsedPageArgs, FALSE); |
48 | $this->assertEquals($expectedUrl, $actualUrl); |
49 | } |
50 | } |