Completed
Pull Request — master (#35)
by Robbie
11:29
created
tests/UserSecurityReportTest.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -21,80 +21,80 @@
 block discarded – undo
21 21
 class UserSecurityReportTest extends SapphireTest
22 22
 {
23 23
 
24
-    protected static $fixture_file = 'UserSecurityReportTest.yml';
25
-
26
-    protected $records;
27
-    protected $report;
28
-
29
-    protected static $required_extensions = [
30
-        Member::class => [
31
-            MemberReportExtension::class,
32
-        ],
33
-    ];
34
-
35
-    protected static $illegal_extensions = [
36
-        Group::class => [
37
-            GroupSubsites::class,
38
-        ],
39
-    ];
40
-
41
-    /**
42
-     * Utility method for all tests to use.
43
-     *
44
-     * @return ArrayList
45
-     * @todo pre-fill the report with fixture-defined users
46
-     */
47
-    protected function setUp()
48
-    {
49
-        parent::setUp();
50
-        $reports = Report::get_reports();
51
-        $report = $reports[UserSecurityReport::class];
52
-        $this->report = $report;
53
-        $this->records = $report->sourceRecords()->toArray();
54
-    }
55
-
56
-    public function testSourceRecords()
57
-    {
58
-        $this->assertNotEmpty($this->records);
59
-    }
60
-
61
-    public function testGetMemberGroups()
62
-    {
63
-        //getMemberGroups(&$member) returns string
64
-        $member = $this->objFromFixture(Member::class, 'member-has-0-groups');
65
-        $groups = $member->GroupsDescription;
66
-        $this->assertEquals('Not in a Security Group', $groups);
67
-
68
-        $member = $this->objFromFixture(Member::class, 'member-has-1-groups');
69
-        $groups = $member->GroupsDescription;
70
-        $this->assertEquals('Group Test 01', $groups);
71
-    }
72
-
73
-    public function testGetMemberPermissions()
74
-    {
75
-        $member = $this->objFromFixture(Member::class, 'member-has-0-permissions');
76
-        $perms = $member->PermissionsDescription;
77
-        $this->assertEquals('No Permissions', $perms);
78
-
79
-        $member = $this->objFromFixture(Member::class, 'member-has-1-permissions');
80
-        $perms = $member->PermissionsDescription;
81
-        $this->assertEquals('Full administrative rights', $perms);
82
-
83
-        $member = $this->objFromFixture(Member::class, 'member-has-n-permissions');
84
-        $perms = $member->PermissionsDescription;
85
-        $this->assertEquals('Full administrative rights, Edit any page', $perms);
86
-    }
87
-
88
-    public function testLoginLoggingColumnShowsOnlyWhenApplicable()
89
-    {
90
-        $original = Config::inst()->get(Security::class, 'login_recording');
91
-
92
-        Config::modify()->set(Security::class, 'login_recording', true);
93
-        $this->assertContains('LastLoggedIn', array_keys($this->report->columns()));
94
-
95
-        Config::modify()->set(Security::class, 'login_recording', false);
96
-        $this->assertNotContains('LastLoggedIn', array_keys($this->report->columns()));
97
-
98
-        Config::modify()->set(Security::class, 'login_recording', $original);
99
-    }
24
+	protected static $fixture_file = 'UserSecurityReportTest.yml';
25
+
26
+	protected $records;
27
+	protected $report;
28
+
29
+	protected static $required_extensions = [
30
+		Member::class => [
31
+			MemberReportExtension::class,
32
+		],
33
+	];
34
+
35
+	protected static $illegal_extensions = [
36
+		Group::class => [
37
+			GroupSubsites::class,
38
+		],
39
+	];
40
+
41
+	/**
42
+	 * Utility method for all tests to use.
43
+	 *
44
+	 * @return ArrayList
45
+	 * @todo pre-fill the report with fixture-defined users
46
+	 */
47
+	protected function setUp()
48
+	{
49
+		parent::setUp();
50
+		$reports = Report::get_reports();
51
+		$report = $reports[UserSecurityReport::class];
52
+		$this->report = $report;
53
+		$this->records = $report->sourceRecords()->toArray();
54
+	}
55
+
56
+	public function testSourceRecords()
57
+	{
58
+		$this->assertNotEmpty($this->records);
59
+	}
60
+
61
+	public function testGetMemberGroups()
62
+	{
63
+		//getMemberGroups(&$member) returns string
64
+		$member = $this->objFromFixture(Member::class, 'member-has-0-groups');
65
+		$groups = $member->GroupsDescription;
66
+		$this->assertEquals('Not in a Security Group', $groups);
67
+
68
+		$member = $this->objFromFixture(Member::class, 'member-has-1-groups');
69
+		$groups = $member->GroupsDescription;
70
+		$this->assertEquals('Group Test 01', $groups);
71
+	}
72
+
73
+	public function testGetMemberPermissions()
74
+	{
75
+		$member = $this->objFromFixture(Member::class, 'member-has-0-permissions');
76
+		$perms = $member->PermissionsDescription;
77
+		$this->assertEquals('No Permissions', $perms);
78
+
79
+		$member = $this->objFromFixture(Member::class, 'member-has-1-permissions');
80
+		$perms = $member->PermissionsDescription;
81
+		$this->assertEquals('Full administrative rights', $perms);
82
+
83
+		$member = $this->objFromFixture(Member::class, 'member-has-n-permissions');
84
+		$perms = $member->PermissionsDescription;
85
+		$this->assertEquals('Full administrative rights, Edit any page', $perms);
86
+	}
87
+
88
+	public function testLoginLoggingColumnShowsOnlyWhenApplicable()
89
+	{
90
+		$original = Config::inst()->get(Security::class, 'login_recording');
91
+
92
+		Config::modify()->set(Security::class, 'login_recording', true);
93
+		$this->assertContains('LastLoggedIn', array_keys($this->report->columns()));
94
+
95
+		Config::modify()->set(Security::class, 'login_recording', false);
96
+		$this->assertNotContains('LastLoggedIn', array_keys($this->report->columns()));
97
+
98
+		Config::modify()->set(Security::class, 'login_recording', $original);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
src/MemberReportExtension.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -14,106 +14,106 @@
 block discarded – undo
14 14
  */
15 15
 class MemberReportExtension extends DataExtension
16 16
 {
17
-    /**
18
-     * Set cast of additional fields
19
-     *
20
-     * @var array
21
-     * @config
22
-     */
23
-    private static $casting = array(
24
-        'GroupsDescription' => 'Text',
25
-        'PermissionsDescription' => 'Text'
26
-    );
17
+	/**
18
+	 * Set cast of additional fields
19
+	 *
20
+	 * @var array
21
+	 * @config
22
+	 */
23
+	private static $casting = array(
24
+		'GroupsDescription' => 'Text',
25
+		'PermissionsDescription' => 'Text'
26
+	);
27 27
 
28
-    /**
29
-     * Retrieves the most recent successful LoginAttempt
30
-     *
31
-     * @return DBDatetime|string
32
-     */
33
-    public function getLastLoggedIn()
34
-    {
35
-        $lastTime = LoginAttempt::get()
36
-            ->filter([
37
-                'MemberID' => $this->owner->ID,
38
-                'Status' => 'Success',
39
-            ])
40
-            ->sort('Created', 'DESC')
41
-            ->first();
28
+	/**
29
+	 * Retrieves the most recent successful LoginAttempt
30
+	 *
31
+	 * @return DBDatetime|string
32
+	 */
33
+	public function getLastLoggedIn()
34
+	{
35
+		$lastTime = LoginAttempt::get()
36
+			->filter([
37
+				'MemberID' => $this->owner->ID,
38
+				'Status' => 'Success',
39
+			])
40
+			->sort('Created', 'DESC')
41
+			->first();
42 42
 
43
-        if ($lastTime) {
44
-            return $lastTime->dbObject('Created')->format(DBDatetime::ISO_DATETIME);
45
-        }
46
-        return _t(__CLASS__ . '.NEVER', 'Never');
47
-    }
43
+		if ($lastTime) {
44
+			return $lastTime->dbObject('Created')->format(DBDatetime::ISO_DATETIME);
45
+		}
46
+		return _t(__CLASS__ . '.NEVER', 'Never');
47
+	}
48 48
 
49
-    /**
50
-     * Builds a comma separated list of member group names for a given Member.
51
-     *
52
-     * @return string
53
-     */
54
-    public function getGroupsDescription()
55
-    {
56
-        if (class_exists(Subsite::class)) {
57
-            Subsite::disable_subsite_filter(true);
58
-        }
49
+	/**
50
+	 * Builds a comma separated list of member group names for a given Member.
51
+	 *
52
+	 * @return string
53
+	 */
54
+	public function getGroupsDescription()
55
+	{
56
+		if (class_exists(Subsite::class)) {
57
+			Subsite::disable_subsite_filter(true);
58
+		}
59 59
 
60
-        // Get the member's groups, if any
61
-        $groups = $this->owner->Groups();
62
-        if ($groups->Count()) {
63
-            // Collect the group names
64
-            $groupNames = array();
65
-            foreach ($groups as $group) {
66
-                /** @var Group $group */
67
-                $groupNames[] = html_entity_decode($group->getTreeTitle());
68
-            }
69
-            // return a csv string of the group names, sans-markup
70
-            $result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
71
-        } else {
72
-            // If no groups then return a status label
73
-            $result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
74
-        }
60
+		// Get the member's groups, if any
61
+		$groups = $this->owner->Groups();
62
+		if ($groups->Count()) {
63
+			// Collect the group names
64
+			$groupNames = array();
65
+			foreach ($groups as $group) {
66
+				/** @var Group $group */
67
+				$groupNames[] = html_entity_decode($group->getTreeTitle());
68
+			}
69
+			// return a csv string of the group names, sans-markup
70
+			$result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
71
+		} else {
72
+			// If no groups then return a status label
73
+			$result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
74
+		}
75 75
 
76
-        if (class_exists(Subsite::class)) {
77
-            Subsite::disable_subsite_filter(false);
78
-        }
79
-        return $result;
80
-    }
76
+		if (class_exists(Subsite::class)) {
77
+			Subsite::disable_subsite_filter(false);
78
+		}
79
+		return $result;
80
+	}
81 81
 
82
-    /**
83
-     * Builds a comma separated list of human-readbale permissions for a given Member.
84
-     *
85
-     * @return string
86
-     */
87
-    public function getPermissionsDescription()
88
-    {
89
-        if (class_exists(Subsite::class)) {
90
-            Subsite::disable_subsite_filter(true);
91
-        }
82
+	/**
83
+	 * Builds a comma separated list of human-readbale permissions for a given Member.
84
+	 *
85
+	 * @return string
86
+	 */
87
+	public function getPermissionsDescription()
88
+	{
89
+		if (class_exists(Subsite::class)) {
90
+			Subsite::disable_subsite_filter(true);
91
+		}
92 92
 
93
-        $permissionsUsr = Permission::permissions_for_member($this->owner->ID);
94
-        $permissionsSrc = Permission::get_codes(true);
95
-        sort($permissionsUsr);
93
+		$permissionsUsr = Permission::permissions_for_member($this->owner->ID);
94
+		$permissionsSrc = Permission::get_codes(true);
95
+		sort($permissionsUsr);
96 96
 
97
-        $permissionNames = array();
98
-        foreach ($permissionsUsr as $code) {
99
-            $code = strtoupper($code);
100
-            foreach ($permissionsSrc as $k => $v) {
101
-                if (isset($v[$code])) {
102
-                    $name = empty($v[$code]['name'])
103
-                        ? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
104
-                        : $v[$code]['name'];
105
-                    $permissionNames[] = $name;
106
-                }
107
-            }
108
-        }
97
+		$permissionNames = array();
98
+		foreach ($permissionsUsr as $code) {
99
+			$code = strtoupper($code);
100
+			foreach ($permissionsSrc as $k => $v) {
101
+				if (isset($v[$code])) {
102
+					$name = empty($v[$code]['name'])
103
+						? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
104
+						: $v[$code]['name'];
105
+					$permissionNames[] = $name;
106
+				}
107
+			}
108
+		}
109 109
 
110
-        $result = $permissionNames
111
-            ? implode(', ', $permissionNames)
112
-            : _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
110
+		$result = $permissionNames
111
+			? implode(', ', $permissionNames)
112
+			: _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
113 113
 
114
-        if (class_exists(Subsite::class)) {
115
-            Subsite::disable_subsite_filter(false);
116
-        }
117
-        return $result;
118
-    }
114
+		if (class_exists(Subsite::class)) {
115
+			Subsite::disable_subsite_filter(false);
116
+		}
117
+		return $result;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         if ($lastTime) {
44 44
             return $lastTime->dbObject('Created')->format(DBDatetime::ISO_DATETIME);
45 45
         }
46
-        return _t(__CLASS__ . '.NEVER', 'Never');
46
+        return _t(__CLASS__.'.NEVER', 'Never');
47 47
     }
48 48
 
49 49
     /**
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
             $result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
71 71
         } else {
72 72
             // If no groups then return a status label
73
-            $result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
73
+            $result = _t(__CLASS__.'.NOGROUPS', 'Not in a Security Group');
74 74
         }
75 75
 
76 76
         if (class_exists(Subsite::class)) {
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             foreach ($permissionsSrc as $k => $v) {
101 101
                 if (isset($v[$code])) {
102 102
                     $name = empty($v[$code]['name'])
103
-                        ? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
103
+                        ? _t(__CLASS__.'.UNKNOWN', 'Unknown')
104 104
                         : $v[$code]['name'];
105 105
                     $permissionNames[] = $name;
106 106
                 }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
         $result = $permissionNames
111 111
             ? implode(', ', $permissionNames)
112
-            : _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
112
+            : _t(__CLASS__.'.NOPERMISSIONS', 'No Permissions');
113 113
 
114 114
         if (class_exists(Subsite::class)) {
115 115
             Subsite::disable_subsite_filter(false);
Please login to merge, or discard this patch.