1<?php
2require_once 'index.php';
3echo '<h3>Area</h3>';
4
5$applications = $admin->perm->getApplications();
6if  (empty($applications)) {
7    echo 'Run the <strong>Application</strong> test first<br />';
8    exit;
9}
10
11echo '<hr />';
12echo '<strong>Sub Tests:</strong><br />';
13echo '<a href="Area_Admin_Areas.php' . $qstring . '">Area Admin Areas</a>';
14echo '<hr />';
15
16// Add
17$id = array_rand($applications);
18for ($i = 1; $i < 4; $i++) {
19    $data = array(
20        'application_id' => $applications[$id]['application_id'],
21        'area_define_name' => 'AREA'.rand(),
22    );
23    $areaId  = $admin->perm->addArea($data);
24
25    if ($areaId === false) {
26        echo '<strong>Error on line: '.__LINE__.'</strong><br />';
27        print_r($admin->getErrors());
28    } else {
29        echo 'Created Area Id <strong>' . $areaId . '</strong><br />';
30    }
31}
32
33// Get
34$areas = $admin->perm->getAreas();
35
36if ($areas === false) {
37    echo '<strong>Error on line: '.__LINE__.'</strong><br />';
38    print_r($admin->getErrors());
39} elseif (empty($areas)) {
40    echo 'No areas were found, thus we\'ve halted the rest of the test<br />';
41} else {
42    echo 'These are our current areas:';
43    Var_Dump::display($areas);
44    echo '<br />';
45
46    // Remove
47    $id = array_rand($areas);
48    $filters = array('area_id' => $areas[$id]['area_id']);
49    $rmArea = $admin->perm->removeArea($filters);
50
51    if ($rmArea === false) {
52        echo '<strong>Error on line: '.__LINE__.'</strong><br />';
53        print_r($admin->getErrors());
54    } else {
55        echo '<strong>Area3</strong> was removed<br />';
56        unset($areas[$id]);
57    }
58
59    // Update
60    $id = array_rand($applications);
61    $id2 = array_rand($areas);
62    $data = array(
63        'area_define_name' => 'AREA2_' . $areas[$id2]['area_id'] . 'updated'.rand(),
64        'application_id' => $applications[$id]['application_id'],
65    );
66
67    $id = array_rand($areas);
68    $filters = array('area_id' => $areas[$id]['area_id']);
69    $upArea = $admin->perm->updateArea($data, $filters);
70
71    if ($upArea === false) {
72        echo '<strong>Error on line: '.__LINE__.'</strong><br />';
73        print_r($admin->getErrors());
74    } else {
75        echo '<strong>Area2</strong> was updated<br />';
76        $params = array('filters' => array('area_id' => $areas[$id]['area_id']));
77        $result = $admin->perm->getAreas($params);
78
79        if ($result === false) {
80            echo '<strong>Error on line: '.__LINE__.'</strong><br />';
81            print_r($admin->getErrors());
82        } elseif (empty($result)) {
83            echo 'No areas were found<br />';
84        } else {
85            Var_Dump::display($result);
86        }
87    }
88
89    // Get
90    $areas = $admin->perm->getAreas();
91
92    if ($areas === false) {
93        echo '<strong>Error on line: '.__LINE__.'</strong><br />';
94        print_r($admin->getErrors());
95    } elseif (empty($areas)) {
96        echo 'No areas were found<br />';
97    } else {
98        echo 'These are our current areas:';
99        Var_Dump::display($areas);
100        echo '<br />';
101    }
102}
103echo '<hr />';
104