Merge pull request #17253 from mattwire/utf8convertblocksize
[civicrm-core.git] / tests / phpunit / CRM / Core / Page / RedirectTest.php
1 <?php
2
3 /**
4 * Class CRM_Core_Page_RedirectTest
5 * @group headless
6 */
7 class CRM_Core_Page_RedirectTest extends CiviUnitTestCase {
8 /**
9 * Get example data.
10 *
11 * @return array
12 */
13
14 /**
15 * @return array
16 */
17 public function examples() {
18 $cases = [];
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[] = ['', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard'];
25 $cases[] = ['', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard'];
26 $cases[] = ['', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar'];
27 $cases[] = ['', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&amp;whiz=1&amp;bang=2'];
28 $cases[] = ['', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&amp;unknown='];
29 $cases[] = ['civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar'];
30
31 $cases[] = [
32 '',
33 'gid=2&reset=1',
34 'url=civicrm/newfoo/%%gid%%?reset=%%reset%%',
35 '/index.php?q=civicrm/newfoo/2&amp;reset=1',
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 *
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
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 }
62
63 }