commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / CRM / Core / Page / RedirectTest.php
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 /**
10 * Get example data.
11 *
12 * @return array
13 */
14 /**
15 * @return array
16 */
17 public function examples() {
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&amp;whiz=1&amp;bang=2');
28 $cases[] = array('', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&amp;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%%',
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 }