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()'); | |
6c6e6187 TO |
17 | $cases[] = array('method', 'othermethod;CRM_Foo_Page_AJAX', FALSE, 'method'); |
18 | $cases[] = array('method', 'CRM_Foo_Page_AJAX;othermethod', FALSE, 'method'); | |
6a488035 TO |
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 | ||
6a488035 TO |
23 | $cases[] = array('page', 'CRM_Foo', FALSE); |
24 | $cases[] = array('page', 'CRM_Foo_Bar', FALSE); | |
25 | $cases[] = array('page', 'CRM_Foo_Page', FALSE); | |
26 | $cases[] = array('page', 'CRM_Foo_Page_Bar', FALSE); | |
27 | $cases[] = array('page', 'CRM_Foo_Page_Inline', FALSE); | |
28 | $cases[] = array('page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE); | |
29 | $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE); | |
30 | $cases[] = array('page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE); | |
31 | $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE); | |
32 | $cases[] = array('page', 'CRM_Foo_Form', FALSE); | |
33 | $cases[] = array('page', 'CRM_Foo_Form_Bar', FALSE); | |
34 | $cases[] = array('page', 'CRM_Foo_Form_Inline', FALSE); | |
35 | $cases[] = array('page', 'CRM_Contact_Form_Inline_Email', TRUE); | |
36 | $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE); | |
37 | $cases[] = array('page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE); | |
38 | $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE); | |
39 | ||
40 | // aliases for 'page' | |
41 | $cases[] = array('class', 'CRM_Foo_Bar', FALSE); | |
42 | $cases[] = array('class', 'CRM_Contact_Page_Inline_Phone', TRUE); | |
43 | $cases[] = array('', 'CRM_Foo_Bar', FALSE); | |
44 | $cases[] = array('', 'CRM_Contact_Page_Inline_Demographics', TRUE); | |
b6708aeb | 45 | |
6a488035 TO |
46 | // invalid type |
47 | $cases[] = array('invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE); | |
48 | $cases[] = array('invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE); | |
49 | ||
50 | foreach ($cases as $case) { | |
0031e7ea E |
51 | list ($type, $className, $expectedResult) = $case; |
52 | $methodName = CRM_Utils_Array::value(3, $case); | |
6a488035 TO |
53 | $actualResult = CRM_Core_Page_AJAX::checkAuthz($type, $className, $methodName); |
54 | if ($methodName) { | |
55 | $this->assertEquals($expectedResult, $actualResult, | |
56 | sprintf('Check type=[%s] value=[%s] method=[%s]', $type, $className, $methodName)); | |
57 | } | |
58 | else { | |
59 | $this->assertEquals($expectedResult, $actualResult, | |
60 | sprintf('Check type=[%s] value=[%s]', $type, $className)); | |
61 | } | |
62 | } | |
63 | } | |
96025800 | 64 | |
6a488035 | 65 | } |