📄 unit_tests.php
字号:
<?phpclass phpgacl_api_test extends gacl_test_case { /** VERSION **/ function get_version() { $result = $this->gacl_api->get_version(); //$expected = '/^[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}$/i'; $expected = '/^[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}[a-zA-Z]{0,1}[0-9]{0,1}$/i'; $this->assertRegexp($expected, $result, 'Version incorrect.'); } function get_schema_version() { $result = $this->gacl_api->get_schema_version(); $expected = '/^[0-9]{1,2}.[0-9]{1,2}$/i'; $this->assertRegexp($expected, $result, 'Schema Version incorrect.'); } /** GENERAL **/ function count_all() { //Create array $arr = array( 'Level1a' => array( 'Level2a' => array( 'Level3a' => 1, 'Level3b' => 2 ), 'Level2b' => 3, ), 'Level1b' => 4, 'Level1c' => array( 'Level2c' => array( 'Level3c' => 5, 'Level3d' => 6 ), 'Level2d' => 7, ), 'Level1d' => 8 ); //Keep in mind count_all only counts actual values. So array()'s don't count as +1 $result = $this->gacl_api->count_all($arr); $this->assertEquals(8, $result, 'Incorrect array count, Should be 8.'); } /** ACO SECTION **/ function get_object_section_section_id_aco() { $result = $this->gacl_api->get_object_section_section_id('unit_test', 'unit_test', 'ACO'); $message = 'get_object_section_section_id failed'; $this->assert($result, $message); return $result; } function add_object_section_aco() { $result = $this->gacl_api->add_object_section('unit_test', 'unit_test', 999, 0, 'ACO'); $message = 'add_object_section failed'; $this->assert($result, $message); } function del_object_section_aco() { $result = $this->gacl_api->del_object_section($this->get_object_section_section_id_aco(), 'ACO'); $message = 'del_object_section failed'; $this->assert($result, $message); } /** ACO **/ function get_object_id_aco() { $result = $this->gacl_api->get_object_id('unit_test','enable_tests', 'ACO'); $message = 'get_object_id failed'; $this->assert($result, $message); return $result; } function add_object_aco() { $result = $this->gacl_api->add_object('unit_test', 'Enable - Tests', 'enable_tests', 999, 0, 'ACO'); $message = 'add_object failed'; $this->assert($result, $message); } function del_object_aco() { $result = $this->gacl_api->del_object($this->get_object_id_aco(), 'ACO'); $message = 'del_object failed'; $this->assert($result, $message); } /** ARO SECTION **/ function get_object_section_section_id_aro() { $result = $this->gacl_api->get_object_section_section_id('unit_test', 'unit_test', 'ARO'); $this->_aco_section_id = $result; $message = 'get_object_section_section_id failed'; $this->assert($result >= 0, $message); return $result; } function add_object_section_aro() { $result = $this->gacl_api->add_object_section('unit_test', 'unit_test', 999, 0, 'ARO'); $message = 'add_object_section failed'; $this->assert($result, $message); } function edit_object_section_aro() { $object_id = $this->get_object_section_section_id_aro(); $rename_result = $this->gacl_api->edit_object_section($object_id, 'unit_test_tmp', 'unit_test_tmp', 999, 0, 'ARO'); $rename2_result = $this->gacl_api->edit_object_section($object_id, 'unit_test', 'unit_test', 999, 0, 'ARO'); if ($rename_result === TRUE AND $rename2_result === TRUE) { $result = TRUE; } else { $result = FALSE; } $message = 'edit_object_section failed'; $this->assert($result, $message); } function del_object_section_aro() { $result = $this->gacl_api->del_object_section($this->get_object_section_section_id_aro(), 'ARO'); $message = 'del_object_section failed'; $this->assert($result, $message); } /** ARO **/ function get_object_id_aro() { $result = $this->gacl_api->get_object_id('unit_test','john_doe', 'ARO'); $message = 'get_object_id failed'; $this->assert($result, $message); return $result; } function get_object2_id_aro() { $result = $this->gacl_api->get_object_id('unit_test','jane_doe', 'ARO'); $message = 'get_object2_id failed'; $this->assert($result, $message); return $result; } function add_object_aro() { $result = $this->gacl_api->add_object('unit_test', 'John Doe', 'john_doe', 999, 0, 'ARO'); $message = 'add_object failed'; $this->assert($result, $message); } function del_object_aro() { $result = $this->gacl_api->del_object($this->get_object_id_aro(), 'ARO'); $message = 'del_object failed'; $this->assert($result, $message); } function add_object2_aro() { $result = $this->gacl_api->add_object('unit_test', 'Jane Doe', 'jane_doe', 998, 0, 'ARO'); $message = 'add_object2 failed'; $this->assert($result, $message); } function del_object2_aro() { $result = $this->gacl_api->del_object($this->get_object2_id_aro(), 'ARO'); $message = 'del_object2 failed'; $this->assert($result, $message); } /** AXO SECTION **/ function get_object_section_section_id_axo() { $result = $this->gacl_api->get_object_section_section_id('unit_test', 'unit_test', 'AXO'); $message = 'get_object_section_section_id failed'; $this->assert($result, $message); return $result; } function add_object_section_axo() { $result = $this->gacl_api->add_object_section('unit_test', 'unit_test', 999, 0, 'AXO'); $this->_aco_section_id = $result; $message = 'add_object_section failed'; $this->assert($result, $message); } function del_object_section_axo() { $result = $this->gacl_api->del_object_section($this->get_object_section_section_id_axo(), 'AXO'); $message = 'del_object_section failed'; $this->assert($result, $message); } /** AXO **/ function get_object_id_axo() { $result = $this->gacl_api->get_object_id('unit_test','object_1', 'AXO'); $message = 'get_object_id failed'; $this->assert($result, $message); return $result; } function add_object_axo() { $result = $this->gacl_api->add_object('unit_test', 'Object 1', 'object_1', 999, 0, 'AXO'); $message = 'add_object failed'; $this->assert($result, $message); } function del_object_axo() { $result = $this->gacl_api->del_object($this->get_object_id_axo(), 'AXO'); $message = 'del_object failed'; $this->assert($result, $message); } /** ARO GROUP **/ function get_group_id_parent_aro() { $result = $this->gacl_api->get_group_id(NULL, 'ARO Group 1', 'ARO'); $message = 'get_group_id_parent_aro failed'; $this->assert($result, $message); return $result; } function get_group_id_child_aro() { $result = $this->gacl_api->get_group_id(NULL, 'ARO Group 2', 'ARO'); $message = 'get_group_id_child_aro failed'; $this->assert($result, $message); return $result; } function get_group_parent_id_aro() { $parent_id = $this->gacl_api->get_group_parent_id($this->get_group_id_child_aro(), 'ARO'); //Make sure it matches with the actual parent. if ($parent_id === $this->get_group_id_parent_aro() ) { $result = TRUE; } else { $result = FALSE; } $message = 'get_group_parent_id_aro failed'; $this->assert($result, $message); return $result; } function get_group_data_aro() { list($id, $parent_id, $value, $name, $lft, $rgt) = $this->gacl_api->get_group_data($this->get_group_id_parent_aro(), 'ARO'); //Check all values in the resulting array. if ( $id > 0 AND $parent_id >= 0 AND strlen($name) > 0 AND $lft >= 1 AND $rgt > 1) { $result = TRUE; } else { $result = FALSE; } $message = 'get_group_data_aro failed'; $this->assert($result, $message); return $result; } function get_parent_group_objects_aro() { $group_objects = $this->gacl_api->get_group_objects($this->get_group_id_parent_aro(), 'ARO'); if (count($group_objects, COUNT_RECURSIVE) == 2 AND $group_objects['unit_test'][0] == 'john_doe') { $result = TRUE; } else { $result = FALSE; } $message = 'get_parent_group_objects_aro failed'; $this->assert($result, $message); return $result; } function get_parent_group_objects_recurse_aro() { $group_objects = $this->gacl_api->get_group_objects($this->get_group_id_parent_aro(), 'ARO', 'RECURSE'); switch (TRUE) { case count($group_objects) != 1:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -