tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Core / Page / RedirectTest.php
1 <?php
2
3 /**
4 * Class CRM_Core_Page_RedirectTest
5 */
6 class CRM_Core_Page_RedirectTest extends CiviUnitTestCase {
7 /**
8 * Get example data.
9 *
10 * @return array
11 */
12 /**
13 * @return array
14 */
15 public function examples() {
16 $cases = array();
17 // $cases[] = array(string $requestPath, string $requestArgs, string $pageArgs, string $expectedUrl)
18
19 // Note: CRM_Utils_System::url() and CRM_Utils_System::redirect() represent the
20 // URL in "htmlized" format, so the $expectedUrl is "htmlized".
21
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&amp;whiz=1&amp;bang=2');
26 $cases[] = array('', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&amp;unknown=');
27 $cases[] = array('civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar');
28
29 $cases[] = array(
30 '',
31 'gid=2&reset=1',
32 'url=civicrm/newfoo/%%gid%%?reset=%%reset%%',
33 '/index.php?q=civicrm/newfoo/2&amp;reset=1',
34 );
35
36 return $cases;
37 }
38
39 /**
40 * Note: Expected URL is htmlized because that's what CRM_Utils_System::url()
41 * and CRM_Utils_System::redirect() work with.
42 *
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
52 */
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);
59 }
60
61 }