Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | ||
5 | class CRM_Core_Page_AJAXTest extends CiviUnitTestCase { | |
b2042573 | 6 | //@todo make BAO enotice compliant & remove the line below |
7 | // WARNING - NEVER COPY & PASTE $_eNoticeCompliant = FALSE | |
8 | // new test classes should be compliant. | |
9 | public $_eNoticeCompliant = FALSE; | |
6a488035 TO |
10 | public function testCheckAuthz() { |
11 | $cases = array(); | |
12 | ||
13 | $cases[] = array('method', 'CRM_Foo', FALSE, 'method'); | |
14 | $cases[] = array('method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method'); | |
15 | $cases[] = array('method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay'); | |
16 | $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method('); | |
17 | $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method()'); | |
18 | $cases[] = array('method', 'othermethod;CRM_Foo_Page_AJAX', FALSE,'method'); | |
19 | $cases[] = array('method', 'CRM_Foo_Page_AJAX;othermethod', FALSE,'method'); | |
20 | $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, ''); | |
21 | $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method'); | |
22 | $cases[] = array('method', 'CRM_Foo->method', FALSE); | |
23 | ||
24 | ||
25 | $cases[] = array('page', 'CRM_Foo', FALSE); | |
26 | $cases[] = array('page', 'CRM_Foo_Bar', FALSE); | |
27 | $cases[] = array('page', 'CRM_Foo_Page', FALSE); | |
28 | $cases[] = array('page', 'CRM_Foo_Page_Bar', FALSE); | |
29 | $cases[] = array('page', 'CRM_Foo_Page_Inline', FALSE); | |
30 | $cases[] = array('page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE); | |
31 | $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE); | |
32 | $cases[] = array('page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE); | |
33 | $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE); | |
34 | $cases[] = array('page', 'CRM_Foo_Form', FALSE); | |
35 | $cases[] = array('page', 'CRM_Foo_Form_Bar', FALSE); | |
36 | $cases[] = array('page', 'CRM_Foo_Form_Inline', FALSE); | |
37 | $cases[] = array('page', 'CRM_Contact_Form_Inline_Email', TRUE); | |
38 | $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE); | |
39 | $cases[] = array('page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE); | |
40 | $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE); | |
41 | ||
42 | // aliases for 'page' | |
43 | $cases[] = array('class', 'CRM_Foo_Bar', FALSE); | |
44 | $cases[] = array('class', 'CRM_Contact_Page_Inline_Phone', TRUE); | |
45 | $cases[] = array('', 'CRM_Foo_Bar', FALSE); | |
46 | $cases[] = array('', 'CRM_Contact_Page_Inline_Demographics', TRUE); | |
b6708aeb | 47 | |
6a488035 TO |
48 | // invalid type |
49 | $cases[] = array('invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE); | |
50 | $cases[] = array('invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE); | |
51 | ||
52 | foreach ($cases as $case) { | |
53 | list ($type, $className, $expectedResult, $methodName) = $case; | |
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 | } |