Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | ||
aba1cd8b EM |
5 | /** |
6 | * Class CRM_Core_Page_AJAXTest | |
7 | */ | |
6a488035 TO |
8 | class CRM_Core_Page_AJAXTest extends CiviUnitTestCase { |
9 | public function testCheckAuthz() { | |
10 | $cases = array(); | |
11 | ||
12 | $cases[] = array('method', 'CRM_Foo', FALSE, 'method'); | |
13 | $cases[] = array('method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method'); | |
14 | $cases[] = array('method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay'); | |
15 | $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method('); | |
16 | $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method()'); | |
17 | $cases[] = array('method', 'othermethod;CRM_Foo_Page_AJAX', FALSE,'method'); | |
18 | $cases[] = array('method', 'CRM_Foo_Page_AJAX;othermethod', FALSE,'method'); | |
19 | $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, ''); | |
20 | $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method'); | |
21 | $cases[] = array('method', 'CRM_Foo->method', FALSE); | |
22 | ||
23 | ||
24 | $cases[] = array('page', 'CRM_Foo', FALSE); | |
25 | $cases[] = array('page', 'CRM_Foo_Bar', FALSE); | |
26 | $cases[] = array('page', 'CRM_Foo_Page', FALSE); | |
27 | $cases[] = array('page', 'CRM_Foo_Page_Bar', FALSE); | |
28 | $cases[] = array('page', 'CRM_Foo_Page_Inline', FALSE); | |
29 | $cases[] = array('page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE); | |
30 | $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE); | |
31 | $cases[] = array('page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE); | |
32 | $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE); | |
33 | $cases[] = array('page', 'CRM_Foo_Form', FALSE); | |
34 | $cases[] = array('page', 'CRM_Foo_Form_Bar', FALSE); | |
35 | $cases[] = array('page', 'CRM_Foo_Form_Inline', FALSE); | |
36 | $cases[] = array('page', 'CRM_Contact_Form_Inline_Email', TRUE); | |
37 | $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE); | |
38 | $cases[] = array('page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE); | |
39 | $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE); | |
40 | ||
41 | // aliases for 'page' | |
42 | $cases[] = array('class', 'CRM_Foo_Bar', FALSE); | |
43 | $cases[] = array('class', 'CRM_Contact_Page_Inline_Phone', TRUE); | |
44 | $cases[] = array('', 'CRM_Foo_Bar', FALSE); | |
45 | $cases[] = array('', 'CRM_Contact_Page_Inline_Demographics', TRUE); | |
b6708aeb | 46 | |
6a488035 TO |
47 | // invalid type |
48 | $cases[] = array('invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE); | |
49 | $cases[] = array('invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE); | |
50 | ||
51 | foreach ($cases as $case) { | |
0031e7ea E |
52 | list ($type, $className, $expectedResult) = $case; |
53 | $methodName = CRM_Utils_Array::value(3, $case); | |
6a488035 TO |
54 | $actualResult = CRM_Core_Page_AJAX::checkAuthz($type, $className, $methodName); |
55 | if ($methodName) { | |
56 | $this->assertEquals($expectedResult, $actualResult, | |
57 | sprintf('Check type=[%s] value=[%s] method=[%s]', $type, $className, $methodName)); | |
58 | } | |
59 | else { | |
60 | $this->assertEquals($expectedResult, $actualResult, | |
61 | sprintf('Check type=[%s] value=[%s]', $type, $className)); | |
62 | } | |
63 | } | |
64 | } | |
65 | } |